Skip to content

Commit

Permalink
Merge pull request #39 from cfournie/unicode
Browse files Browse the repository at this point in the history
Open files as utf8
  • Loading branch information
cfournie committed Feb 8, 2017
2 parents 212d20d + 0764ee5 commit 246ee65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion important/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Use of this source code is governed by a MIT-style license that can be found
# in the LICENSE file.

__version__ = '0.1.2'
__version__ = '0.1.3'
6 changes: 3 additions & 3 deletions important/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def parse_file_imports(filepath, exclusions=None, directory=None):
display_filepath = os.path.relpath(filepath, directory)
# Compile and parse abstract syntax tree and find import statements
try:
with io.open(filepath) as handle:
with io.open(filepath, mode='rt', encoding='utf8') as handle:
source = handle.read()
# Remove lines with only comments (e.g. PEP 263 encodings)
source = '\n'.join(
Expand All @@ -89,7 +89,7 @@ def _is_script(filepath):
if os.access(filepath, os.F_OK | os.R_OK | os.X_OK) and \
not stat.S_ISSOCK(os.stat(filepath).st_mode):
try:
with io.open(filepath, mode='r') as handle:
with io.open(filepath, mode='rt', encoding='utf8') as handle:
first_line = handle.readline()
return bool(RE_SHEBANG.match(first_line))
except UnicodeDecodeError as exc:
Expand All @@ -106,7 +106,7 @@ def parse_dir_imports(current_directory, exclusions=None):
for root, dirs, files in os.walk(current_directory, topdown=True):
dirs[:] = [os.path.join(root, d) for d in dirs if d not in exclusions]
for filename in files:
filename = filename.decode('utf-8') \
filename = filename.decode('utf8') \
if hasattr(filename, 'decode') and isinstance(filename, str) \
else filename
filepath = os.path.join(root, filename)
Expand Down

0 comments on commit 246ee65

Please sign in to comment.