Rev 5797: (mbp) better message when argv can't be decoded in the application locale in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Apr 18 03:15:07 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5797 [merge]
revision-id: pqm at pqm.ubuntu.com-20110418031503-x95t7v5ujr0lh9yw
parent: pqm at pqm.ubuntu.com-20110418023225-u6xxkipegqztrv9e
parent: gzlist at googlemail.com-20110415212257-jgtovwwp4be7egd9
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-04-18 03:15:03 +0000
message:
  (mbp) better message when argv can't be decoded in the application locale
   (Martin [gz])
modified:
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/blackbox/test_command_encoding.py test_command_encoding.py-20060106032110-45431fd2ce9ff21f
  bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
  bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2011-04-05 01:12:15 +0000
+++ b/bzrlib/commands.py	2011-04-15 18:11:31 +0000
@@ -1031,7 +1031,7 @@
         Specify the number of processes that can be run concurrently (selftest).
     """
     trace.mutter("bazaar version: " + bzrlib.__version__)
-    argv = list(argv)
+    argv = _specified_or_unicode_argv(argv)
     trace.mutter("bzr arguments: %r", argv)
 
     opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
@@ -1177,7 +1177,7 @@
         new_argv = []
         try:
             # ensure all arguments are unicode strings
-            for a in argv[1:]:
+            for a in argv:
                 if isinstance(a, unicode):
                     new_argv.append(a)
                 else:
@@ -1199,7 +1199,8 @@
 
     :return: exit code of bzr command.
     """
-    argv = _specified_or_unicode_argv(argv)
+    if argv is not None:
+        argv = argv[1:]
     _register_builtin_commands()
     ret = run_bzr_catch_errors(argv)
     trace.mutter("return code %d", ret)

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2011-04-04 13:37:25 +0000
+++ b/bzrlib/osutils.py	2011-04-15 21:22:52 +0000
@@ -96,8 +96,8 @@
         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))
+        raise errors.BzrError("Parameter %r encoding is unsupported by %s "
+            "application locale." % (a, user_encoding))
 
 
 def make_readonly(filename):

=== modified file 'bzrlib/tests/blackbox/test_command_encoding.py'
--- a/bzrlib/tests/blackbox/test_command_encoding.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_command_encoding.py	2011-04-15 21:13:48 +0000
@@ -54,13 +54,12 @@
         register_command(cmd_echo_exact)
         try:
             self.assertEqual('foo', bzr('echo-exact foo'))
-            # This is cheating a little bit, because 'foo\xb5' shouldn't
-            # get past main()
-            self.assertEqual('foo\xb5', bzr('echo-exact foo\xb5'))
             # Exact should fail to decode the string
             self.assertRaises(UnicodeEncodeError,
                 bzr,
                 ['echo-exact', u'foo\xb5'])
+            # Previously a non-ascii bytestring was also tested, as 'exact'
+            # outputs bytes untouched, but needed buggy argv parsing to work
         finally:
             plugin_cmds.remove('echo-exact')
 

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2011-04-13 02:01:11 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2011-04-18 03:15:03 +0000
@@ -335,26 +335,6 @@
         tree.add('foo.c')
         self.run_bzr('commit -m ""', retcode=3)
 
-    def test_unsupported_encoding_commit_message(self):
-        if sys.platform == 'win32':
-            raise tests.TestNotApplicable('Win32 parses arguments directly'
-                ' as Unicode, so we can\'t pass invalid non-ascii')
-        tree = self.make_branch_and_tree('.')
-        self.build_tree_contents([('foo.c', 'int main() {}')])
-        tree.add('foo.c')
-        # LANG env variable has no effect on Windows
-        # but some characters anyway cannot be represented
-        # in default user encoding
-        char = probe_bad_non_ascii(osutils.get_user_encoding())
-        if char is None:
-            raise TestSkipped('Cannot find suitable non-ascii character'
-                'for user_encoding (%s)' % osutils.get_user_encoding())
-        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
-                                          retcode=1,
-                                          env_changes={'LANG': 'C'})
-        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
-                                    'unsupported by the current encoding.')
-
     def test_other_branch_commit(self):
         # this branch is to ensure consistent behaviour, whether we're run
         # inside a branch, or not.

=== modified file 'bzrlib/tests/blackbox/test_exceptions.py'
--- a/bzrlib/tests/blackbox/test_exceptions.py	2011-03-05 01:37:14 +0000
+++ b/bzrlib/tests/blackbox/test_exceptions.py	2011-04-15 18:11:36 +0000
@@ -16,6 +16,7 @@
 
 """Tests for display of exceptions."""
 
+import os
 import sys
 
 from bzrlib import (
@@ -45,6 +46,21 @@
                 r'exceptions\.AssertionError: always fails\n')
         self.assertContainsRe(err, r'Bazaar has encountered an internal error')
 
+    def test_undecodable_argv(self):
+        """A user error must be reported if argv is not in the locale encoding
+
+        A subprocess with an environment ascii-only setting is used so the test
+        can run without worrying about the locale the test suite is using.
+        """
+        if os.name != "posix":
+            raise tests.TestNotApplicable("Needs system beholden to C locales")
+        out, err = self.run_bzr_subprocess(["\xa0"],
+            env_changes={"LANG": "C"},
+            universal_newlines=True,
+            retcode=errors.EXIT_ERROR)
+        self.assertContainsRe(err, r"^bzr: ERROR: .*'\\xa0'.* unsupported")
+        self.assertEquals(out, "")
+
 
 class TestOptParseBugHandling(TestCase):
     "Test that we handle http://bugs.python.org/issue2931"

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-04-17 18:24:56 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-04-18 03:15:03 +0000
@@ -57,6 +57,9 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* Arguments that can't be decoded to unicode in the current posix locale give
+  a clearer error message without a traceback. (Martin [gz], #745712)
+
 * ``bzrlib.log._DEFAULT_REQUEST_PARAMS`` is no longer accidentally
   mutated by ``bzrlib.log._apply_log_request_defaults``.  In practice
   these default values aren't relied on very often so this probably




More information about the bazaar-commits mailing list