Skip to content

Commit

Permalink
refactor(website): use files instead of open_text of importlib.resour…
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Nov 8, 2021
1 parent d2c1b01 commit 9ce7706
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions guessit/rules/properties/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Website property.
"""
try:
from importlib.resources import open_text # @UnresolvedImport
from importlib.resources import files # @UnresolvedImport
except ImportError:
from importlib_resources import open_text # @UnresolvedImport
from importlib_resources import files # @UnresolvedImport

from rebulk.remodule import re

Expand All @@ -31,10 +31,11 @@ def website(config):
rebulk = rebulk.regex_defaults(flags=re.IGNORECASE).string_defaults(ignore_case=True)
rebulk.defaults(name="website")

with open_text('guessit.data', 'tlds-alpha-by-domain.txt') as tld_file:
with files('guessit.data') as data_files:
tld_file = data_files.joinpath('tlds-alpha-by-domain.txt').read_text(encoding='utf-8')
tlds = [
tld.strip()
for tld in tld_file.readlines()
for tld in tld_file.split('\n')
if '--' not in tld
][1:] # All registered domain extension

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
with io.open(os.path.join(here, 'CHANGELOG.md'), encoding='utf-8') as f:
changelog = f.read()

install_requires = ['rebulk>=3.1.0', 'babelfish>=0.6.0', 'python-dateutil', 'importlib-resources;python_version<"3.7"']
install_requires = ['rebulk>=3.1.0', 'babelfish>=0.6.0', 'python-dateutil', 'importlib-resources;python_version<"3.9"']

setup_requires = ['pytest-runner']

Expand Down

0 comments on commit 9ce7706

Please sign in to comment.