Given a relative path like 'a/b/c/d', yield all ascending path components like:

        'a/b/c/d'
        'a/b/c'
        'a/b'
        'a'
        ''
185208
def recursive_dirname(f):
  
  prev = None
  while f != prev:
    yield f
    prev = f
    f = os.path.dirname(f)
  yield ''
1193383
def path_for(self, *args):
        """"""
        if args and args[0].startswith(os.path.sep):
            return os.path.join(*args)
        return os.path.join(self._root_path or os.getcwd(), *args)
929131
def _items_to_rela_paths(self, items):
        """"""
        paths = []
        for item in items:
            if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
                paths.append(self._to_relative_path(item.path))
            elif isinstance(item, string_types):
                paths.append(self._to_relative_path(item))
            else:
                raise TypeError("Invalid item type: %r" % item)
        # END for each item
        return paths
248311
def p_path(self, p):
        """"""

        if len(p)==2:
            p[0] = RegExpPropositional(p[1])
        elif len(p)==3:
            if p[2]==Symbols.PATH_TEST.value:
                p[0] = RegExpTest(p[1])
            elif p[2] == Symbols.PATH_STAR.value:
                p[0] = RegExpStar(p[1])
            else:
                raise ValueError
        elif len(p)==4:
            if p[2]==Symbols.PATH_UNION.value:
                p[0] = RegExpUnion([p[1], p[3]])
            elif p[2] == Symbols.PATH_SEQUENCE.value:
                p[0] = RegExpSequence([p[1], p[3]])
            else:
                raise ValueError
        else:
            raise ValueError
901787
def _add_path_traversal_strings(self, lib):
        '''
        
        '''
        entries = [
            (('/etc/passwd', 'absolute - /etc/passwd')),
            (('./../../../../../../../../../../../../../../etc/passwd', 'relative - /etc/passwd')),
            (('../../../../../../../../../../../../../../etc/passwd', 'relative - /etc/passwd')),
            (('/proc/cpuinfo', 'absolute path - /proc/cpuinfo')),
            (('./../../../../../../../../../../../../../../proc/cpuinfo', 'relative - /proc/cpuinfo')),
            (('../../../../../../../../../../../../../../proc/cpuinfo', 'relative - /proc/cpuinfo')),
            (('~/.profile', 'absolute - home')),
            (('$HOME/.profile', 'environment - home')),
            (('/../../../../../../../../../../../../boot.ini', 'relative - boot.ini')),
        ]
        for (s, desc) in entries:
            lib.append((s, 'path traversal - %s' % desc))
521953
def parse_relative_path(root_path, experiment_config, key):
    ''''''
    if experiment_config.get(key) and not os.path.isabs(experiment_config.get(key)):
        absolute_path = os.path.join(root_path, experiment_config.get(key))
        print_normal('expand %s: %s to %s ' % (key, experiment_config[key], absolute_path))
        experiment_config[key] = absolute_path
496250
def relative_path(self, key):
    ''''''
    key = str(key)                # stringify
    key = key.replace(':', '/')   # turn namespace delimiters into slashes
    key = key[1:]                 # remove first slash (absolute)
    if not self.case_sensitive:
      key = key.lower()           # coerce to lowercase
    return os.path.normpath(key)
41772
def make_relative_to_root(path):
  """"""
  return os.path.normpath(path.format(pex_root=ENV.PEX_ROOT))
194768
def _PathStripPrefix(self, path):
    
    if path.startswith('\\\\.\\') or path.startswith('\\\\?\\'):
      if len(path) < 7 or path[5] != ':' or path[6] != self._PATH_SEPARATOR:
        # Cannot handle a non-volume path.
        return None

      path = path[7:]

    elif path.startswith('\\\\'):
      # Cannot handle an UNC path.
      return None

    elif len(path) >= 3 and path[1] == ':':
      # Check if the path is a Volume 'absolute' path.
      if path[2] != self._PATH_SEPARATOR:
        # Cannot handle a Volume 'relative' path.
        return None

      path = path[3:]

    elif path.startswith('\\'):
      path = path[1:]

    else:
      # Cannot handle a relative path.
      return None

    return path
1144456
def _split_path(path):
    
    path = path.strip('/')
    list_path = path.split('/')
    sentinel = list_path.pop(0)
    return sentinel, list_path, path
440362
def path_pieces(vault_path):
    """"""
    path_bits = vault_path.split('/')
    path = '/'.join(path_bits[0:len(path_bits) - 1])
    key = path_bits[len(path_bits) - 1]
    return path, key
598728
public static String relativePath(String base,
                                      String pathSpec,
                                      String path )
    {
        String info=pathInfo(pathSpec,path);
        if (info==null)
            info=path;

        if( info.startsWith( "./"))
            info = info.substring( 2);
        if( base.endsWith( "/"))
            if( info.startsWith( "/"))
                path = base + info.substring(1);
            else
                path = base + info;
        else
            if( info.startsWith( "/"))
                path = base + info;
            else
                path = base + "/" + info;
        return path;
    }
1030969
def abspath(raw):
    """"""
    path_bits = []
    if raw.find('/') != -1:
        path_bits = raw.split('/')
    elif raw.find('\\') != -1:
        path_bits = raw.split('\\')
    else:
        path_bits = [raw]

    return os.path.abspath(os.sep.join(path_bits))
948899
def _to_relative_path(cls, parent_repo, path):
        """"""
        path = to_native_path_linux(path)
        if path.endswith('/'):
            path = path[:-1]
        # END handle trailing slash

        if osp.isabs(path):
            working_tree_linux = to_native_path_linux(parent_repo.working_tree_dir)
            if not path.startswith(working_tree_linux):
                raise ValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'"
                                 % (working_tree_linux, path))
            path = path[len(working_tree_linux.rstrip('/')) + 1:]
            if not path:
                raise ValueError("Absolute submodule path '%s' didn't yield a valid relative path" % path)
            # end verify converted relative path makes sense
        # end convert to a relative path

        return path
1089160
def path_yield(path):
    """"""
    for part in (x for x in path.strip(SEP).split(SEP) if x not in (None, '')):
        yield part
935112
def simplify_path(path):
    
    skip = {'..', '.', ''}
    stack = []
    paths = path.split('/')
    for tok in paths:
        if tok == '..':
            if stack:
                stack.pop()
        elif tok not in skip:
            stack.append(tok)
    return '/' + '/'.join(stack)
1371170
def parts(path):
    # type: (Text) -> List[Text]
    
    _path = normpath(path)
    components = _path.strip("/")

    _parts = ["/" if _path.startswith("/") else "./"]
    if components:
        _parts += components.split("/")
    return _parts