mirror of
https://github.com/davidhalter/parso.git
synced 2026-08-12 19:11:34 +08:00
Some minor changes to file_io
This commit is contained in:
+8
-2
@@ -5,8 +5,11 @@ class FileIO:
|
|||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def read(self):
|
def read(self): # Returns bytes/str
|
||||||
with open(self.path) as f:
|
# 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()
|
return f.read()
|
||||||
|
|
||||||
def get_last_modified(self):
|
def get_last_modified(self):
|
||||||
@@ -16,6 +19,9 @@ class FileIO:
|
|||||||
"""
|
"""
|
||||||
return os.path.getmtime(self.path)
|
return os.path.getmtime(self.path)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '%s(%s)' % (self.__class__.__name__, self.path)
|
||||||
|
|
||||||
|
|
||||||
class KnownContentFileIO(FileIO):
|
class KnownContentFileIO(FileIO):
|
||||||
def __init__(self, path, content):
|
def __init__(self, path, content):
|
||||||
|
|||||||
+2
-1
@@ -105,7 +105,8 @@ class Grammar(object):
|
|||||||
if module_node is not None:
|
if module_node is not None:
|
||||||
return module_node
|
return module_node
|
||||||
|
|
||||||
code = file_io.read()
|
if code is None:
|
||||||
|
code = file_io.read()
|
||||||
code = python_bytes_to_unicode(code)
|
code = python_bytes_to_unicode(code)
|
||||||
|
|
||||||
lines = split_lines(code, keepends=True)
|
lines = split_lines(code, keepends=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user