8000 Use re.Pattern for python 3.7 compatibility and fallback to re._patte… · stevejaker/python-readability@7f9cf4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f9cf4a

Browse files
committed
Use re.Pattern for python 3.7 compatibility and fallback to re._pattern_type in older versions.
1 parent 73c598d commit 7f9cf4a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

readability/compat/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ def tostring_(s):
1818
str_ = str
1919
def tostring_(s):
2020
return tostring(s, encoding='utf-8')
21+
22+
23+
try:
24+
from re import Pattern as pattern_type
25+
except ImportError:
26+
from re import _pattern_type as pattern_type

readability/readability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .htmls import get_body
1515
from .htmls import get_title
1616
from .htmls import shorten_title
17-
from .compat import str_, bytes_, tostring_
17+
from .compat import str_, bytes_, tostring_, pattern_type
1818
from .debug import describe, text_content
1919

2020

@@ -77,7 +77,7 @@ def text_length(i):
7777
def compile_pattern(elements):
7878
if not elements:
7979
return None
80-
elif isinstance(elements, re._pattern_type):
80+
elif isinstance(elements, pattern_type):
8181
return elements
8282
elif isinstance(elements, (str_, bytes_)):
8383
if isinstance(elements, bytes_):

0 commit comments

Comments
 (0)
0