]> crepu.dev Git - config.git/blame_incremental - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/parso/file_io.py
Reorganización de directorios
[config.git] / djavu-asus / emacs / elpy / rpc-venv / lib / python3.11 / site-packages / parso / file_io.py
... / ...
CommitLineData
1import os
2from pathlib import Path
3from typing import Union
4
5
6class FileIO:
7 def __init__(self, path: Union[os.PathLike, str]):
8 if isinstance(path, str):
9 path = Path(path)
10 self.path = path
11
12 def read(self): # Returns bytes/str
13 # We would like to read unicode here, but we cannot, because we are not
14 # sure if it is a valid unicode file. Therefore just read whatever is
15 # here.
16 with open(self.path, 'rb') as f:
17 return f.read()
18
19 def get_last_modified(self):
20 """
21 Returns float - timestamp or None, if path doesn't exist.
22 """
23 try:
24 return os.path.getmtime(self.path)
25 except FileNotFoundError:
26 return None
27
28 def __repr__(self):
29 return '%s(%s)' % (self.__class__.__name__, self.path)
30
31
32class KnownContentFileIO(FileIO):
33 def __init__(self, path, content):
34 super().__init__(path)
35 self._content = content
36
37 def read(self):
38 return self._content