diff options
| author | prettyboy <[email protected]> | 2023-09-08 00:22:12 +0300 |
|---|---|---|
| committer | prettyboy <[email protected]> | 2023-09-08 00:46:04 +0300 |
| commit | 3a6cd865171eed9b89bf536cd242285f8b583a91 (patch) | |
| tree | 25e2756c125f7484fb118e0d5724212199662389 /library/python/codecs | |
| parent | 67f3f216950849664a29035458cfaa5d12a62846 (diff) | |
[build/plugins/ytest] Allow prebuilt linters for opensource
Без этого, ydb или не сможет запускать flake8 с помощью ya make.
Или к ним поедет сборка flake8.
Возможно последнее и не так плохо, но сейчас предлагается пока так
Diffstat (limited to 'library/python/codecs')
| -rw-r--r-- | library/python/codecs/__codecs.pyx | 61 | ||||
| -rw-r--r-- | library/python/codecs/__init__.py | 1 | ||||
| -rw-r--r-- | library/python/codecs/ya.make | 16 |
3 files changed, 78 insertions, 0 deletions
diff --git a/library/python/codecs/__codecs.pyx b/library/python/codecs/__codecs.pyx new file mode 100644 index 00000000000..42ec37fe886 --- /dev/null +++ b/library/python/codecs/__codecs.pyx @@ -0,0 +1,61 @@ +import six + +from libcpp cimport bool + +from util.generic.string cimport TString, TStringBuf + + +def to_bytes(s): + try: + return s.encode('utf-8') + except AttributeError: + pass + + return s + + +def from_bytes(s): + if six.PY3: + return s.decode('utf-8') + + return s + + +cdef extern from "library/cpp/blockcodecs/codecs.h" namespace "NBlockCodecs": + cdef cppclass ICodec: + void Encode(TStringBuf data, TString& res) nogil + void Decode(TStringBuf data, TString& res) nogil + + cdef const ICodec* Codec(const TStringBuf& name) except + + cdef TString ListAllCodecsAsString() except + + + +def dumps(name, data): + name = to_bytes(name) + + cdef const ICodec* codec = Codec(TStringBuf(name, len(name))) + cdef TString res + cdef TStringBuf cdata = TStringBuf(data, len(data)) + + with nogil: + codec.Encode(cdata, res) + + return res.c_str()[:res.length()] + + +def loads(name, data): + name = to_bytes(name) + + cdef const ICodec* codec = Codec(TStringBuf(name, len(name))) + cdef TString res + cdef TStringBuf cdata = TStringBuf(data, len(data)) + + with nogil: + codec.Decode(cdata, res) + + return res.c_str()[:res.length()] + +def list_all_codecs(): + cdef TString res = ListAllCodecsAsString() + + return from_bytes(res.c_str()[:res.length()]).split(',') diff --git a/library/python/codecs/__init__.py b/library/python/codecs/__init__.py new file mode 100644 index 00000000000..b9fb00deb0a --- /dev/null +++ b/library/python/codecs/__init__.py @@ -0,0 +1 @@ +from __codecs import loads, dumps, list_all_codecs # noqa diff --git a/library/python/codecs/ya.make b/library/python/codecs/ya.make new file mode 100644 index 00000000000..f42d115d5d1 --- /dev/null +++ b/library/python/codecs/ya.make @@ -0,0 +1,16 @@ +PY23_LIBRARY() + +PEERDIR( + library/cpp/blockcodecs + contrib/python/six +) + +PY_SRCS( + __init__.py +) + +BUILDWITH_CYTHON_CPP(__codecs.pyx) + +PY_REGISTER(__codecs) + +END() |
