Skip to content

Commit 6872c94

Browse files
committed
cleaned code
1 parent 14d4474 commit 6872c94

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

readability/encoding.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import sys
44

55

6-
RE_CHARSET = re.compile(br'<meta.*?charset=["\']*(.+?)["\'>]', flags=re.I)
7-
RE_PRAGMA = re.compile(br'<meta.*?content=["\']*;?charset=(.+?)["\'>]', flags=re.I)
8-
RE_XML = re.compile(br'^<\?xml.*?encoding=["\']*(.+?)["\'>]')
6+
RE_CHARSET = re.compile(r'<meta.*?charset=["\']*(.+?)["\'>]', flags=re.I)
7+
RE_PRAGMA = re.compile(r'<meta.*?content=["\']*;?charset=(.+?)["\'>]', flags=re.I)
8+
RE_XML = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]')
99

1010
CHARSETS = {
1111
'big5': 'big5hkscs',
@@ -34,24 +34,24 @@ def get_encoding(page):
3434
# Try any declared encodings
3535
for declared_encoding in declared_encodings:
3636
try:
37+
# Python3 only
3738
if sys.version_info[0] == 3:
3839
# declared_encoding will actually be bytes but .decode() only
3940
# accepts `str` type. Decode blindly with ascii because no one should
4041
# ever use non-ascii characters in the name of an encoding.
4142
declared_encoding = declared_encoding.decode('ascii', 'replace')
4243

4344
encoding = fix_charset(declared_encoding)
44-
4545
# Now let's decode the page
4646
page.decode(encoding)
4747
# It worked!
4848
return encoding
49-
except (UnicodeDecodeError, LookupError):
49+
except UnicodeDecodeError:
5050
pass
5151

5252
# Fallback to chardet if declared encodings fail
5353
# Remove all HTML tags, and leave only text for chardet
54-
text = re.sub(br'(\s*</?[^>]*>)+\s*', b' ', page).strip()
54+
text = re.sub(r'(\s*</?[^>]*>)+\s*', ' ', page).strip()
5555
enc = 'utf-8'
5656
if len(text) < 10:
5757
return enc # can't guess

0 commit comments

Comments
 (0)