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
=== modified file 'ubuntutools/config.py'
--- ubuntutools/config.py 2013-03-18 23:18:02 +0000
+++ ubuntutools/config.py 2013-05-15 00:21:27 +0000
@@ -21,6 +21,7 @@
21import shlex21import shlex
22import socket22import socket
23import sys23import sys
24import locale
2425
25from ubuntutools.logger import Logger26from ubuntutools.logger import Logger
2627
@@ -173,4 +174,10 @@
173 if export:174 if export:
174 os.environ['DEBFULLNAME'] = name175 os.environ['DEBFULLNAME'] = name
175 os.environ['DEBEMAIL'] = email176 os.environ['DEBEMAIL'] = email
177
178 # decode env var or gecos raw string with the current locale's encoding
179 encoding = locale.getdefaultlocale()[1]
180 if not encoding:
181 encoding = 'utf-8'
182 name = name.decode(encoding)
176 return name, email183 return name, email
177184
=== modified file 'ubuntutools/test/test_config.py'
--- ubuntutools/test/test_config.py 2013-03-18 23:18:02 +0000
+++ ubuntutools/test/test_config.py 2013-05-15 00:21:27 +0000
@@ -1,4 +1,5 @@
1# test_config.py - Test suite for ubuntutools.config1# test_config.py - Test suite for ubuntutools.config
2# -*- coding: utf-8 -*-
2#3#
3# Copyright (C) 2010, Stefano Rivera <stefanor@ubuntu.com>4# Copyright (C) 2010, Stefano Rivera <stefanor@ubuntu.com>
4#5#
@@ -17,6 +18,7 @@
17import __builtin__18import __builtin__
18import os19import os
19import sys20import sys
21import locale
20from StringIO import StringIO22from StringIO import StringIO
2123
22import mox24import mox
@@ -210,3 +212,12 @@
210 os.environ['DEBEMAIL'] = orig = '%s <%s>' % (name, email)212 os.environ['DEBEMAIL'] = orig = '%s <%s>' % (name, email)
211 self.assertEqual(ubu_email(), (name, email))213 self.assertEqual(ubu_email(), (name, email))
212 self.assertEqual(os.environ['DEBEMAIL'], orig)214 self.assertEqual(os.environ['DEBEMAIL'], orig)
215
216 def test_unicode_name(self):
217 encoding = locale.getdefaultlocale()[1]
218 if not encoding:
219 encoding = 'utf-8'
220 name = 'Jöe Déveloper'.decode('utf-8')
221 os.environ['DEBFULLNAME'] = name.encode(encoding)
222 os.environ['DEBEMAIL'] = email = 'joe@example.net'
223 self.assertEqual(ubu_email(), (name, email))

Subscribers

People subscribed via source and target branches

to status/vote changes: