Merge lp:~lool/ubuntu-dev-tools/fix-non-ascii-name into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Loïc Minier
Status: Merged
Merged at revision: 1390
Proposed branch: lp:~lool/ubuntu-dev-tools/fix-non-ascii-name
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 53 lines (+18/-0)
2 files modified
ubuntutools/config.py (+7/-0)
ubuntutools/test/test_config.py (+11/-0)
To merge this branch: bzr merge lp:~lool/ubuntu-dev-tools/fix-non-ascii-name
Reviewer Review Type Date Requested Status
Ubuntu Development Team Pending
Review via email: mp+163511@code.launchpad.net

Description of the change

Properly decode non-ascii developer name from environment or gecos.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

Looks good, but that test won't pass at package build time, with the C locale.

We'll need to run the tests with LANG=C.UTF-8 in debian/rules

1391. By Loïc Minier

Default to UTF-8 encoding when locale doesn't specify one (as Python defaults
to ascii); thanks Stefano Rivera.

1392. By Loïc Minier

Encode the developer name in the current locale to run the test; thanks
Stefano Rivera.

Revision history for this message
Loïc Minier (lool) wrote :

(missed your review for some reason; sorry)

Good catch; I've pushed r1391 to default to utf-8 in the config when locale doesn't specify an encoding and r1392 to convert the string from utf-8 into the current locale in the test.

I didn't want to require a specific locale to run the tests or add heavy build-deps; the only requirement now is that the current locale's encoding allows representing "Jöe Déveloper"; alternatively we could set the locale in the test but that seemed more invasive.

Revision history for this message
Loïc Minier (lool) wrote :

BTW I've tested r1392 with fr_FR.UTF-8, C and fr_FR.ISO-8859-1 locales; this last one was still failing with r1391.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntutools/config.py'
2--- ubuntutools/config.py 2013-03-18 23:18:02 +0000
3+++ ubuntutools/config.py 2013-05-15 00:21:27 +0000
4@@ -21,6 +21,7 @@
5 import shlex
6 import socket
7 import sys
8+import locale
9
10 from ubuntutools.logger import Logger
11
12@@ -173,4 +174,10 @@
13 if export:
14 os.environ['DEBFULLNAME'] = name
15 os.environ['DEBEMAIL'] = email
16+
17+ # decode env var or gecos raw string with the current locale's encoding
18+ encoding = locale.getdefaultlocale()[1]
19+ if not encoding:
20+ encoding = 'utf-8'
21+ name = name.decode(encoding)
22 return name, email
23
24=== modified file 'ubuntutools/test/test_config.py'
25--- ubuntutools/test/test_config.py 2013-03-18 23:18:02 +0000
26+++ ubuntutools/test/test_config.py 2013-05-15 00:21:27 +0000
27@@ -1,4 +1,5 @@
28 # test_config.py - Test suite for ubuntutools.config
29+# -*- coding: utf-8 -*-
30 #
31 # Copyright (C) 2010, Stefano Rivera <stefanor@ubuntu.com>
32 #
33@@ -17,6 +18,7 @@
34 import __builtin__
35 import os
36 import sys
37+import locale
38 from StringIO import StringIO
39
40 import mox
41@@ -210,3 +212,12 @@
42 os.environ['DEBEMAIL'] = orig = '%s <%s>' % (name, email)
43 self.assertEqual(ubu_email(), (name, email))
44 self.assertEqual(os.environ['DEBEMAIL'], orig)
45+
46+ def test_unicode_name(self):
47+ encoding = locale.getdefaultlocale()[1]
48+ if not encoding:
49+ encoding = 'utf-8'
50+ name = 'Jöe Déveloper'.decode('utf-8')
51+ os.environ['DEBFULLNAME'] = name.encode(encoding)
52+ os.environ['DEBEMAIL'] = email = 'joe@example.net'
53+ self.assertEqual(ubu_email(), (name, email))

Subscribers

People subscribed via source and target branches

to status/vote changes: