forked from VimPlug/jedi
Start using file io when opening random modules
This commit is contained in:
@@ -3,13 +3,31 @@ import os
|
||||
from parso import file_io
|
||||
|
||||
|
||||
class _ListDirMixin(object):
|
||||
def listdir(self):
|
||||
directory = self.path
|
||||
return os.listdir(directory)
|
||||
class AbstractFolderIO(object):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def list(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_file_io(self, name):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ZipFileIO(file_io.KnownContentFileIO):
|
||||
class FolderIO(AbstractFolderIO):
|
||||
def list(self):
|
||||
return os.listdir(self.path)
|
||||
|
||||
def get_file_io(self, name):
|
||||
return FileIO(os.path.join(self.path, name))
|
||||
|
||||
|
||||
class FileIOFolderMixin(object):
|
||||
def get_parent_folder(self):
|
||||
return FolderIO(os.path.dirname(self.path))
|
||||
|
||||
|
||||
class ZipFileIO(file_io.KnownContentFileIO, FileIOFolderMixin):
|
||||
"""For .zip and .egg archives"""
|
||||
def __init__(self, path, code, zip_path):
|
||||
super(ZipFileIO, self).__init__(path, code)
|
||||
@@ -21,13 +39,10 @@ class ZipFileIO(file_io.KnownContentFileIO):
|
||||
except OSError: # Python 3 would probably only need FileNotFoundError
|
||||
return None
|
||||
|
||||
def listdir(self):
|
||||
return []
|
||||
|
||||
|
||||
class FileIO(_ListDirMixin, file_io.FileIO):
|
||||
class FileIO(file_io.FileIO, FileIOFolderMixin):
|
||||
pass
|
||||
|
||||
|
||||
class KnownContentFileIO(file_io.KnownContentFileIO):
|
||||
class KnownContentFileIO(file_io.KnownContentFileIO, FileIOFolderMixin):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user