]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/jedi/file_io.py
3 from parso
import file_io
6 class AbstractFolderIO
:
7 def __init__(self
, path
):
10 def get_base_name(self
):
11 raise NotImplementedError
14 raise NotImplementedError
16 def get_file_io(self
, name
):
17 raise NotImplementedError
19 def get_parent_folder(self
):
20 raise NotImplementedError
23 return '<%s: %s>' % (self
.__class
__.__name
__, self
.path
)
26 class FolderIO(AbstractFolderIO
):
27 def get_base_name(self
):
28 return os
.path
.basename(self
.path
)
31 return os
.listdir(self
.path
)
33 def get_file_io(self
, name
):
34 return FileIO(os
.path
.join(self
.path
, name
))
36 def get_parent_folder(self
):
37 return FolderIO(os
.path
.dirname(self
.path
))
40 for root
, dirs
, files
in os
.walk(self
.path
):
41 root_folder_io
= FolderIO(root
)
42 original_folder_ios
= [FolderIO(os
.path
.join(root
, d
)) for d
in dirs
]
43 modified_folder_ios
= list(original_folder_ios
)
47 [FileIO(os
.path
.join(root
, f
)) for f
in files
],
49 modified_iterator
= iter(reversed(modified_folder_ios
))
50 current
= next(modified_iterator
, None)
51 i
= len(original_folder_ios
)
52 for folder_io
in reversed(original_folder_ios
):
53 i
-= 1 # Basically enumerate but reversed
54 if current
is folder_io
:
55 current
= next(modified_iterator
, None)
60 class FileIOFolderMixin
:
61 def get_parent_folder(self
):
62 return FolderIO(os
.path
.dirname(self
.path
))
65 class ZipFileIO(file_io
.KnownContentFileIO
, FileIOFolderMixin
):
66 """For .zip and .egg archives"""
67 def __init__(self
, path
, code
, zip_path
):
68 super().__init
__(path
, code
)
69 self
._zip
_path
= zip_path
71 def get_last_modified(self
):
73 return os
.path
.getmtime(self
._zip
_path
)
74 except (FileNotFoundError
, PermissionError
, NotADirectoryError
):
78 class FileIO(file_io
.FileIO
, FileIOFolderMixin
):
82 class KnownContentFileIO(file_io
.KnownContentFileIO
, FileIOFolderMixin
):