lib/util/fs.py
def _split_path_components(path):
    '''
    Splits `path` into a list of path components. The resulting list will start
    with directory names, leading up to the basename of the path.
    e.g.    '/usr/lib' -> ['', usr', 'lib']
            'C:\\Users' -> ['C:', 'Users']
    '''
    if not isinstance(path, str):
        raise TypeError('path must be a str: %r' % (path))
    primary_dirsep = os.sep
    secondary_dirsep = os.altsep

    if not secondary_dirsep:
        # easy case, only one directory separator, so split on it
        return path.split(primary_dirsep)

    # ugh, more complicated case
    # the file system might permit both directory separators
    # e.g.  'C:\\Program Files/Sublime Text 3'
    # need to split on both to get the correct result in that case...

    def _iter_components(path=path):
        current_path = path[:]
        while current_path:
            primary_position = current_path.find(primary_dirsep)
            secondary_position = current_path.find(secondary_dirsep)
            split_position = -1

            # `str.find` returns -1 if no match, so check that first
            if primary_position >= 0 and secondary_position >= 0:
                # both are present - figure out which is first
                if primary_position > secondary_position:
                    # secondary separator first - split on second
                    split_position = secondary_position
                else:
                    # primary separator first - split on first
                    split_position = primary_position
            elif primary_position >= 0:
                # primary separator only - split on it
                # technically we can just split on the one separator and
                # yield the list items, but meh
                split_position = primary_position
            elif secondary_position >= 0:
                split_position = secondary_position
            # else, nothing to split

            if split_position >= 0:
                # perform split from 0 to split_position (non-inclusive), and
                # from split_position+1 to the end
                head = (
                    current_path[:split_position]
                    if split_position > 0 else ''
                )
                tail = (
                    current_path[split_position + 1:]
                    if split_position < len(current_path) else ''
                )

                yield head
                current_path = tail
            else:
                yield current_path
                current_path = ''

    return list(_iter_components(path))

    Splits `path` into a list of path components. The resulting list will start
    with directory names, leading up to the basename of the path.
    e.g.    '/usr/lib' -> ['', usr', 'lib']
            'C:\\Users' -> ['C:', 'Users']
    
Splits `path` into a list of path components. The resulting list will start
with directory names, leading up to the basename of the path.
Splits ` path ` into a list of path components . The resulting list will start with directory names leading up to the basename of the path .
def _split_path_components(path):
    if not isinstance(path, str):
        raise TypeError('path must be a str: %r' % (path))
    primary_dirsep = os.sep
    secondary_dirsep = os.altsep
    if not secondary_dirsep:
        return path.split(primary_dirsep)
    def _iter_components(path=path):
        current_path = path[:]
        while current_path:
            primary_position = current_path.find(primary_dirsep)
            secondary_position = current_path.find(secondary_dirsep)
            split_position = -1
            if primary_position >= 0 and secondary_position >= 0:
                if primary_position > secondary_position:
                    split_position = secondary_position
                else:
                    split_position = primary_position
            elif primary_position >= 0:
                split_position = primary_position
            elif secondary_position >= 0:
                split_position = secondary_position
            if split_position >= 0:
                head = (
                    current_path[:split_position]
                    if split_position > 0 else ''
                )
                tail = (
                    current_path[split_position + 1:]
                    if split_position < len(current_path) else ''
                )
                yield head
                current_path = tail
            else:
                yield current_path
                current_path = ''
    return list(_iter_components(path))
def _split_path_components ( path ) : if not isinstance ( path , str ) : raise TypeError ( 'path must be a str: %r' % ( path ) ) primary_dirsep = os . sep secondary_dirsep = os . altsep if not secondary_dirsep : return path . split ( primary_dirsep ) def _iter_components ( path = path ) : current_path = path [ : ] while current_path : primary_position = current_path . find ( primary_dirsep ) secondary_position = current_path . find ( secondary_dirsep ) split_position = - 1 if primary_position >= 0 and secondary_position >= 0 : if primary_position > secondary_position : split_position = secondary_position else : split_position = primary_position elif primary_position >= 0 : split_position = primary_position elif secondary_position >= 0 : split_position = secondary_position if split_position >= 0 : head = ( current_path [ : split_position ] if split_position > 0 else '' ) tail = ( current_path [ split_position + 1 : ] if split_position < len ( current_path ) else '' ) yield head current_path = tail else : yield current_path current_path = '' return list ( _iter_components ( path ) )
Splits `path` into a list of path components.
Splits ` path ` into a list of path components .
'''
    Splits `path` into a list of path components. The resulting list will start
    with directory names, leading up to the basename of the path.
    e.g.    '/usr/lib' -> ['', usr', 'lib']
            'C:\\Users' -> ['C:', 'Users']
    ''' # easy case, only one directory separator, so split on it # ugh, more complicated case # the file system might permit both directory separators # e.g.  'C:\\Program Files/Sublime Text 3' # need to split on both to get the correct result in that case... # `str.find` returns -1 if no match, so check that first # both are present - figure out which is first # secondary separator first - split on second # primary separator first - split on first # primary separator only - split on it # technically we can just split on the one separator and # yield the list items, but meh # else, nothing to split # perform split from 0 to split_position (non-inclusive), and # from split_position+1 to the end
path