aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/importer.pxi
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /library/python/runtime_py3/importer.pxi
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/runtime_py3/importer.pxi')
-rw-r--r--library/python/runtime_py3/importer.pxi104
1 files changed, 52 insertions, 52 deletions
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 904f94dea2..6abbb3cf58 100644
--- a/library/python/runtime_py3/importer.pxi
+++ b/library/python/runtime_py3/importer.pxi
@@ -333,58 +333,58 @@ class ResourceImporter(object):
for m in self.arcadia_source_finder.iter_modules(self._package_prefix, prefix):
yield m
- def get_resource_reader(self, fullname):
- try:
- if not self.is_package(fullname):
- return None
- except ImportError:
- return None
- return _ResfsResourceReader(self, fullname)
-
-
-class _ResfsResourceReader:
-
- def __init__(self, importer, fullname):
- self.importer = importer
- self.fullname = fullname
-
- import os
- self.prefix = "{}/".format(os.path.dirname(self.importer.get_filename(self.fullname)))
-
- def open_resource(self, resource):
- path = f'{self.prefix}{resource}'
- from io import BytesIO
- try:
- return BytesIO(self.importer.get_data(path))
- except OSError:
- raise FileNotFoundError(path)
-
- def resource_path(self, resource):
- # All resources are in the binary file, so there is no path to the file.
- # Raising FileNotFoundError tells the higher level API to extract the
- # binary data and create a temporary file.
- raise FileNotFoundError
-
- def is_resource(self, name):
- path = f'{self.prefix}{name}'
- try:
- self.importer.get_data(path)
- except OSError:
- return False
- return True
-
- def contents(self):
- subdirs_seen = set()
- for key in resfs_files(self.prefix):
- relative = key[len(self.prefix):]
- res_or_subdir, *other = relative.split(b'/')
- if not other:
- yield _s(res_or_subdir)
- elif res_or_subdir not in subdirs_seen:
- subdirs_seen.add(res_or_subdir)
- yield _s(res_or_subdir)
-
-
+ def get_resource_reader(self, fullname):
+ try:
+ if not self.is_package(fullname):
+ return None
+ except ImportError:
+ return None
+ return _ResfsResourceReader(self, fullname)
+
+
+class _ResfsResourceReader:
+
+ def __init__(self, importer, fullname):
+ self.importer = importer
+ self.fullname = fullname
+
+ import os
+ self.prefix = "{}/".format(os.path.dirname(self.importer.get_filename(self.fullname)))
+
+ def open_resource(self, resource):
+ path = f'{self.prefix}{resource}'
+ from io import BytesIO
+ try:
+ return BytesIO(self.importer.get_data(path))
+ except OSError:
+ raise FileNotFoundError(path)
+
+ def resource_path(self, resource):
+ # All resources are in the binary file, so there is no path to the file.
+ # Raising FileNotFoundError tells the higher level API to extract the
+ # binary data and create a temporary file.
+ raise FileNotFoundError
+
+ def is_resource(self, name):
+ path = f'{self.prefix}{name}'
+ try:
+ self.importer.get_data(path)
+ except OSError:
+ return False
+ return True
+
+ def contents(self):
+ subdirs_seen = set()
+ for key in resfs_files(self.prefix):
+ relative = key[len(self.prefix):]
+ res_or_subdir, *other = relative.split(b'/')
+ if not other:
+ yield _s(res_or_subdir)
+ elif res_or_subdir not in subdirs_seen:
+ subdirs_seen.add(res_or_subdir)
+ yield _s(res_or_subdir)
+
+
class BuiltinSubmoduleImporter(BuiltinImporter):
@classmethod
def find_spec(cls, fullname, path=None, target=None):