Rev 3267: (bialix) bzr send: ensure that command line to invoking mail client in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Mar 12 07:38:23 GMT 2008


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

------------------------------------------------------------
revno: 3267
revision-id:pqm at pqm.ubuntu.com-20080312073810-r3a7ot93mw7hmk1m
parent: pqm at pqm.ubuntu.com-20080312041921-iqibnzp8pcqx18mk
parent: bialix at ukr.net-20080312055901-44umxb8uc3zs10fe
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-03-12 07:38:10 +0000
message:
  (bialix) bzr send: ensure that command line to invoking	mail client
   is 8-bit string, not unicode (#139318)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
  bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
  bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
  bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
  bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 3234.2.9
    revision-id:bialix at ukr.net-20080312055901-44umxb8uc3zs10fe
    parent: bialix at ukr.net-20080312054031-4fsyuz6zhjsc3vd1
    parent: pqm at pqm.ubuntu.com-20080312041921-iqibnzp8pcqx18mk
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Wed 2008-03-12 07:59:01 +0200
    message:
      merge bzr.dev
    added:
      bzrlib/directory_service.py    directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
      bzrlib/tests/test_directory_service.py test_directory_servi-20080305221044-vr2mkvlsk8jypa2y-2
      doc/en/admin-guide/            docenadminguide-20080305135054-y7y2c986yf94zljn-1
      doc/en/admin-guide/index.txt   index.txt-20080305140741-ecw0lap8dxkxc05g-1
    renamed:
      bzrlib/plugins/launchpad/lp_indirect.py => bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
      bzrlib/plugins/launchpad/test_lp_indirect.py => bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/debug.py                debug.py-20061102062349-vdhrw9qdpck8cl35-1
      bzrlib/delta.py                delta.py-20050729221636-54cf14ef94783d0a
      bzrlib/deprecated_graph.py     graph.py-20050905070950-b47dce53236c5e48
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
      bzrlib/merge_directive.py      merge_directive.py-20070228184838-ja62280spt1g7f4x-1
      bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
      bzrlib/registry.py             lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
      bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/branch_implementations/test_revision_history.py test_revision_histor-20070326062311-v7co92liyuchb80w-1
      bzrlib/tests/intertree_implementations/test_compare.py test_compare.py-20060724101752-09ysswo1a92uqyoz-2
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_registry.py  test_lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-2
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/tests/test_tsort.py     testtsort.py-20051025073946-27da871c394d5be4
      bzrlib/tests/test_upgrade.py   test_upgrade.py-20051004040251-555fe1d2bae1bc71
      bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
      bzrlib/tests/workingtree_implementations/test_merge_from_branch.py test_merge_from_bran-20060904034200-12jxyk2zlhpufxe1-1
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/tsort.py                tsort.py-20051025073946-7808f6aaf7d07208
      bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
      bzrlib/util/configobj/docs/configobj.txt configobj.txt-20051018184548-4949b5f17e6a19c7
      bzrlib/util/configobj/docs/validate.txt validate.txt-20051018184548-9e0e5ad913e258f5
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      doc/developers/lca-merge.txt   lcamerge.txt-20080103061803-9isydn4ivgwrvorw-1
      doc/en/user-guide/resolving_conflicts.txt resolving_conflicts.-20071122141511-0knao2lklsdsvb1q-5
      bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
      bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
    ------------------------------------------------------------
    revno: 3234.2.8
    revision-id:bialix at ukr.net-20080312054031-4fsyuz6zhjsc3vd1
    parent: bialix at ukr.net-20080302165711-w22fjx7opsi22hrm
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Wed 2008-03-12 07:40:31 +0200
    message:
      fix grammar in formatting string of UnableEncodePath error.
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
    ------------------------------------------------------------
    revno: 3234.2.7
    revision-id:bialix at ukr.net-20080302165711-w22fjx7opsi22hrm
    parent: bialix at ukr.net-20080302165419-2u0r0ogn1h7s4gib
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Sun 2008-03-02 18:57:11 +0200
    message:
      update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3234.2.6
    revision-id:bialix at ukr.net-20080302165419-2u0r0ogn1h7s4gib
    parent: bialix at ukr.net-20080302155055-je174871vc1qde2j
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Sun 2008-03-02 18:54:19 +0200
    message:
      because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 3234.2.5
    revision-id:bialix at ukr.net-20080302155055-je174871vc1qde2j
    parent: bialix at ukr.net-20080227190102-c4xveq84wj920y2i
    parent: pqm at pqm.ubuntu.com-20080229011300-p50it0si2y8mbv0d
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Sun 2008-03-02 17:50:55 +0200
    message:
      merge bzr.dev
    added:
      bzrlib/plugins/launchpad/test_lp_service.py test_lp_service.py-20080213034527-drf0ucr2x1js3onb-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/cmd_version_info.py     __init__.py-20051228204928-697d01fdca29c99b
      bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/option.py               option.py-20051014052914-661fb36e76e7362f
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
      bzrlib/plugins/launchpad/test_lp_indirect.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
      bzrlib/tests/blackbox/test_checkout.py test_checkout.py-20060211231752-a5cde67cf70af854
      bzrlib/tests/blackbox/test_version_info.py test_bb_version_info.py-20051228204928-91711c6559d952f7
      bzrlib/tests/branch_implementations/test_commit.py test_commit.py-20070206022134-117z1i5b644p63r0-1
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
      bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
      bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
      bzrlib/tests/workingtree_implementations/test_inv.py test_inv.py-20070311221604-ighlq8tbn5xq0kuo-1
      bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
      bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
      bzrlib/util/configobj/docs/BSD-LICENSE.txt BSDLICENSE.txt-20051018184548-29b89ff3102657f5
      bzrlib/util/configobj/docs/configobj.txt configobj.txt-20051018184548-4949b5f17e6a19c7
      bzrlib/util/configobj/docs/validate.txt validate.txt-20051018184548-9e0e5ad913e258f5
      bzrlib/version_info_formats/__init__.py generate_version_info.py-20051228204928-8358edabcddcd97e
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      doc/en/user-guide/bazaar_workflows.txt bazaar_workflows.txt-20071114035000-q36a9h57ps06uvnl-1
      doc/en/user-guide/branching_a_project.txt branching_a_project.-20071122141511-0knao2lklsdsvb1q-2
    ------------------------------------------------------------
    revno: 3234.2.4
    revision-id:bialix at ukr.net-20080227190102-c4xveq84wj920y2i
    parent: bialix at ukr.net-20080227185257-5gor8qkadhw0ljvq
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Wed 2008-02-27 21:01:02 +0200
    message:
      update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3234.2.3
    revision-id:bialix at ukr.net-20080227185257-5gor8qkadhw0ljvq
    parent: bialix at ukr.net-20080227183004-li318rd4rawj62my
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Wed 2008-02-27 20:52:57 +0200
    message:
      mail_client.py: provide new private method ExternalMailClient._get_compose_8bit_commandline to make bug #139318 testable (as Aaron requested).
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
    ------------------------------------------------------------
    revno: 3234.2.2
    revision-id:bialix at ukr.net-20080227183004-li318rd4rawj62my
    parent: bialix at ukr.net-20080226101452-a4l4pxn4s9ge2z3w
    parent: bialix at ukr.net-20080227182439-qltsi1rc2amf5kjr
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Wed 2008-02-27 20:30:04 +0200
    message:
      [merge] URL is always ascii.
    modified:
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
        ------------------------------------------------------------
        revno: 3234.3.1
        revision-id:bialix at ukr.net-20080227182439-qltsi1rc2amf5kjr
        parent: pqm at pqm.ubuntu.com-20080224013817-4ps9nmrzjtg9ugtz
        committer: Alexander Belchenko <bialix at ukr.net>
        branch nick: url.is.ascii
        timestamp: Wed 2008-02-27 20:24:39 +0200
        message:
          ensure that local_path_to_url() always returns plain string, not unicode.
        modified:
          bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
          bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 3234.2.1
    revision-id:bialix at ukr.net-20080226101452-a4l4pxn4s9ge2z3w
    parent: pqm at pqm.ubuntu.com-20080224013817-4ps9nmrzjtg9ugtz
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bug.139318
    timestamp: Tue 2008-02-26 12:14:52 +0200
    message:
      bzr send @ win32: ensure that command line to invoking Thunderbird is 8-bit string, not unicode (because subprocess does not understand non-ascii unicode)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
=== modified file 'NEWS'
--- a/NEWS	2008-03-12 01:06:03 +0000
+++ b/NEWS	2008-03-12 05:59:01 +0000
@@ -54,6 +54,10 @@
     * Disable plink's interactive prompt for password.
       (#107593, Dmitry Vasiliev)
 
+    * Encode command line arguments from unicode to user_encoding before
+      invoking external mail client in `bzr send` command.
+      (#139318, Alexander Belchenko)
+
     * Include quick-start-summary.svg file to python-based installer(s)
       for Windows. (#192924, Alexander Belchenko)
 

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2008-03-03 17:44:53 +0000
+++ b/bzrlib/errors.py	2008-03-12 05:59:01 +0000
@@ -2580,3 +2580,14 @@
 
     def __init__(self, timezone):
         self.timezone = timezone
+
+
+class UnableEncodePath(BzrError):
+
+    _fmt = ('Unable to encode %(kind)s path %(path)r in '
+            'user encoding %(user_encoding)s')
+
+    def __init__(self, path, kind):
+        self.path = path
+        self.kind = kind
+        self.user_encoding = osutils.get_user_encoding()

=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2008-03-07 18:17:13 +0000
+++ b/bzrlib/mail_client.py	2008-03-12 05:59:01 +0000
@@ -20,6 +20,7 @@
 import sys
 import tempfile
 
+import bzrlib
 from bzrlib import (
     email_message,
     errors,
@@ -153,7 +154,7 @@
             the attachment type.
         """
         for name in self._get_client_commands():
-            cmdline = [name]
+            cmdline = [self._encode_path(name, 'executable')]
             cmdline.extend(self._get_compose_commandline(to, subject,
                                                          attach_path))
             try:
@@ -176,6 +177,34 @@
         """
         raise NotImplementedError
 
+    def _encode_safe(self, u):
+        """Encode possible unicode string argument to 8-bit string
+        in user_encoding. Unencodable characters will be replaced
+        with '?'.
+
+        :param  u:  possible unicode string.
+        :return:    encoded string if u is unicode, u itself otherwise.
+        """
+        if isinstance(u, unicode):
+            return u.encode(bzrlib.user_encoding, 'replace')
+        return u
+
+    def _encode_path(self, path, kind):
+        """Encode unicode path in user encoding.
+
+        :param  path:   possible unicode path.
+        :param  kind:   path kind ('executable' or 'attachment').
+        :return:        encoded path if path is unicode,
+                        path itself otherwise.
+        :raise:         UnableEncodePath.
+        """
+        if isinstance(path, unicode):
+            try:
+                return path.encode(bzrlib.user_encoding)
+            except UnicodeEncodeError:
+                raise errors.UnableEncodePath(path, kind)
+        return path
+
 
 class Evolution(ExternalMailClient):
     """Evolution mail client."""
@@ -190,8 +219,9 @@
         if attach_path is not None:
             message_options['attach'] = attach_path
         options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
-                        message_options.iteritems()]
-        return ['mailto:%s?%s' % (to or '', '&'.join(options_list))]
+                        sorted(message_options.iteritems())]
+        return ['mailto:%s?%s' % (self._encode_safe(to or ''),
+            '&'.join(options_list))]
 
 
 class Mutt(ExternalMailClient):
@@ -203,11 +233,12 @@
         """See ExternalMailClient._get_compose_commandline"""
         message_options = []
         if subject is not None:
-            message_options.extend(['-s', subject ])
+            message_options.extend(['-s', self._encode_safe(subject)])
         if attach_path is not None:
-            message_options.extend(['-a', attach_path])
+            message_options.extend(['-a',
+                self._encode_path(attach_path, 'attachment')])
         if to is not None:
-            message_options.append(to)
+            message_options.append(self._encode_safe(to))
         return message_options
 
 
@@ -228,9 +259,9 @@
         """See ExternalMailClient._get_compose_commandline"""
         message_options = {}
         if to is not None:
-            message_options['to'] = to
+            message_options['to'] = self._encode_safe(to)
         if subject is not None:
-            message_options['subject'] = subject
+            message_options['subject'] = self._encode_safe(subject)
         if attach_path is not None:
             message_options['attachment'] = urlutils.local_path_to_url(
                 attach_path)
@@ -248,12 +279,12 @@
         """See ExternalMailClient._get_compose_commandline"""
         message_options = []
         if subject is not None:
-            message_options.extend( ['-s', subject ] )
+            message_options.extend(['-s', self._encode_safe(subject)])
         if attach_path is not None:
-            message_options.extend( ['--attach', attach_path] )
+            message_options.extend(['--attach',
+                self._encode_path(attach_path, 'attachment')])
         if to is not None:
-            message_options.extend( [ to ] )
-
+            message_options.extend([self._encode_safe(to)])
         return message_options
 
 
@@ -266,11 +297,12 @@
         """See ExternalMailClient._get_compose_commandline"""
         if not to:
             raise errors.NoMailAddressSpecified()
-        commandline = [to]
+        commandline = [self._encode_safe(to)]
         if subject is not None:
-            commandline.extend(['--subject', subject])
+            commandline.extend(['--subject', self._encode_safe(subject)])
         if attach_path is not None:
-            commandline.extend(['--attach', attach_path])
+            commandline.extend(['--attach',
+                self._encode_path(attach_path, 'attachment')])
         return commandline
 
 

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2008-03-03 21:53:19 +0000
+++ b/bzrlib/tests/test_errors.py	2008-03-12 05:59:01 +0000
@@ -21,6 +21,7 @@
 from bzrlib import (
     bzrdir,
     errors,
+    osutils,
     symbol_versioning,
     urlutils,
     )
@@ -452,6 +453,12 @@
              "http://bug.com/"),
             str(err))
 
+    def test_unable_encode_path(self):
+        err = errors.UnableEncodePath('foo', 'executable')
+        self.assertEquals("Unable to encode executable path 'foo' in "
+            "user encoding " + osutils.get_user_encoding(),
+            str(err))
+
     def test_unknown_format(self):
         err = errors.UnknownFormatError('bar', kind='foo')
         self.assertEquals("Unknown foo format: 'bar'", str(err))

=== modified file 'bzrlib/tests/test_mail_client.py'
--- a/bzrlib/tests/test_mail_client.py	2007-11-29 06:41:00 +0000
+++ b/bzrlib/tests/test_mail_client.py	2008-03-02 16:54:19 +0000
@@ -32,6 +32,17 @@
         self.assertEqual(['-s', 'Hi there!', 'jrandom at example.org'],
                          commandline)
 
+    def test_commandline_is_8bit(self):
+        mutt = mail_client.Mutt(None)
+        cmdline = mutt._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(
+            ['-s', 'Hi there!', '-a', 'file%', 'jrandom at example.org'],
+            cmdline)
+        for item in cmdline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
 
 class TestThunderbird(tests.TestCase):
 
@@ -46,6 +57,19 @@
         self.assertEqual(['-compose', "subject='Hi there!',"
                                       "to='jrandom at example.org'"], commandline)
 
+    def test_commandline_is_8bit(self):
+        # test for bug #139318
+        tbird = mail_client.Thunderbird(None)
+        cmdline = tbird._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(['-compose',
+            ("attachment='%s'," % urlutils.local_path_to_url('file%')) +
+            "subject='Hi there!',to='jrandom at example.org'",
+            ], cmdline)
+        for item in cmdline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
 
 class TestXDGEmail(tests.TestCase):
 
@@ -63,6 +87,18 @@
         self.assertEqual(['jrandom at example.org', '--subject', 'Hi there!'],
                          commandline)
 
+    def test_commandline_is_8bit(self):
+        xdg_email = mail_client.XDGEmail(None)
+        cmdline = xdg_email._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(
+            ['jrandom at example.org', '--subject', 'Hi there!',
+             '--attach', 'file%'],
+            cmdline)
+        for item in cmdline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
 
 class TestEvolution(tests.TestCase):
 
@@ -75,6 +111,18 @@
         self.assertEqual(['mailto:jrandom at example.org?subject=Hi%20there%21'],
                          commandline)
 
+    def test_commandline_is_8bit(self):
+        evo = mail_client.Evolution(None)
+        cmdline = evo._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(
+            ['mailto:jrandom at example.org?attach=file%25&subject=Hi%20there%21'
+            ],
+            cmdline)
+        for item in cmdline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
 
 class TestKMail(tests.TestCase):
 
@@ -87,6 +135,17 @@
         self.assertEqual(['-s', 'Hi there!', 'jrandom at example.org'],
                          commandline)
 
+    def test_commandline_is_8bit(self):
+        kmail = mail_client.KMail(None)
+        cmdline = kmail._get_compose_commandline(u'jrandom at example.org',
+            u'Hi there!', u'file%')
+        self.assertEqual(
+            ['-s', 'Hi there!', '--attach', 'file%', 'jrandom at example.org'],
+            cmdline)
+        for item in cmdline:
+            self.assertFalse(isinstance(item, unicode),
+                'Command-line item %r is unicode!' % item)
+
 
 class TestEditor(tests.TestCase):
 

=== modified file 'bzrlib/tests/test_urlutils.py'
--- a/bzrlib/tests/test_urlutils.py	2007-12-21 17:26:37 +0000
+++ b/bzrlib/tests/test_urlutils.py	2008-02-27 18:24:39 +0000
@@ -291,6 +291,7 @@
             raise TestSkipped("local encoding cannot handle unicode")
 
         self.assertEqual('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
+        self.assertFalse(isinstance(result, unicode))
 
     def test_posix_local_path_from_url(self):
         from_url = urlutils._posix_local_path_from_url
@@ -322,6 +323,7 @@
             raise TestSkipped("local encoding cannot handle unicode")
 
         self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
+        self.assertFalse(isinstance(result, unicode))
 
     def test_win32_unc_path_to_url(self):
         to_url = urlutils._win32_local_path_to_url
@@ -336,7 +338,7 @@
             raise TestSkipped("local encoding cannot handle unicode")
 
         self.assertEqual('file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
-
+        self.assertFalse(isinstance(result, unicode))
 
     def test_win32_local_path_from_url(self):
         from_url = urlutils._win32_local_path_from_url
@@ -491,6 +493,7 @@
     def test_escape(self):
         self.assertEqual('%25', urlutils.escape('%'))
         self.assertEqual('%C3%A5', urlutils.escape(u'\xe5'))
+        self.assertFalse(isinstance(urlutils.escape(u'\xe5'), unicode))
 
     def test_unescape(self):
         self.assertEqual('%', urlutils.unescape('%25'))

=== modified file 'bzrlib/urlutils.py'
--- a/bzrlib/urlutils.py	2007-12-21 17:26:37 +0000
+++ b/bzrlib/urlutils.py	2008-02-27 18:24:39 +0000
@@ -274,7 +274,8 @@
     # check for UNC path \\HOST\path
     if win32_path.startswith('//'):
         return 'file:' + escape(win32_path)
-    return 'file:///' + win32_path[0].upper() + ':' + escape(win32_path[2:])
+    return ('file:///' + str(win32_path[0].upper()) + ':' +
+        escape(win32_path[2:]))
 
 
 local_path_to_url = _posix_local_path_to_url




More information about the bazaar-commits mailing list