diff --git a/parso/file_io.py b/parso/file_io.py index dda48bb..b9a24f4 100644 --- a/parso/file_io.py +++ b/parso/file_io.py @@ -5,8 +5,11 @@ class FileIO: def __init__(self, path): self.path = path - def read(self): - with open(self.path) as f: + def read(self): # Returns bytes/str + # We would like to read unicode here, but we cannot, because we are not + # sure if it is a valid unicode file. Therefore just read whatever is + # here. + with open(self.path, 'rb') as f: return f.read() def get_last_modified(self): @@ -16,6 +19,9 @@ class FileIO: """ return os.path.getmtime(self.path) + def __repr__(self): + return '%s(%s)' % (self.__class__.__name__, self.path) + class KnownContentFileIO(FileIO): def __init__(self, path, content): diff --git a/parso/grammar.py b/parso/grammar.py index 938439d..68a944a 100644 --- a/parso/grammar.py +++ b/parso/grammar.py @@ -105,7 +105,8 @@ class Grammar(object): if module_node is not None: return module_node - code = file_io.read() + if code is None: + code = file_io.read() code = python_bytes_to_unicode(code) lines = split_lines(code, keepends=True)