File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ def parse_encoding(fp):
65
65
try :
66
66
import parser
67
67
parser .suite (line1 .decode ('latin-1' ))
68
- except (ImportError , SyntaxError ):
68
+ except (ImportError , SyntaxError , UnicodeEncodeError ):
69
69
# Either it's a real syntax error, in which case the source is
70
70
# not valid python source, or line2 is a continuation of line1,
71
71
# in which case we don't want to scan line2 for a magic
Original file line number Diff line number Diff line change 14
14
import unittest
15
15
16
16
from babel import util
17
+ from babel ._compat import BytesIO
17
18
18
19
19
20
def test_distinct ():
@@ -52,3 +53,17 @@ def test_zone_zero_offset(self):
52
53
def test_zone_positive_offset (self ):
53
54
self .assertEqual ('Etc/GMT+330' , util .FixedOffsetTimezone (330 ).zone )
54
55
56
+
57
+ parse_encoding = lambda s : util .parse_encoding (BytesIO (s .encode ('utf-8' )))
58
+
59
+
60
+ def test_parse_encoding_defined ():
61
+ assert parse_encoding (u'# coding: utf-8' ) == 'utf-8'
62
+
63
+
64
+ def test_parse_encoding_undefined ():
65
+ assert parse_encoding (u'' ) is None
66
+
67
+
68
+ def test_parse_encoding_non_ascii ():
69
+ assert parse_encoding (u'K\xf6 ln' ) is None
You can’t perform that action at this time.
0 commit comments