]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Default to UTF-8 source encoding (PEP8: python3) 399/head
authorAnthony Sottile <asottile@umich.edu>
Wed, 27 Apr 2016 19:26:29 +0000 (12:26 -0700)
committerAnthony Sottile <asottile@umich.edu>
Thu, 28 Apr 2016 16:43:02 +0000 (09:43 -0700)
babel/messages/extract.py
tests/messages/test_extract.py

index 716262706d814b1bda480e5899ca7fb4144d36c8..4dc56a4544e0ea8a44bb0dc757136001b826b516 100644 (file)
@@ -398,7 +398,7 @@ def extract_python(fileobj, keywords, comment_tags, options):
     in_def = in_translator_comments = False
     comment_tag = None
 
-    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
+    encoding = parse_encoding(fileobj) or options.get('encoding', 'UTF-8')
 
     if PY2:
         next_line = fileobj.readline
index db03af2e895e840006dd9a9a2e9fc4dd0c82af61..9d78d923b10cb749c1e1ab5da8c3c750420d185a 100644 (file)
@@ -50,6 +50,21 @@ msg10 = dngettext(getDomain(), 'Page', 'Pages', 3)
             (10, 'dngettext', (None, u'Page', u'Pages', None), [])],
             messages)
 
+    def test_extract_default_encoding_ascii(self):
+        buf = BytesIO(b'_("a")')
+        messages = list(extract.extract_python(
+            buf, list(extract.DEFAULT_KEYWORDS), [], {},
+        ))
+        # Should work great in both py2 and py3
+        self.assertEqual([(1, '_', 'a', [])], messages)
+
+    def test_extract_default_encoding_utf8(self):
+        buf = BytesIO(u'_("☃")'.encode('UTF-8'))
+        messages = list(extract.extract_python(
+            buf, list(extract.DEFAULT_KEYWORDS), [], {},
+        ))
+        self.assertEqual([(1, '_', u'☃', [])], messages)
+
     def test_nested_comments(self):
         buf = BytesIO(b"""\
 msg = ngettext('pylon',  # TRANSLATORS: shouldn't be