|
|
741b2c |
From cc62c28fda69ab948f2d169d6a20f3d5c3bfda2e Mon Sep 17 00:00:00 2001
|
|
|
741b2c |
From: Samuel Erb <samrerb@erbbysam.com>
|
|
|
741b2c |
Date: Tue, 17 Sep 2019 12:22:12 -0400
|
|
|
741b2c |
Subject: [PATCH] change default updateDocMode behavior and add new option to
|
|
|
741b2c |
keep old behavior (#510)
|
|
|
741b2c |
|
|
|
741b2c |
(cherry picked from commit acfac594e643f9c44f1c3b8d6d8957190a4d76f2)
|
|
|
741b2c |
Conflicts:
|
|
|
741b2c |
unoconv
|
|
|
741b2c |
unoconv2.py
|
|
|
741b2c |
unoconv3.py
|
|
|
741b2c |
---
|
|
|
741b2c |
unoconv2.py | 27 ++++++++++++++++++---------
|
|
|
741b2c |
unoconv3.py | 27 ++++++++++++++++++---------
|
|
|
741b2c |
2 files changed, 36 insertions(+), 18 deletions(-)
|
|
|
741b2c |
|
|
|
741b2c |
diff --git a/unoconv2.py b/unoconv2.py
|
|
|
741b2c |
index cf45010..22dee0b 100755
|
|
|
741b2c |
--- a/unoconv2.py
|
|
|
741b2c |
+++ b/unoconv2.py
|
|
|
741b2c |
@@ -523,6 +523,7 @@ class Options:
|
|
|
741b2c |
self.template = None
|
|
|
741b2c |
self.timeout = 6
|
|
|
741b2c |
self.verbose = 0
|
|
|
741b2c |
+ self.updateDocMode = UNO_NO_UPDATE
|
|
|
741b2c |
|
|
|
741b2c |
### Get options from the commandline
|
|
|
741b2c |
try:
|
|
|
741b2c |
@@ -530,7 +531,7 @@ class Options:
|
|
|
741b2c |
['connection=', 'debug', 'doctype=', 'export=', 'format=',
|
|
|
741b2c |
'help', 'import', 'listener', 'no-launch', 'output=',
|
|
|
741b2c |
'outputpath', 'password=', 'pipe=', 'port=', 'server=',
|
|
|
741b2c |
- 'timeout=', 'show', 'stdout', 'template', 'verbose',
|
|
|
741b2c |
+ 'timeout=', 'show', 'stdout', 'template', 'unsafe-quiet-update', 'verbose',
|
|
|
741b2c |
'version'] )
|
|
|
741b2c |
except getopt.error, exc:
|
|
|
741b2c |
print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
|
|
|
741b2c |
@@ -609,6 +610,10 @@ class Options:
|
|
|
741b2c |
self.template = arg
|
|
|
741b2c |
elif opt in ['-T', '--timeout']:
|
|
|
741b2c |
self.timeout = int(arg)
|
|
|
741b2c |
+ elif opt in ['--unsafe-quiet-update']:
|
|
|
741b2c |
+ # ref https://www.openoffice.org/api/docs/common/ref/com/sun/star/document/UpdateDocMode.html
|
|
|
741b2c |
+ print('Warning: Do not use the option --unsafe-quiet-update with untrusted input.')
|
|
|
741b2c |
+ self.updateDocMode = UNO_QUIET_UPDATE
|
|
|
741b2c |
elif opt in ['-v', '--verbose']:
|
|
|
741b2c |
self.verbose = self.verbose + 1
|
|
|
741b2c |
elif opt in ['-V', '--version']:
|
|
|
741b2c |
@@ -699,6 +704,7 @@ unoconv options:
|
|
|
741b2c |
--stdout write output to stdout
|
|
|
741b2c |
-t, --template=file import the styles from template (.ott)
|
|
|
741b2c |
-T, --timeout=secs timeout after secs if connection to listener fails
|
|
|
741b2c |
+ --unsafe-quiet-update allow rendered document to fetch external resources (Warning: this is unsafe with untrusted input)
|
|
|
741b2c |
-v, --verbose be more and more verbose (-vvv for debugging)
|
|
|
741b2c |
'''
|
|
|
741b2c |
|
|
|
741b2c |
@@ -826,7 +832,7 @@ class Convertor:
|
|
|
741b2c |
phase = "import"
|
|
|
741b2c |
|
|
|
741b2c |
### Load inputfile
|
|
|
741b2c |
- inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=UNO_QUIET_UPDATE)
|
|
|
741b2c |
+ inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=op.updateDocMode)
|
|
|
741b2c |
|
|
|
741b2c |
# if op.password:
|
|
|
741b2c |
# info = GlobalUnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
|
|
|
741b2c |
@@ -859,13 +865,14 @@ class Convertor:
|
|
|
741b2c |
print >>sys.stderr, 'unoconv: template file `%s\' does not exist.' % op.template
|
|
|
741b2c |
exitcode = 1
|
|
|
741b2c |
|
|
|
741b2c |
- ### Update document links
|
|
|
741b2c |
- phase = "update-links"
|
|
|
741b2c |
- try:
|
|
|
741b2c |
- document.updateLinks()
|
|
|
741b2c |
- except AttributeError:
|
|
|
741b2c |
- # the document doesn't implement the XLinkUpdate interface
|
|
|
741b2c |
- pass
|
|
|
741b2c |
+ ### Update document links links if appropriate
|
|
|
741b2c |
+ if op.updateDocMode != UNO_NO_UPDATE:
|
|
|
741b2c |
+ phase = "update-links"
|
|
|
741b2c |
+ try:
|
|
|
741b2c |
+ document.updateLinks()
|
|
|
741b2c |
+ except AttributeError:
|
|
|
741b2c |
+ # the document doesn't implement the XLinkUpdate interface
|
|
|
741b2c |
+ pass
|
|
|
741b2c |
|
|
|
741b2c |
### Update document indexes
|
|
|
741b2c |
phase = "update-indexes"
|
|
|
741b2c |
@@ -1131,6 +1138,7 @@ def run():
|
|
|
741b2c |
### Now that we have found a working pyuno library, let's import some classes
|
|
|
741b2c |
global UnoPropertyValue
|
|
|
741b2c |
global UnoNoConnectException
|
|
|
741b2c |
+ global UNO_NO_UPDATE
|
|
|
741b2c |
global UNO_QUIET_UPDATE
|
|
|
741b2c |
global UnoDisposedException
|
|
|
741b2c |
global UnoIllegalArgumentException
|
|
|
741b2c |
@@ -1142,6 +1150,7 @@ def run():
|
|
|
741b2c |
|
|
|
741b2c |
from com.sun.star.beans import PropertyValue as UnoPropertyValue
|
|
|
741b2c |
from com.sun.star.connection import NoConnectException as UnoNoConnectException
|
|
|
741b2c |
+ from com.sun.star.document.UpdateDocMode import NO_UPDATE as UNO_NO_UPDATE
|
|
|
741b2c |
from com.sun.star.document.UpdateDocMode import QUIET_UPDATE as UNO_QUIET_UPDATE
|
|
|
741b2c |
from com.sun.star.lang import DisposedException as UnoDisposedException
|
|
|
741b2c |
from com.sun.star.lang import IllegalArgumentException as UnoIllegalArgumentException
|
|
|
741b2c |
diff --git a/unoconv3.py b/unoconv3.py
|
|
|
741b2c |
index 84b59f3..da3922f 100755
|
|
|
741b2c |
--- a/unoconv3.py
|
|
|
741b2c |
+++ b/unoconv3.py
|
|
|
741b2c |
@@ -523,6 +523,7 @@ class Options:
|
|
|
741b2c |
self.template = None
|
|
|
741b2c |
self.timeout = 6
|
|
|
741b2c |
self.verbose = 0
|
|
|
741b2c |
+ self.updateDocMode = UNO_NO_UPDATE
|
|
|
741b2c |
|
|
|
741b2c |
### Get options from the commandline
|
|
|
741b2c |
try:
|
|
|
741b2c |
@@ -530,7 +531,7 @@ class Options:
|
|
|
741b2c |
['connection=', 'debug', 'doctype=', 'export=', 'format=',
|
|
|
741b2c |
'help', 'import', 'listener', 'no-launch', 'output=',
|
|
|
741b2c |
'outputpath', 'password=', 'pipe=', 'port=', 'server=',
|
|
|
741b2c |
- 'timeout=', 'show', 'stdout', 'template', 'verbose',
|
|
|
741b2c |
+ 'timeout=', 'show', 'stdout', 'template', 'unsafe-quiet-update', 'verbose',
|
|
|
741b2c |
'version'] )
|
|
|
741b2c |
except getopt.error as exc:
|
|
|
741b2c |
print('unoconv: %s, try unoconv -h for a list of all the options' % str(exc))
|
|
|
741b2c |
@@ -609,6 +610,10 @@ class Options:
|
|
|
741b2c |
self.template = arg
|
|
|
741b2c |
elif opt in ['-T', '--timeout']:
|
|
|
741b2c |
self.timeout = int(arg)
|
|
|
741b2c |
+ elif opt in ['--unsafe-quiet-update']:
|
|
|
741b2c |
+ # ref https://www.openoffice.org/api/docs/common/ref/com/sun/star/document/UpdateDocMode.html
|
|
|
741b2c |
+ print('Warning: Do not use the option --unsafe-quiet-update with untrusted input.')
|
|
|
741b2c |
+ self.updateDocMode = UNO_QUIET_UPDATE
|
|
|
741b2c |
elif opt in ['-v', '--verbose']:
|
|
|
741b2c |
self.verbose = self.verbose + 1
|
|
|
741b2c |
elif opt in ['-V', '--version']:
|
|
|
741b2c |
@@ -699,6 +704,7 @@ unoconv options:
|
|
|
741b2c |
--stdout write output to stdout
|
|
|
741b2c |
-t, --template=file import the styles from template (.ott)
|
|
|
741b2c |
-T, --timeout=secs timeout after secs if connection to listener fails
|
|
|
741b2c |
+ --unsafe-quiet-update allow rendered document to fetch external resources (Warning: this is unsafe with untrusted input)
|
|
|
741b2c |
-v, --verbose be more and more verbose (-vvv for debugging)
|
|
|
741b2c |
''', file=sys.stderr)
|
|
|
741b2c |
|
|
|
741b2c |
@@ -826,7 +832,7 @@ class Convertor:
|
|
|
741b2c |
phase = "import"
|
|
|
741b2c |
|
|
|
741b2c |
### Load inputfile
|
|
|
741b2c |
- inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=UNO_QUIET_UPDATE)
|
|
|
741b2c |
+ inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=op.updateDocMode)
|
|
|
741b2c |
|
|
|
741b2c |
# if op.password:
|
|
|
741b2c |
# info = GlobalUnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
|
|
|
741b2c |
@@ -859,13 +865,14 @@ class Convertor:
|
|
|
741b2c |
print('unoconv: template file `%s\' does not exist.' % op.template, file=sys.stderr)
|
|
|
741b2c |
exitcode = 1
|
|
|
741b2c |
|
|
|
741b2c |
- ### Update document links
|
|
|
741b2c |
- phase = "update-links"
|
|
|
741b2c |
- try:
|
|
|
741b2c |
- document.updateLinks()
|
|
|
741b2c |
- except AttributeError:
|
|
|
741b2c |
- # the document doesn't implement the XLinkUpdate interface
|
|
|
741b2c |
- pass
|
|
|
741b2c |
+ ### Update document links if appropriate
|
|
|
741b2c |
+ if op.updateDocMode != UNO_NO_UPDATE:
|
|
|
741b2c |
+ phase = "update-links"
|
|
|
741b2c |
+ try:
|
|
|
741b2c |
+ document.updateLinks()
|
|
|
741b2c |
+ except AttributeError:
|
|
|
741b2c |
+ # the document doesn't implement the XLinkUpdate interface
|
|
|
741b2c |
+ pass
|
|
|
741b2c |
|
|
|
741b2c |
### Update document indexes
|
|
|
741b2c |
phase = "update-indexes"
|
|
|
741b2c |
@@ -1131,6 +1138,7 @@ def run():
|
|
|
741b2c |
### Now that we have found a working pyuno library, let's import some classes
|
|
|
741b2c |
global UnoPropertyValue
|
|
|
741b2c |
global UnoNoConnectException
|
|
|
741b2c |
+ global UNO_NO_UPDATE
|
|
|
741b2c |
global UNO_QUIET_UPDATE
|
|
|
741b2c |
global UnoDisposedException
|
|
|
741b2c |
global UnoIllegalArgumentException
|
|
|
741b2c |
@@ -1142,6 +1150,7 @@ def run():
|
|
|
741b2c |
|
|
|
741b2c |
from com.sun.star.beans import PropertyValue as UnoPropertyValue
|
|
|
741b2c |
from com.sun.star.connection import NoConnectException as UnoNoConnectException
|
|
|
741b2c |
+ from com.sun.star.document.UpdateDocMode import NO_UPDATE as UNO_NO_UPDATE
|
|
|
741b2c |
from com.sun.star.document.UpdateDocMode import QUIET_UPDATE as UNO_QUIET_UPDATE
|
|
|
741b2c |
from com.sun.star.lang import DisposedException as UnoDisposedException
|
|
|
741b2c |
from com.sun.star.lang import IllegalArgumentException as UnoIllegalArgumentException
|
|
|
741b2c |
--
|
|
|
741b2c |
2.24.1
|
|
|
741b2c |
|