[Zope-CVS] CVS: Products/ExternalEditor - CHANGES.txt:1.26 zopeedit.py:1.34
Casey Duncan
casey@zope.com
Mon, 22 Jul 2002 18:52:11 -0400
Update of /cvs-repository/Products/ExternalEditor
In directory cvs.zope.org:/tmp/cvs-serv9555
Modified Files:
CHANGES.txt zopeedit.py
Log Message:
Fixed editor command parsing on unix. Now handles quoted args properly
=== Products/ExternalEditor/CHANGES.txt 1.25 => 1.26 ===
External Editor Change Log
+ - Unix editor command line parsing is much more robust now and properly
+ handles quoted arguments. You can also specify the "$1" placeholder in the
+ editor command to denote where the content file name is inserted. If
+ omitted it is appended to the end of the command line. "%1" continues to
+ work similarly for Windows. Thanks to Marc St-Jean.
+
- Fixed bug editing large (chunked) files and images. External editor now
streams their data properly to the client. Thanks to all the users who
reported various symptoms of this bug.
=== Products/ExternalEditor/zopeedit.py 1.33 => 1.34 ===
launch_success = 0
last_mtime = os.path.getmtime(self.content_file)
command = self.getEditorCommand()
- if command.find('%1') > -1:
- command = command.replace('%1', self.content_file)
+
+ if win32:
+ file_insert = '%1'
+ else:
+ file_insert = '$1'
+
+ if command.find(file_insert) > -1:
+ command = command.replace(file_insert, self.content_file)
else:
command = '%s %s' % (command, self.content_file)
editor = EditorProcess(command)
@@ -561,6 +567,7 @@
else: # Posix platform
from time import sleep
+ import re
def has_tk():
"""Sets up a suitable tk root window if one has not
@@ -605,8 +612,12 @@
class EditorProcess:
def __init__(self, command):
"""Launch editor process"""
- command = command.split()
- self.pid = os.spawnvp(os.P_NOWAIT, command[0], command)
+ # Prepare the command arguments, we use this regex to
+ # split on whitespace and properly handle quoting
+ arg_re = r"""\s*([^'"]\S+)\s+|\s*"([^"]+)"\s*|\s*'([^']+)'\s*"""
+ args = re.split(arg_re, command.strip())
+ args = filter(None, args) # Remove empty elements
+ self.pid = os.spawnvp(os.P_NOWAIT, args[0], args)
def wait(self, timeout):
"""Wait for editor to exit or until timeout"""