mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-02 17:43:43 +08:00
Some minor changes to file_io
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user