Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:davidhalter/jedi into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Apr 25, 2014
2 parents a6f962f + ecd9470 commit 289dbc8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Akinori Hattori (@hattya)
srusskih (@srusskih)
Steven Silvester (@blink1073)
Colin Duquesnoy (@ColinDuquesnoy) <colin.duquesnoy@gmail.com>
Jorgen Schaefer (@jorgenschaefer) <contact@jorgenschaefer.de>

Note: (@user) means a github user name.
4 changes: 1 addition & 3 deletions jedi/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def find_module_py33(string, path=None):
module_file = None
else:
module_path = loader.get_filename(string)
module_ext = os.path.splitext(module_path)[1]
mode = 'rb' if module_ext in ['.pyc', '.so', '.pyd'] else 'r'
module_file = open(module_path, mode)
module_file = open(module_path, 'rb')
except AttributeError:
# ExtensionLoader has not attribute get_filename, instead it has a
# path attribute that we can use to retrieve the module path
Expand Down
10 changes: 5 additions & 5 deletions jedi/evaluate/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ def follow_path(directories, paths):
deeper_paths.append(new)
return follow_path(directories, deeper_paths)

with open(os.path.join(found_path, '__init__.py')) as f:
content = f.read()
with open(os.path.join(found_path, '__init__.py'), 'rb') as f:
content = common.source_to_unicode(f.read())
# these are strings that need to be used for namespace packages,
# the first one is ``pkgutil``, the second ``pkg_resources``.
options = 'declare_namespace(__name__)', 'extend_path(__path__'
Expand Down Expand Up @@ -406,7 +406,7 @@ def follow_str(ns_path, string):
# is a directory module
if is_package_directory:
path += '/__init__.py'
with open(path) as f:
with open(path, 'rb') as f:
source = f.read()
else:
source = current_namespace[0].read()
Expand Down Expand Up @@ -454,7 +454,7 @@ def load_module(path=None, source=None, name=None):
def load(source):
if path is not None and path.endswith('.py'):
if source is None:
with open(path) as f:
with open(path, 'rb') as f:
source = f.read()
else:
return compiled.load_module(path, name)
Expand All @@ -481,7 +481,7 @@ def check_python_file(path):
return None

def check_fs(path):
with open(path) as f:
with open(path, 'rb') as f:
source = source_to_unicode(f.read())
if name in source:
return load_module(path, source)
Expand Down
17 changes: 17 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import sys
import textwrap

from .helpers import TestCase, cwd_at
Expand Down Expand Up @@ -154,3 +155,19 @@ def test_generator(self):
" yield 1\n" \
"abc()."
assert Script(s).completions()


def test_loading_unicode_files_with_bad_global_charset(monkeypatch, tmpdir):
dirname = str(tmpdir.mkdir('jedi-test'))
filename1 = os.path.join(dirname, 'test1.py')
filename2 = os.path.join(dirname, 'test2.py')
if sys.version_info < (3, 0):
data = "# coding: latin-1\nfoo = 'm\xf6p'\n"
else:
data = "# coding: latin-1\nfoo = 'm\xf6p'\n".encode("latin-1")

with open(filename1, "wb") as f:
f.write(data)
s = Script("from test1 import foo\nfoo.",
line=2, column=4, path=filename2)
s.complete()

0 comments on commit 289dbc8

Please sign in to comment.