Some minor changes to file_io

This commit is contained in:
Dave Halter
2019-03-27 01:02:27 +01:00
parent 3e2956264c
commit 4c65368056
2 changed files with 10 additions and 3 deletions

View File

@@ -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):

View File

@@ -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)