← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-getPreferredLanguages into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-getPreferredLanguages into launchpad:master.

Commit message:
Adjust RequestPreferredLanguages.getPreferredLanguages for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396682
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-getPreferredLanguages into launchpad:master.
diff --git a/lib/lp/services/geoip/model.py b/lib/lp/services/geoip/model.py
index 0ba0489..53260aa 100644
--- a/lib/lp/services/geoip/model.py
+++ b/lib/lp/services/geoip/model.py
@@ -113,10 +113,8 @@ class RequestPreferredLanguages(object):
         languages = set()
 
         for code in codes:
-            # We need to ensure that the code received contains only ASCII
-            # characters otherwise SQLObject will crash if it receives a query
-            # with non printable ASCII characters.
-            if isinstance(code, str):
+            # Language tags are restricted to ASCII (see RFC 5646).
+            if isinstance(code, bytes):
                 try:
                     code = code.decode('ASCII')
                 except UnicodeDecodeError:
@@ -124,7 +122,7 @@ class RequestPreferredLanguages(object):
                     continue
             else:
                 try:
-                    code = code.encode('ASCII')
+                    code.encode('ASCII')
                 except UnicodeEncodeError:
                     # skip language codes that can't be represented in ASCII
                     continue