Merge lp:~canonical-isd-hackers/canonical-identity-provider/login-unicode-error into lp:canonical-identity-provider/release

Proposed by Szilveszter Farkas
Status: Merged
Merged at revision: 13
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/login-unicode-error
Merge into: lp:canonical-identity-provider/release
Diff against target: 72 lines (+20/-16)
3 files modified
identityprovider/decorators.py (+1/-1)
identityprovider/tests/test_views_ui.py (+19/-0)
setup.py (+0/-15)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/login-unicode-error
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Ricardo Kirkner (community) Approve
Review via email: mp+24728@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

looks ok.

review: Approve
Revision history for this message
Anthony Lenton (elachuni) wrote :

In general when using non-ascii character literals in code it's better to use unicodes instead of regular strings, even if you need encoded strings.

So, u'test客'.encode('utf-8') is better than 'test客' even in a utf-8 encoded file:
- If you ever need to transcode your files to something else, you'll then just need to update the file header and everything keeps working, instead of having to change all your string literals.
- Explicit is better than implicit -- in the first case you know the encoding instantly, otherwise you have to go up and look at the file header.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/decorators.py'
2--- identityprovider/decorators.py 2010-04-21 15:29:24 +0000
3+++ identityprovider/decorators.py 2010-05-07 16:08:26 +0000
4@@ -148,7 +148,7 @@
5 # IP address and key_field (if it is set)
6 extra = super(ratelimit_post, self).key_extra(request)
7 if self.key_field:
8- value = sha1(request.POST.get(self.key_field, '')).hexdigest()
9+ value = sha1(request.POST.get(self.key_field, '').encode('utf-8')).hexdigest()
10 extra += '-' + value
11 return extra
12
13
14=== modified file 'identityprovider/tests/test_views_ui.py'
15--- identityprovider/tests/test_views_ui.py 2010-04-21 15:29:24 +0000
16+++ identityprovider/tests/test_views_ui.py 2010-05-07 16:08:26 +0000
17@@ -1,3 +1,4 @@
18+# encoding: utf-8
19 # Copyright 2010 Canonical Ltd. This software is licensed under the
20 # GNU Affero General Public License version 3 (see the file LICENSE).
21
22@@ -42,6 +43,24 @@
23 def authenticate(self):
24 self.client.login(username='mark@example.com', password='test')
25
26+ def test_login_with_unicode_email(self):
27+ r = self.client.post(
28+ '/+login',
29+ {
30+ 'email': u'mark@客example.com'.encode('utf-8'),
31+ 'password': 'test',
32+ })
33+ self.assertFormError(r, 'form', 'email', 'Invalid email.')
34+
35+ def test_login_with_unicode_password(self):
36+ r = self.client.post(
37+ '/+login',
38+ {
39+ 'email': 'mark@example.com',
40+ 'password': u'test客'.encode('utf-8'),
41+ })
42+ self.assertFormError(r, 'form', None, 'Password didn\'t match.')
43+
44 def test_login_with_next(self):
45 r = self.client.post('/+login', {'email': 'mark@example.com',
46 'password': 'test',
47
48=== modified file 'setup.py'
49--- setup.py 2010-04-23 15:38:18 +0000
50+++ setup.py 2010-05-07 16:08:26 +0000
51@@ -47,21 +47,6 @@
52
53 zip_safe=False,
54
55- install_requires=[
56- "django==1.0.2-final",
57- "simplejson==2.0.0",
58- "lazr.restful==0.9.17",
59- "python-openid",
60- "oauth",
61- "psycopg2==2.0.14",
62- "python-memcached",
63- "zope.testbrowser",
64- "coverage",
65- "beautifulsoup",
66- "lazr.authentication",
67- "lazr.restfulclient==0.9.10",
68- ],
69-
70 data_files=data_files,
71 package_data={
72 'identityprovider.webservice': ['site.zcml'],