diff options
author | dvshkurko <dvshkurko@yandex-team.ru> | 2022-02-10 16:45:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:52 +0300 |
commit | c768a99151e47c3a4bb7b92c514d256abd301c4d (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/python/fs | |
parent | 321ee9bce31ec6e238be26dbcbe539cffa2c3309 (diff) | |
download | ydb-c768a99151e47c3a4bb7b92c514d256abd301c4d.tar.gz |
Restoring authorship annotation for <dvshkurko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/python/fs')
-rw-r--r-- | library/python/fs/__init__.py | 54 | ||||
-rw-r--r-- | library/python/fs/test/test_fs.py | 46 | ||||
-rw-r--r-- | library/python/fs/test/ya.make | 2 |
3 files changed, 51 insertions, 51 deletions
diff --git a/library/python/fs/__init__.py b/library/python/fs/__init__.py index 3c596f0e42..b1b7cde079 100644 --- a/library/python/fs/__init__.py +++ b/library/python/fs/__init__.py @@ -6,7 +6,7 @@ import logging import os import random import shutil -import six +import six import stat import sys @@ -128,7 +128,7 @@ def remove_dir(path): def fix_path_encoding(path): - return library.python.strings.to_str(path, library.python.strings.fs_encoding()) + return library.python.strings.to_str(path, library.python.strings.fs_encoding()) # File/directory remove @@ -201,7 +201,7 @@ def hardlink_or_copy(src, lnk): def should_fallback_to_copy(exc): if WindowsError is not None and isinstance(exc, WindowsError) and exc.winerror == 1142: # too many hardlinks return True - # cross-device hardlink or too many hardlinks, or some known WSL error + # cross-device hardlink or too many hardlinks, or some known WSL error if isinstance(exc, OSError) and exc.errno in ( errno.EXDEV, errno.EMLINK, @@ -217,7 +217,7 @@ def hardlink_or_copy(src, lnk): except Exception as e: logger.debug('Failed to hardlink %s to %s with error %s, will copy it', src, lnk, repr(e)) if should_fallback_to_copy(e): - copy2(src, lnk, follow_symlinks=False) + copy2(src, lnk, follow_symlinks=False) else: raise @@ -234,19 +234,19 @@ def symlink(src, lnk): os.symlink(src, lnk) -# shutil.copy2 with follow_symlinks=False parameter (Unix only) -def copy2(src, lnk, follow_symlinks=True): - if six.PY3: - shutil.copy2(src, lnk, follow_symlinks=follow_symlinks) - return - - if follow_symlinks or not os.path.islink(src): - shutil.copy2(src, lnk) - return - - symlink(os.readlink(src), lnk) - - +# shutil.copy2 with follow_symlinks=False parameter (Unix only) +def copy2(src, lnk, follow_symlinks=True): + if six.PY3: + shutil.copy2(src, lnk, follow_symlinks=follow_symlinks) + return + + if follow_symlinks or not os.path.islink(src): + shutil.copy2(src, lnk) + return + + symlink(os.readlink(src), lnk) + + # Recursively hardlink directory # Uses plain hardlink for files # Dst must not exist @@ -299,12 +299,12 @@ def read_file(path, binary=True): @errorfix_win def read_file_unicode(path, binary=True, enc='utf-8'): if not binary: - if six.PY2: - with open(path, 'r') as f: - return library.python.strings.to_unicode(f.read(), enc) - else: - with open(path, 'r', encoding=enc) as f: - return f.read() + if six.PY2: + with open(path, 'r') as f: + return library.python.strings.to_unicode(f.read(), enc) + else: + with open(path, 'r', encoding=enc) as f: + return f.read() # codecs.open is always binary with codecs.open(path, 'r', encoding=enc, errors=library.python.strings.ENCODING_ERRORS_POLICY) as f: return f.read() @@ -417,9 +417,9 @@ def copytree3( else: ignored_names = set() - if not (dirs_exist_ok and os.path.isdir(dst)): - os.makedirs(dst) - + if not (dirs_exist_ok and os.path.isdir(dst)): + os.makedirs(dst) + errors = [] for name in names: if name in ignored_names: @@ -441,7 +441,7 @@ def copytree3( # otherwise let the copy occurs. copy2 will raise an error copy_function(srcname, dstname) elif os.path.isdir(srcname): - copytree3(srcname, dstname, symlinks, ignore, copy_function, dirs_exist_ok=dirs_exist_ok) + copytree3(srcname, dstname, symlinks, ignore, copy_function, dirs_exist_ok=dirs_exist_ok) else: # Will raise a SpecialFileError for unsupported file types copy_function(srcname, dstname) diff --git a/library/python/fs/test/test_fs.py b/library/python/fs/test/test_fs.py index 00bd7e3d29..9e2c70c069 100644 --- a/library/python/fs/test/test_fs.py +++ b/library/python/fs/test/test_fs.py @@ -4,10 +4,10 @@ import errno import os import pytest import shutil -import six +import six import library.python.fs -import library.python.strings +import library.python.strings import library.python.tmp import library.python.windows @@ -23,7 +23,7 @@ def in_env(case): def mkfile(path, data=''): - with open(path, 'wb') as f: + with open(path, 'wb') as f: if data: f.write(data) if isinstance(data, six.binary_type) else f.write( data.encode(library.python.strings.fs_encoding()) @@ -40,8 +40,8 @@ def mktree_example(path, name): def file_data(path): - with open(path, 'rb') as f: - return f.read().decode('utf-8') + with open(path, 'rb') as f: + return f.read().decode('utf-8') def serialize_tree(path): @@ -92,8 +92,8 @@ def test_errorfix_win(): erroneous_func() assert errinfo.value.errno == errno.EACCES assert errinfo.value.filename == 'unknown/file' - # See transcode_error, which encodes strerror, in library/python/windows/__init__.py - assert isinstance(errinfo.value.strerror, (six.binary_type, six.text_type)) + # See transcode_error, which encodes strerror, in library/python/windows/__init__.py + assert isinstance(errinfo.value.strerror, (six.binary_type, six.text_type)) assert errinfo.value.strerror @@ -101,8 +101,8 @@ def test_custom_fs_error(): with pytest.raises(OSError) as errinfo: raise library.python.fs.CustomFsError(errno.EACCES, filename='some/file') assert errinfo.value.errno == errno.EACCES - # See transcode_error, which encodes strerror, in library/python/windows/__init__.py - assert isinstance(errinfo.value.strerror, (six.binary_type, six.text_type)) + # See transcode_error, which encodes strerror, in library/python/windows/__init__.py + assert isinstance(errinfo.value.strerror, (six.binary_type, six.text_type)) assert errinfo.value.filename == 'some/file' @@ -806,14 +806,14 @@ def test_copy_tree_file_exists(path): @in_env def test_read_file(path): mkfile(path('src'), 'SRC') - assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == 'SRC' + assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == 'SRC' assert library.python.fs.read_file(path('src'), binary=False) == 'SRC' @in_env def test_read_file_empty(path): mkfile(path('src')) - assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == '' + assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == '' assert library.python.fs.read_file(path('src'), binary=False) == '' @@ -834,7 +834,7 @@ def test_read_file_multiline_crlf(path): library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == 'SRC line 1\r\nSRC line 2\r\n' ) - if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3 + if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3 assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n' else: assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\r\nSRC line 2\r\n' @@ -879,7 +879,7 @@ def test_read_file_unicode_multiline_crlf(path): mkfile(path('src_cp1251'), s.encode('cp1251')) assert library.python.fs.read_file_unicode(path('src')) == s assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s - if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3 + if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3 assert library.python.fs.read_file_unicode(path('src'), binary=False) == u'АБВ\nИ еще\n' assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == u'АБВ\nИ еще\n' else: @@ -984,14 +984,14 @@ def test_hardlink_or_copy(): def test_remove_tree_unicode(): path = u"test_remove_tree_unicode/русский".encode("utf-8") os.makedirs(path) - library.python.fs.remove_tree(six.text_type("test_remove_tree_unicode")) + library.python.fs.remove_tree(six.text_type("test_remove_tree_unicode")) assert not os.path.exists("test_remove_tree_unicode") def test_remove_tree_safe_unicode(): path = u"test_remove_tree_safe_unicode/русский".encode("utf-8") os.makedirs(path) - library.python.fs.remove_tree_safe(six.text_type("test_remove_tree_safe_unicode")) + library.python.fs.remove_tree_safe(six.text_type("test_remove_tree_safe_unicode")) assert not os.path.exists("test_remove_tree_safe_unicode") @@ -1011,14 +1011,14 @@ def test_copy_tree_custom_copy_function(): assert len(copied) == 2 assert yatest.common.work_path("test_copy_tree_dst/deepper/deepper.txt") in copied assert yatest.common.work_path("test_copy_tree_dst/deepper/inner/inner.txt") in copied - - -def test_copy2(): - library.python.fs.symlink("non-existent", "link") - library.python.fs.copy2("link", "link2", follow_symlinks=False) - - assert os.path.islink("link2") - assert os.readlink("link2") == "non-existent" + + +def test_copy2(): + library.python.fs.symlink("non-existent", "link") + library.python.fs.copy2("link", "link2", follow_symlinks=False) + + assert os.path.islink("link2") + assert os.readlink("link2") == "non-existent" def test_commonpath(): diff --git a/library/python/fs/test/ya.make b/library/python/fs/test/ya.make index b0e636c446..33e3f5b4ff 100644 --- a/library/python/fs/test/ya.make +++ b/library/python/fs/test/ya.make @@ -1,6 +1,6 @@ OWNER(g:yatool) -PY23_TEST() +PY23_TEST() TEST_SRCS( test_fs.py |