Skip to content
Snippets Groups Projects
Commit d976e758 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

2.6.2: add satella.files.split

parent 6018483b
No related branches found
No related tags found
No related merge requests found
# v2.6.2
* _TBA_
* added `satella.files.split`
# v2.6.1
......
......@@ -9,4 +9,9 @@ read_re_sub_and_write
find_files
----------
.. autofunction:: satella.files.find_files
\ No newline at end of file
.. autofunction:: satella.files.find_files
split
-----
.. autofuction:: satella.files.split
__version__ = '2.6.2_a1'
__version__ = '2.6.2'
......@@ -2,7 +2,28 @@ import typing as tp
import re
import os
__all__ = ['read_re_sub_and_write', 'find_files']
__all__ = ['read_re_sub_and_write', 'find_files', 'split']
SEPARATORS = {'\\', '/'}
SEPARATORS.add(os.path.sep)
def _has_separator(path: str) -> bool:
return any(map(lambda x: x in path, SEPARATORS))
def split(path: str) -> tp.List[str]:
"""
An exact reverse of os.path.join
Is is true that
>>> os.path.join(split(a)) == a
"""
data = list(os.path.split(path))
while _has_separator(data[0]):
data = list(os.path.split(data[0])) + data[1:]
return data
def read_re_sub_and_write(path: str, pattern: tp.Union[re.compile, str],
......
......@@ -2,10 +2,16 @@ import os
import tempfile
import unittest
import shutil
from satella.files import read_re_sub_and_write, find_files
from satella.files import read_re_sub_and_write, find_files, split
class TestFiles(unittest.TestCase):
def test_split(self):
self.assertEqual(split('c:/windows/system32/system.exe'), ['c:/', 'windows', 'system32',
'system32.exe'])
self.assertEqual(split('~/user/something/./else'), ['~', 'user', 'something', '.',
'else'])
def setUp(self) -> None:
self.filename = tempfile.mktemp()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment