Rev 4364: (bialix) Use get_unicode_argv() to properly handle Unicode arguments in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu May 14 17:27:59 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4364
revision-id: pqm at pqm.ubuntu.com-20090514162755-t4q986mjos2ekecr
parent: pqm at pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz
parent: bialix at ukr.net-20090514124006-e5oxbauo706jks6a
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-05-14 17:27:55 +0100
message:
(bialix) Use get_unicode_argv() to properly handle Unicode arguments
on windows.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzr bzr.py-20050313053754-5485f144c7006fa6
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 4355.2.5
revision-id: bialix at ukr.net-20090514124006-e5oxbauo706jks6a
parent: bialix at ukr.net-20090514123752-prhs1hfkjzv92aig
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: cmdline
timestamp: Thu 2009-05-14 15:40:06 +0300
message:
improve comment
modified:
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 4355.2.4
revision-id: bialix at ukr.net-20090514123752-prhs1hfkjzv92aig
parent: bialix at ukr.net-20090514093839-nmz9saqqfqxi2u0q
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: cmdline
timestamp: Thu 2009-05-14 15:37:52 +0300
message:
win32utils.py: get_unicode_argv: get bzr options as tail of argv list based on the number of items in sys.argv[1:] list.
modified:
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 4355.2.3
revision-id: bialix at ukr.net-20090514093839-nmz9saqqfqxi2u0q
parent: bialix at ukr.net-20090514082448-12lcq3mq3jgb4jc4
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: cmdline
timestamp: Thu 2009-05-14 12:38:39 +0300
message:
commands.py: main() function expect to get argv argument as list of unicode or pure ascii strings.
NEWS updated based on suggestions from John Meinel.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
------------------------------------------------------------
revno: 4355.2.2
revision-id: bialix at ukr.net-20090514082448-12lcq3mq3jgb4jc4
parent: bialix at ukr.net-20090513192614-92n4xfzwshxshy79
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: cmdline
timestamp: Thu 2009-05-14 11:24:48 +0300
message:
osutils.py: get_unicode_argv function (to obtain unicode command line arguments from sys.argv) moved to the beginning of module based on suggestions from review of John Meinel.
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 4355.2.1
revision-id: bialix at ukr.net-20090513192614-92n4xfzwshxshy79
parent: pqm at pqm.ubuntu.com-20090513053911-fjajgycew5in8q5s
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: cmdline
timestamp: Wed 2009-05-13 22:26:14 +0300
message:
Using unicode Windows API to obtain command-line arguments.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzr bzr.py-20050313053754-5485f144c7006fa6
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
=== modified file 'NEWS'
--- a/NEWS 2009-05-12 09:05:30 +0000
+++ b/NEWS 2009-05-14 09:38:39 +0000
@@ -106,6 +106,9 @@
set the root data the same way that reconcile does.
(Robert Collins, #368921)
+* Using unicode Windows API to obtain command-line arguments.
+ (Alexander Belchenko, #375934)
+
Documentation
*************
@@ -116,6 +119,12 @@
instead of ``InstallFailed`` when they detect a missing revision.
``InstallFailed`` itself has been deleted. (Jonathan Lange)
+* Not passing arguments to ``bzrlib.commands.main()`` will now grab the
+ arguments from ``osutils.get_unicode_argv()`` which has proper support
+ for unicode arguments on windows. Further, the supplied arguments are now
+ required to be unicode strings, rather than user_encoded strings.
+ (Alexander Belchenko)
+
Internals
*********
=== modified file 'bzr'
--- a/bzr 2009-04-30 22:40:42 +0000
+++ b/bzr 2009-05-13 19:26:14 +0000
@@ -127,7 +127,7 @@
if __name__ == '__main__':
bzrlib.trace.enable_default_logging()
- exit_val = bzrlib.commands.main(sys.argv)
+ exit_val = bzrlib.commands.main()
if profiling:
profile_imports.log_stack_info(sys.stderr)
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2009-05-06 05:36:28 +0000
+++ b/bzrlib/commands.py 2009-05-14 09:38:39 +0000
@@ -952,7 +952,16 @@
return ignore_pipe
-def main(argv):
+def main(argv=None):
+ """Main entry point of command-line interface.
+
+ :param argv: list of unicode command-line arguments similar to sys.argv.
+ argv[0] is script name usually, it will be ignored.
+ Don't pass here sys.argv because this list contains plain strings
+ and not unicode; pass None instead.
+
+ :return: exit code of bzr command.
+ """
import bzrlib.ui
bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
sys.stdin, sys.stdout, sys.stderr)
@@ -961,12 +970,20 @@
if bzrlib.version_info[3] == 'final':
from bzrlib import symbol_versioning
symbol_versioning.suppress_deprecation_warnings(override=False)
- try:
- user_encoding = osutils.get_user_encoding()
- argv = [a.decode(user_encoding) for a in argv[1:]]
- except UnicodeDecodeError:
- raise errors.BzrError(("Parameter '%r' is unsupported by the current "
- "encoding." % a))
+ if argv is None:
+ argv = osutils.get_unicode_argv()
+ else:
+ new_argv = []
+ try:
+ # ensure all arguments are unicode strings
+ for a in argv[1:]:
+ if isinstance(a, unicode):
+ new_argv.append(a)
+ else:
+ new_argv.append(a.decode('ascii'))
+ except UnicodeDecodeError:
+ raise errors.BzrError("argv should be list of unicode strings.")
+ argv = new_argv
ret = run_bzr_catch_errors(argv)
trace.mutter("return code %d", ret)
return ret
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-05-07 04:58:58 +0000
+++ b/bzrlib/osutils.py 2009-05-14 08:24:48 +0000
@@ -77,6 +77,15 @@
O_BINARY = getattr(os, 'O_BINARY', 0)
+def get_unicode_argv():
+ try:
+ user_encoding = get_user_encoding()
+ return [a.decode(user_encoding) for a in sys.argv[1:]]
+ except UnicodeDecodeError:
+ raise errors.BzrError(("Parameter '%r' is unsupported by the current "
+ "encoding." % a))
+
+
def make_readonly(filename):
"""Make a filename read-only."""
mod = os.lstat(filename).st_mode
@@ -390,6 +399,11 @@
def rmtree(path, ignore_errors=False, onerror=_win32_delete_readonly):
"""Replacer for shutil.rmtree: could remove readonly dirs/files"""
return shutil.rmtree(path, ignore_errors, onerror)
+
+ f = win32utils.get_unicode_argv # special function or None
+ if f is not None:
+ get_unicode_argv = f
+
elif sys.platform == 'darwin':
getcwd = _mac_getcwd
=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py 2009-04-04 02:50:01 +0000
+++ b/bzrlib/win32utils.py 2009-05-14 12:40:06 +0000
@@ -433,7 +433,6 @@
import glob
expanded_file_list = []
for possible_glob in file_list:
-
# work around bugs in glob.glob()
# - Python bug #1001604 ("glob doesn't return unicode with ...")
# - failing expansion for */* with non-iso-8859-* chars
@@ -488,3 +487,32 @@
"""Set file attributes to hidden if possible"""
if has_win32file:
win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
+
+
+if has_ctypes and winver != 'Windows 98':
+ def get_unicode_argv():
+ LPCWSTR = ctypes.c_wchar_p
+ INT = ctypes.c_int
+ POINTER = ctypes.POINTER
+ prototype = ctypes.WINFUNCTYPE(LPCWSTR)
+ GetCommandLine = prototype(("GetCommandLineW",
+ ctypes.windll.kernel32))
+ prototype = ctypes.WINFUNCTYPE(POINTER(LPCWSTR), LPCWSTR, POINTER(INT))
+ CommandLineToArgv = prototype(("CommandLineToArgvW",
+ ctypes.windll.shell32))
+ c = INT(0)
+ pargv = CommandLineToArgv(GetCommandLine(), ctypes.byref(c))
+ # Skip the first argument, since we only care about parameters
+ argv = [pargv[i] for i in range(1, c.value)]
+ if getattr(sys, 'frozen', None) is None:
+ # Invoked via 'python.exe' which takes the form:
+ # python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
+ # we need to get only BZR_OPTIONS part,
+ # so let's using sys.argv[1:] as reference to get the tail
+ # of unicode argv
+ tail_len = len(sys.argv[1:])
+ ix = len(argv) - tail_len
+ argv = argv[ix:]
+ return argv
+else:
+ get_unicode_argv = None
More information about the bazaar-commits
mailing list