diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/resource | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/resource')
-rw-r--r-- | library/python/resource/__init__.py | 49 | ||||
-rw-r--r-- | library/python/resource/ut/lib/qw.txt | 1 | ||||
-rw-r--r-- | library/python/resource/ut/lib/test_simple.py | 31 | ||||
-rw-r--r-- | library/python/resource/ut/lib/ya.make | 17 | ||||
-rw-r--r-- | library/python/resource/ut/py2/ya.make | 9 | ||||
-rw-r--r-- | library/python/resource/ut/py3/ya.make | 9 | ||||
-rw-r--r-- | library/python/resource/ut/ya.make | 6 | ||||
-rw-r--r-- | library/python/resource/ya.make | 13 |
8 files changed, 135 insertions, 0 deletions
diff --git a/library/python/resource/__init__.py b/library/python/resource/__init__.py new file mode 100644 index 0000000000..26503ef7fc --- /dev/null +++ b/library/python/resource/__init__.py @@ -0,0 +1,49 @@ +from __res import find as __find, count, key_by_index, resfs_files as __resfs_files +from __res import resfs_read, resfs_resolve, resfs_src # noqa + +import six + + +def iterkeys(prefix='', strip_prefix=False): + decode = lambda s: s + if isinstance(prefix, six.text_type): + prefix = prefix.encode('utf-8') + decode = lambda s: s.decode('utf-8') + + for i in six.moves.range(count()): + key = key_by_index(i) + if key.startswith(prefix): + if strip_prefix: + key = key[len(prefix):] + yield decode(key) + + +def itervalues(prefix=b''): + for key in iterkeys(prefix=prefix): + value = find(key) + yield value + + +def iteritems(prefix='', strip_prefix=False): + for key in iterkeys(prefix=prefix): + value = find(key) + if strip_prefix: + key = key[len(prefix):] + yield key, value + + +def resfs_file_exists(path): + return resfs_src(path, resfs_file=True) is not None + + +def resfs_files(prefix=''): + decode = lambda s: s + if isinstance(prefix, six.text_type): + decode = lambda s: s.decode('utf-8') + return [decode(s) for s in __resfs_files(prefix=prefix)] + + +def find(path): + if isinstance(path, six.text_type): + path = path.encode('utf-8') + return __find(path) diff --git a/library/python/resource/ut/lib/qw.txt b/library/python/resource/ut/lib/qw.txt new file mode 100644 index 0000000000..50e37d5cac --- /dev/null +++ b/library/python/resource/ut/lib/qw.txt @@ -0,0 +1 @@ +na gorshke sidel korol diff --git a/library/python/resource/ut/lib/test_simple.py b/library/python/resource/ut/lib/test_simple.py new file mode 100644 index 0000000000..52f006ff91 --- /dev/null +++ b/library/python/resource/ut/lib/test_simple.py @@ -0,0 +1,31 @@ +import six # noqa + +import library.python.resource as rs + +text = b'na gorshke sidel korol\n' + + +def test_find(): + assert rs.find('/qw.txt') == text + + +def test_iter(): + assert set(rs.iterkeys()).issuperset({'/qw.txt', '/prefix/1.txt', '/prefix/2.txt'}) + assert set(rs.iterkeys(prefix='/prefix/')) == {'/prefix/1.txt', '/prefix/2.txt'} + assert set(rs.iterkeys(prefix='/prefix/', strip_prefix=True)) == {'1.txt', '2.txt'} + assert set(rs.iteritems(prefix='/prefix')) == { + ('/prefix/1.txt', text), + ('/prefix/2.txt', text), + } + assert set(rs.iteritems(prefix='/prefix', strip_prefix=True)) == { + ('/1.txt', text), + ('/2.txt', text), + } + + +def test_resfs_files(): + assert 'contrib/python/py/.dist-info/METADATA' in set(rs.resfs_files()) + + +def test_resfs_read(): + assert 'Metadata-Version' in rs.resfs_read('contrib/python/py/.dist-info/METADATA').decode('utf-8') diff --git a/library/python/resource/ut/lib/ya.make b/library/python/resource/ut/lib/ya.make new file mode 100644 index 0000000000..693e388878 --- /dev/null +++ b/library/python/resource/ut/lib/ya.make @@ -0,0 +1,17 @@ +PY23_LIBRARY() + +OWNER(pg) + +TEST_SRCS(test_simple.py) + +PEERDIR( + library/python/resource +) + +RESOURCE( + qw.txt /qw.txt + qw.txt /prefix/1.txt + qw.txt /prefix/2.txt +) + +END() diff --git a/library/python/resource/ut/py2/ya.make b/library/python/resource/ut/py2/ya.make new file mode 100644 index 0000000000..5085610faf --- /dev/null +++ b/library/python/resource/ut/py2/ya.make @@ -0,0 +1,9 @@ +PY2TEST() + +OWNER(pg) + +PEERDIR( + library/python/resource/ut/lib +) + +END() diff --git a/library/python/resource/ut/py3/ya.make b/library/python/resource/ut/py3/ya.make new file mode 100644 index 0000000000..64eb2e83ce --- /dev/null +++ b/library/python/resource/ut/py3/ya.make @@ -0,0 +1,9 @@ +PY3TEST() + +OWNER(pg) + +PEERDIR( + library/python/resource/ut/lib +) + +END() diff --git a/library/python/resource/ut/ya.make b/library/python/resource/ut/ya.make new file mode 100644 index 0000000000..a5ec192d74 --- /dev/null +++ b/library/python/resource/ut/ya.make @@ -0,0 +1,6 @@ +OWNER(pg) + +RECURSE( + py2 + py3 +) diff --git a/library/python/resource/ya.make b/library/python/resource/ya.make new file mode 100644 index 0000000000..989329fa4b --- /dev/null +++ b/library/python/resource/ya.make @@ -0,0 +1,13 @@ +PY23_LIBRARY() + +OWNER(pg) + +PEERDIR( + contrib/python/six +) + +PY_SRCS(__init__.py) + +END() + +RECURSE_FOR_TESTS(ut) |