diff options
| author | nkozlovskiy <[email protected]> | 2023-09-29 12:24:06 +0300 |
|---|---|---|
| committer | nkozlovskiy <[email protected]> | 2023-09-29 12:41:34 +0300 |
| commit | e0e3e1717e3d33762ce61950504f9637a6e669ed (patch) | |
| tree | bca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/importlib-resources | |
| parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) | |
add ydb deps
Diffstat (limited to 'contrib/python/importlib-resources')
| -rw-r--r-- | contrib/python/importlib-resources/importlib_resources/__init__.py | 47 | ||||
| -rw-r--r-- | contrib/python/importlib-resources/ya.make | 12 |
2 files changed, 59 insertions, 0 deletions
diff --git a/contrib/python/importlib-resources/importlib_resources/__init__.py b/contrib/python/importlib-resources/importlib_resources/__init__.py new file mode 100644 index 00000000000..bdbac100a92 --- /dev/null +++ b/contrib/python/importlib-resources/importlib_resources/__init__.py @@ -0,0 +1,47 @@ +import io +import pkgutil +from contextlib import contextmanager + +__all__ = 'read_binary read_text open_binary open_text is_resource contents path'.split() + +try: + FileNotFoundError +except NameError: + FileNotFoundError = OSError + + +def read_binary(package, resource): + data = pkgutil.get_data(package, resource) + if data is None: + raise FileNotFoundError('{} does not contain {!r}'.format(package, resource)) + return data + + +def read_text(package, resource, encoding='utf-8', errors='strict'): + return read_binary(package, resource).decode(encoding, errors) + + +def open_binary(package, resource): + return io.BytesIO(read_binary(package, resource)) + + +def open_text(package, resource, encoding='utf-8', errors='strict'): + return io.StringIO(read_text(package, resource, encoding, errors)) + + +def is_resource(package, name): + try: + read_binary(package, name) + return True + except (FileNotFoundError, OSError, IOError): + return False + + +def contents(package): + raise NotImplementedError('importlib_resources.contents is not implemented') + + +@contextmanager +def path(package, resource): + raise NotImplementedError('importlib_resources.path is not implemented') + yield None diff --git a/contrib/python/importlib-resources/ya.make b/contrib/python/importlib-resources/ya.make new file mode 100644 index 00000000000..21d607abef0 --- /dev/null +++ b/contrib/python/importlib-resources/ya.make @@ -0,0 +1,12 @@ +PY23_LIBRARY() + +LICENSE(Apache-2.0) + +PY_SRCS( + TOP_LEVEL + importlib_resources/__init__.py +) + +NO_LINT() + +END() |
