A recursive generator wrapper for get_acls

        :param path: path from which to start
        :param depth: depth of the recursion (-1 no recursion, 0 means no limit)
        :param include_ephemerals: get ACLs for ephemerals too
358064
def get_acls_recursive(self, path, depth, include_ephemerals):
        
        yield path, self.get_acls(path)[0]

        if depth == -1:
            return

        for tpath, _ in self.tree(path, depth, full_path=True):
            try:
                acls, stat = self.get_acls(tpath)
            except NoNodeError:
                continue

            if not include_ephemerals and stat.ephemeralOwner != 0:
                continue

            yield tpath, acls
353906
def get_files(path, ext=[], include=True):
    
    has_ext = len(ext)>0
    for p, d, fs in os.walk(path):
        for f in fs:
            if has_ext:
                in_ext = False
                for name in ext:
                    if f.endswith(name):
                        in_ext = True
                        break
                if (include and in_ext) or \
                (not include and not in_ext):
                    yield os.path.join(p,f)
            else:
                yield os.path.join(p, f)
1035246
def nodes(self, path):
        
        path = posix_path(path)

        yield from (self.path(path, e) for e in self._handler.find(path))
643763
def depth(self):
        
        return len(self.path.rstrip(os.sep).split(os.sep))
176467
def _walk_to_root(path):
    
    if not os.path.exists(path):
        raise IOError('Starting path not found')

    if os.path.isfile(path):
        path = os.path.dirname(path)

    last_dir = None
    current_dir = os.path.abspath(path)
    while last_dir != current_dir:
        yield current_dir
        parent_dir = os.path.abspath(os.path.join(current_dir, os.path.pardir))
        last_dir, current_dir = current_dir, parent_dir
112069
def recurse_tree(rootpath, excludes, opts):
    # type: (unicode, List[unicode], Any) -> List[unicode]
    
    if INITPY in os.listdir(rootpath):
        path_prefix = path.sep.join(rootpath.split(path.sep)[:-1])
    else:
        path_prefix = rootpath

    toplevels = []
    followlinks = getattr(opts, 'followlinks', False)
    includeprivate = getattr(opts, 'includeprivate', False)
    implicit_namespaces = getattr(opts, 'implicit_namespaces', False)
    for root, subs, files in walk(rootpath, followlinks=followlinks):
        # document only Python module files (that aren't excluded)
        py_files = sorted(f for f in files
                          if path.splitext(f)[1] in PY_SUFFIXES and
                          not is_excluded(path.join(root, f), excludes))
        is_pkg = INITPY in py_files
        if is_pkg:
            py_files.remove(INITPY)
            py_files.insert(0, INITPY)
        elif root != rootpath:
            # only accept non-package at toplevel unless using implicit
            # namespaces
            if not implicit_namespaces:
                del subs[:]
                continue
        # remove hidden ('.') and private ('_') directories, as well as
        # excluded dirs
        if includeprivate:
            exclude_prefixes = ('.',)  # type: Tuple[unicode, ...]
        else:
            exclude_prefixes = ('.', '_')
        subs[:] = sorted(sub for sub in subs
                         if not sub.startswith(exclude_prefixes) and
                         not is_excluded(path.join(root, sub), excludes))

        pkg = root[len(path_prefix):].lstrip(path.sep).replace(path.sep, '.')
        for py_file in py_files:
            if not shall_skip(path.join(root, py_file), opts):
                if py_file == INITPY:
                    module = ''
                else:
                    module = path.splitext(py_file)[0]
                toplevels.append(makename(pkg, module))

    return toplevels
1059057
def tree(self, path):
        '''
        
        '''
        ret = {}
        try:
            items = self.read(path)
        except (etcd.EtcdKeyNotFound, ValueError):
            return None
        except etcd.EtcdConnectionFailed:
            log.error("etcd: failed to perform 'tree' operation on path %s due to connection error", path)
            return None

        for item in items.children:
            comps = six.text_type(item.key).split('/')
            if item.dir is True:
                if item.key == path:
                    continue
                ret[comps[-1]] = self.tree(item.key)
            else:
                ret[comps[-1]] = item.value
        return ret
956508
def chdir(path: str) -> Iterator[None]:
    
    curdir = os.getcwd()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(curdir)
962377
public Map.Entry<List<ACL>, Stat> getAcl(final String path) throws ZkException {
        if (path == null) {
            throw new NullPointerException("Missing value for path");
        }

        if (!exists(path)) {
            throw new RuntimeException("trying to get acls on non existing node " + path);
        }

        return retryUntilConnected(new Callable<Map.Entry<List<ACL>, Stat>>() {
            @Override
            public Map.Entry<List<ACL>, Stat> call() throws Exception {
                return _connection.getAcl(path);
            }
        });
    }
473997
def from_folder(cls, path:PathOrStr, extensions:Collection[str]=None, recurse:bool=True,
                    include:Optional[Collection[str]]=None, processor:PreProcessors=None, **kwargs)->'ItemList':
        """"""
        path = Path(path)
        return cls(get_files(path, extensions, recurse=recurse, include=include), path=path, processor=processor, **kwargs)
1285255
def acls(self):
        """"""
        if self._acls is None:
            self._acls = InstanceAcls(instance=self)
        return self._acls
322741
def ListDescendentPathInfos(self,
                              client_id,
                              path_type,
                              components,
                              timestamp=None,
                              max_depth=None):
    """"""
    result = []

    for path_idx, path_record in iteritems(self.path_records):
      other_client_id, other_path_type, other_components = path_idx
      if client_id != other_client_id or path_type != other_path_type:
        continue
      if len(other_components) == len(components):
        continue
      if not collection.StartsWith(other_components, components):
        continue
      if (max_depth is not None and
          len(other_components) - len(components) > max_depth):
        continue

      result.append(path_record.GetPathInfo(timestamp=timestamp))

    if timestamp is None:
      return sorted(result, key=lambda _: tuple(_.components))

    # We need to filter implicit path infos if specific timestamp is given.

    # TODO(hanuszczak): If we were to switch to use path trie instead of storing
    # records by path id, everything would be much easier.

    class TrieNode(object):
      """A trie of path components with path infos as values."""

      def __init__(self):
        self.path_info = None
        self.children = {}
        self.explicit = False

      def Add(self, path_info, idx=0):
        """Adds given path info to the trie (or one of its subtrees)."""
        components = path_info.components
        if idx == len(components):
          self.path_info = path_info
          self.explicit |= (
              path_info.HasField("stat_entry") or
              path_info.HasField("hash_entry"))
        else:
          child = self.children.setdefault(components[idx], TrieNode())
          child.Add(path_info, idx=idx + 1)
          self.explicit |= child.explicit

      def Collect(self, path_infos):
        if self.path_info is not None and self.explicit:
          path_infos.append(self.path_info)

        for component in sorted(iterkeys(self.children)):
          self.children[component].Collect(path_infos)

    trie = TrieNode()
    for path_info in result:
      trie.Add(path_info)

    explicit_path_infos = []
    trie.Collect(explicit_path_infos)
    return explicit_path_infos
824697
def get_file_list(path, max_depth=1, cur_depth=0):
    
    if os.path.exists(path):
        for name in os.listdir(path):
            if name.startswith('.'):
                continue
            
            full_path = os.path.join(path, name)
            if os.path.isdir(full_path):
                if cur_depth == max_depth:
                    continue
                
                file_list = get_file_list(full_path, max_depth, cur_depth + 1)
                for result in file_list:
                    yield result
            else:
                yield full_path
92414
def iter_object_acl(root):
    

    for obj in iter_object_graph(root):
        for ace in parse_acl(getattr(obj, '__acl__', ())):
            yield ace
46647
def tree(path, depth=2, topdown=True, followlinks=False, showhidden=False):
    """"""
    rt = []
    for root, dirs, files in os.walk(path, topdown=topdown, followlinks=followlinks):
        if not showhidden and File.is_hidden(root):
            continue

        current_depth = len(os.path.relpath(root, path).split(os.sep))
        if current_depth > depth:
            continue

        if showhidden:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs],
                [File(os.path.join(root, _file)) for _file in files]
            )
        else:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs if _dir[0] != '.'],
                [File(os.path.join(root, _file)) for _file in files if _file[0] != '.']
            )

        rt.append(_tuple)
    return rt
1166673
def recursive_path(pack, path):
    """"""
    matches = []
    for root, _, filenames in os.walk(os.path.join(pack, path)):
        for filename in filenames:
            matches.append(os.path.join(root, filename)[len(pack) + 1:])
    return matches
234310
def dfs_paths(path)
      paths = []
      stack = [path]
      seen  = Set.new

      while path = stack.pop
        seen.add(path.last)
        paths << path

        children = yield path.last
        children.reverse_each do |node|
          stack.push(path + [node]) unless seen.include?(node)
        end
      end

      paths
    end