maxb@tigris.org writes:
> Modified:
> trunk/build/generator/gen_win.py
> trunk/subversion/bindings/swig/python/svn/core.py
> Log:
> Unify the handling of shell argument quoting in Python code throughout
> Subversion and cvs2svn.
>
> [Subversion]
> * subversion/bindings/swig/python/svn/core.py: Here.
> * build/generator/gen_win.py: And here.
>
> [cvs2svn]
> * cvs2svn: And also here.
Hrmh. I'm not sure records of sync-changes to slave copies belong in
the master's repository...
-K
> Modified: trunk/build/generator/gen_win.py
> Url: http://svn.collab.net/viewcvs/svn/trunk/build/generator/gen_win.py?view=diff&rev=12356&p1=trunk/build/generator/gen_win.py&r1=12355&p2=trunk/build/generator/gen_win.py&r2=12356
> ==============================================================================
> --- trunk/build/generator/gen_win.py (original)
> +++ trunk/build/generator/gen_win.py Fri Dec 17 13:54:46 2004
> @@ -866,12 +866,56 @@
> def __init__(self, **kw):
> vars(self).update(kw)
>
> +# ============================================================================
> +# Reusable code segment. This code is duplicated in the several locations.
> +# This is NOT the master copy.
> +# The master copy is: subversion/subversion/bindings/swig/python/svn/core.py
> +#
> +# Please keep all copies in sync.
> +#
> if sys.platform == "win32":
> - def escape_shell_arg(str):
> - return '"' + string.replace(str, '"', '"^""') + '"'
> + _escape_shell_arg_re = re.compile(r'(\\+)(\"|$)')
> +
> + def escape_shell_arg(arg):
> + # The (very strange) parsing rules used by the C runtime library are
> + # described at:
> + # http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_Parsing_C.2b2b_.Command.2d.Line_Arguments.asp
> +
> + # double up slashes, but only if they are followed by a quote character
> + arg = re.sub(_escape_shell_arg_re, r'\1\1\2', arg)
> +
> + # surround by quotes and escape quotes inside
> + arg = '"' + string.replace(arg, '"', '"^""') + '"'
> + return arg
> +
> +
> + def argv_to_command_string(argv):
> + """Flatten a list of command line arguments into a command string.
> +
> + The resulting command string is expected to be passed to the system
> + shell which os functions like popen() and system() invoke internally.
> + """
> +
> + # According cmd's usage notes (cmd /?), it parses the command line by
> + # "seeing if the first character is a quote character and if so, stripping
> + # the leading character and removing the last quote character."
> + # So to prevent the argument string from being changed we add an extra set
> + # of quotes around it here.
> + return '"' + string.join(map(escape_shell_arg, argv), " ") + '"'
> +
> else:
> def escape_shell_arg(str):
> return "'" + string.replace(str, "'", "'\\''") + "'"
> +
> + def argv_to_command_string(argv):
> + """Flatten a list of command line arguments into a command string.
> +
> + The resulting command string is expected to be passed to the system
> + shell which os functions like popen() and system() invoke internally.
> + """
> +
> + return string.join(map(escape_shell_arg, argv), " ")
> +# ============================================================================
>
> FILTER_LIBS = 1
> FILTER_PROJECTS = 2
>
> Modified: trunk/subversion/bindings/swig/python/svn/core.py
> Url: http://svn.collab.net/viewcvs/svn/trunk/subversion/bindings/swig/python/svn/core.py?view=diff&rev=12356&p1=trunk/subversion/bindings/swig/python/svn/core.py&r1=12355&p2=trunk/subversion/bindings/swig/python/svn/core.py&r2=12356
> ==============================================================================
> --- trunk/subversion/bindings/swig/python/svn/core.py (original)
> +++ trunk/subversion/bindings/swig/python/svn/core.py Fri Dec 17 13:54:46 2004
> @@ -110,33 +110,58 @@
> # ### aprtime is microseconds; turn it into seconds
> return aprtime / 1000000
>
> -def argv_to_command_string(argv):
> - """Flatten a list of command line arguments into a command string.
>
> - The resulting command string is expected to be passed to the system
> - shell which os functions like popen() and system() invoke internally.
> - """
>
> - _re_slashquote = re.compile(r'(\\+)(\"|$)')
> +# ============================================================================
> +# Reusable code segment. This code is duplicated in the several locations.
> +# THIS IS THE MASTER COPY.
> +#
> +# Duplicates are located at:
> +# - subversion/build/generator/gen_win.py
> +# - cvs2svn/cvs2svn
> +#
> +# Please keep all copies in sync, and the list above up-to-date.
> +#
> +if sys.platform == "win32":
> + _escape_shell_arg_re = re.compile(r'(\\+)(\"|$)')
>
> - def _escape_arg(arg):
> + def escape_shell_arg(arg):
> # The (very strange) parsing rules used by the C runtime library are
> # described at:
> # http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_Parsing_C.2b2b_.Command.2d.Line_Arguments.asp
>
> # double up slashes, but only if they are followed by a quote character
> - arg = re.sub(_re_slashquote, r'\1\1\2', arg)
> + arg = re.sub(_escape_shell_arg_re, r'\1\1\2', arg)
>
> # surround by quotes and escape quotes inside
> arg = '"' + string.replace(arg, '"', '"^""') + '"'
> return arg
>
> - if sys.platform == "win32":
> +
> + def argv_to_command_string(argv):
> + """Flatten a list of command line arguments into a command string.
> +
> + The resulting command string is expected to be passed to the system
> + shell which os functions like popen() and system() invoke internally.
> + """
> +
> # According cmd's usage notes (cmd /?), it parses the command line by
> # "seeing if the first character is a quote character and if so, stripping
> # the leading character and removing the last quote character."
> # So to prevent the argument string from being changed we add an extra set
> # of quotes around it here.
> - return '"' + string.join(map(_escape_arg, argv), " ") + '"'
> - else:
> - return string.join(argv, " ")
> + return '"' + string.join(map(escape_shell_arg, argv), " ") + '"'
> +
> +else:
> + def escape_shell_arg(str):
> + return "'" + string.replace(str, "'", "'\\''") + "'"
> +
> + def argv_to_command_string(argv):
> + """Flatten a list of command line arguments into a command string.
> +
> + The resulting command string is expected to be passed to the system
> + shell which os functions like popen() and system() invoke internally.
> + """
> +
> + return string.join(map(escape_shell_arg, argv), " ")
> +# ============================================================================
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: svn-help@subversion.tigris.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Dec 17 22:29:17 2004