diff options
author | Aleksandr <ivansduck@gmail.com> | 2022-02-10 16:47:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:52 +0300 |
commit | b05913d1c3c02a773578bceb7285084d2933ae86 (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /library/python/strings/strings.py | |
parent | ea6c5b7f172becca389cacaff7d5f45f6adccbe6 (diff) | |
download | ydb-b05913d1c3c02a773578bceb7285084d2933ae86.tar.gz |
Restoring authorship annotation for Aleksandr <ivansduck@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/python/strings/strings.py')
-rw-r--r-- | library/python/strings/strings.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/library/python/strings/strings.py b/library/python/strings/strings.py index 476a797117..5bfddfe78a 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) |