aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/strings
diff options
context:
space:
mode:
authorAleksandr <ivansduck@gmail.com>2022-02-10 16:47:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:52 +0300
commitea6c5b7f172becca389cacaff7d5f45f6adccbe6 (patch)
treed16cef493ac1e092b4a03ab9437ec06ffe3d188f /library/python/strings
parent37de222addabbef336dcaaea5f7c7645a629fc6d (diff)
downloadydb-ea6c5b7f172becca389cacaff7d5f45f6adccbe6.tar.gz
Restoring authorship annotation for Aleksandr <ivansduck@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/strings')
-rw-r--r--library/python/strings/__init__.py34
-rw-r--r--library/python/strings/strings.py48
-rw-r--r--library/python/strings/ut/test_strings.py14
-rw-r--r--library/python/strings/ya.make10
4 files changed, 53 insertions, 53 deletions
diff --git a/library/python/strings/__init__.py b/library/python/strings/__init__.py
index bd6bf6e7ce..47a731b1de 100644
--- a/library/python/strings/__init__.py
+++ b/library/python/strings/__init__.py
@@ -1,17 +1,17 @@
-# flake8 noqa: F401
-
-from .strings import (
- DEFAULT_ENCODING,
- ENCODING_ERRORS_POLICY,
- encode,
- fs_encoding,
- get_stream_encoding,
- guess_default_encoding,
- left_strip,
- locale_encoding,
- stringize_deep,
- to_basestring,
- to_str,
- to_unicode,
- unicodize_deep,
-)
+# flake8 noqa: F401
+
+from .strings import (
+ DEFAULT_ENCODING,
+ ENCODING_ERRORS_POLICY,
+ encode,
+ fs_encoding,
+ get_stream_encoding,
+ guess_default_encoding,
+ left_strip,
+ locale_encoding,
+ stringize_deep,
+ to_basestring,
+ to_str,
+ to_unicode,
+ unicodize_deep,
+)
diff --git a/library/python/strings/strings.py b/library/python/strings/strings.py
index 5bfddfe78a..476a797117 100644
--- a/library/python/strings/strings.py
+++ b/library/python/strings/strings.py
@@ -9,7 +9,7 @@ import library.python.func
logger = logging.getLogger(__name__)
-DEFAULT_ENCODING = 'utf-8'
+DEFAULT_ENCODING = 'utf-8'
ENCODING_ERRORS_POLICY = 'replace'
@@ -40,7 +40,7 @@ def to_basestring(value):
to_text = to_basestring
-def to_unicode(value, from_enc=DEFAULT_ENCODING):
+def to_unicode(value, from_enc=DEFAULT_ENCODING):
if isinstance(value, six.text_type):
return value
if isinstance(value, six.binary_type):
@@ -52,7 +52,7 @@ def to_unicode(value, from_enc=DEFAULT_ENCODING):
# Optional from_enc enables transcoding
-def to_str(value, to_enc=DEFAULT_ENCODING, from_enc=None):
+def to_str(value, to_enc=DEFAULT_ENCODING, from_enc=None):
if isinstance(value, six.binary_type):
if from_enc is None or to_enc == from_enc:
# Unknown input encoding or input and output encoding are the same
@@ -63,32 +63,32 @@ def to_str(value, to_enc=DEFAULT_ENCODING, from_enc=None):
return six.binary_type(value)
-def _convert_deep(x, enc, convert, relaxed=True):
+def _convert_deep(x, enc, convert, relaxed=True):
if x is None:
return None
if isinstance(x, (six.text_type, six.binary_type)):
return convert(x, enc)
if isinstance(x, dict):
return {convert(k, enc): _convert_deep(v, enc, convert, relaxed) for k, v in six.iteritems(x)}
- if isinstance(x, list):
- return [_convert_deep(e, enc, convert, relaxed) for e in x]
- if isinstance(x, tuple):
- return tuple([_convert_deep(e, enc, convert, relaxed) for e in x])
-
- if relaxed:
- return x
+ if isinstance(x, list):
+ return [_convert_deep(e, enc, convert, relaxed) for e in x]
+ if isinstance(x, tuple):
+ return tuple([_convert_deep(e, enc, convert, relaxed) for e in x])
+
+ if relaxed:
+ return x
raise TypeError('unsupported type')
-def unicodize_deep(x, enc=DEFAULT_ENCODING, relaxed=True):
- return _convert_deep(x, enc, to_unicode, relaxed)
+def unicodize_deep(x, enc=DEFAULT_ENCODING, relaxed=True):
+ return _convert_deep(x, enc, to_unicode, relaxed)
-def stringize_deep(x, enc=DEFAULT_ENCODING, relaxed=True):
- return _convert_deep(x, enc, to_str, relaxed)
+def stringize_deep(x, enc=DEFAULT_ENCODING, relaxed=True):
+ return _convert_deep(x, enc, to_str, relaxed)
-@library.python.func.memoize()
+@library.python.func.memoize()
def locale_encoding():
try:
loc = locale.getdefaultlocale()[1]
@@ -109,10 +109,10 @@ def fs_encoding():
def guess_default_encoding():
enc = locale_encoding()
- return enc if enc else DEFAULT_ENCODING
+ return enc if enc else DEFAULT_ENCODING
-@library.python.func.memoize()
+@library.python.func.memoize()
def get_stream_encoding(stream):
if stream.encoding:
try:
@@ -120,10 +120,10 @@ def get_stream_encoding(stream):
return stream.encoding
except LookupError:
pass
- return DEFAULT_ENCODING
-
-
-def encode(value, encoding=DEFAULT_ENCODING):
+ return DEFAULT_ENCODING
+
+
+def encode(value, encoding=DEFAULT_ENCODING):
if isinstance(value, six.binary_type):
- value = value.decode(encoding, errors='ignore')
- return value.encode(encoding)
+ value = value.decode(encoding, errors='ignore')
+ return value.encode(encoding)
diff --git a/library/python/strings/ut/test_strings.py b/library/python/strings/ut/test_strings.py
index dd0c694ee1..663ff24b14 100644
--- a/library/python/strings/ut/test_strings.py
+++ b/library/python/strings/ut/test_strings.py
@@ -115,7 +115,7 @@ def test_stringize_deep():
assert library.python.strings.stringize_deep({
'key 1': 'value 1',
u'ключ 2': u'значение 2',
- 'list': [u'ключ 2', 'key 1', (u'к', 2)]
+ 'list': [u'ключ 2', 'key 1', (u'к', 2)]
}) == {
'key 1' if six.PY2 else b'key 1': 'value 1' if six.PY2 else b'value 1',
u'ключ 2'.encode('utf-8'): u'значение 2'.encode('utf-8'),
@@ -157,9 +157,9 @@ def test_stringize_deep_plain():
def test_stringize_deep_nonstr():
with pytest.raises(TypeError):
- library.python.strings.stringize_deep(Convertible(), relaxed=False)
- x = Convertible()
- assert x == library.python.strings.stringize_deep(x)
+ library.python.strings.stringize_deep(Convertible(), relaxed=False)
+ x = Convertible()
+ assert x == library.python.strings.stringize_deep(x)
def test_unicodize_deep():
@@ -200,6 +200,6 @@ def test_unicodize_deep_plain():
def test_unicodize_deep_nonstr():
with pytest.raises(TypeError):
- library.python.strings.unicodize_deep(Convertible(), relaxed=False)
- x = Convertible()
- assert x == library.python.strings.stringize_deep(x)
+ library.python.strings.unicodize_deep(Convertible(), relaxed=False)
+ x = Convertible()
+ assert x == library.python.strings.stringize_deep(x)
diff --git a/library/python/strings/ya.make b/library/python/strings/ya.make
index 7e0b033717..5285c13774 100644
--- a/library/python/strings/ya.make
+++ b/library/python/strings/ya.make
@@ -2,11 +2,11 @@ OWNER(g:yatool)
PY23_LIBRARY()
-PY_SRCS(
- __init__.py
- CYTHONIZE_PY
- strings.py
-)
+PY_SRCS(
+ __init__.py
+ CYTHONIZE_PY
+ strings.py
+)
PEERDIR(
library/python/func