helper to turn a set of paths into nested objects
438885
function deep_set(root, path, value) {
    var twig = root;
    path.split('/').forEach(function (branch, index, branches) {
        if (branch) {
            if (self.camelize) {
                branch = branch.replace(/(\-([a-z]))/g, function (m) { return m[1].toUpperCase(); })
            }
            if (index < branches.length - 1) {
                twig = twig[branch] || (twig[branch] = {});
            } else {
                // optimistically try treating the value as JSON
                try {
                    twig[branch] = JSON.parse(value);
                } catch (e) {
                    twig[branch] = value;
                }
            }
        }
    });
}
1354294
def objectify(self, load, node, depth=2, path=None):
        
        if path is None:
            path = set()

        if self.is_object:
            if depth < 1:
                return
            return self._objectify_object(load, node, depth, path)
        elif self.is_array:
            if depth < 1:
                return
            return [self.items.objectify(load, node, depth, path)]
        else:
            return node
1207120
def objects_to_root(objects: List) -> Root:
    

    def _to_tree(objs: Iterable) -> Dict:
        """
        Build a tree structure from a flat list of objects.

        :param objs: The raw iterable of S3 `ObjectSummary`s, as returned by a
                     bucket listing.
        :return: The listing as a nested dictionary where keys are directory
                 and file names. The values of directories will in turn be a
                 dict. The values of keys representing files will be the
                 `ObjectSummary` instance.
        """
        path_tree = {}
        for obj in objs:
            is_dir = obj.key.endswith('/')
            chunks = [chunk for chunk in obj.key.split('/') if chunk]
            chunk_count = len(chunks)
            tmp = path_tree
            for i, chunk in enumerate(chunks):
                is_last_chunk = i == chunk_count - 1

                if is_last_chunk and not is_dir:
                    tmp[chunk] = obj
                else:
                    # must be a directory
                    if chunk not in tmp:
                        # it doesn't exist - create it
                        tmp[chunk] = {}
                    tmp = tmp[chunk]
        return path_tree

    def _to_entity(key: str, value: Union[Dict, Any]) -> Entity:
        """
        Turn a nested dictionary representing an S3 bucket into the correct
        `Entity` object.

        :param key: The name of the entity.
        :param value: If the entity is a directory, the nested dict
                      representing its contents. Otherwise, the `ObjectSummary`
                      instance representing the file.
        :return: The entity representing the entity name and value pair.
        """
        if isinstance(value, dict):
            return Directory(
                key,
                {key_: _to_entity(key_, value_)
                 for key_, value_ in value.items()})

        return File(pathlib.PurePath(value.key).name, value.size,
                    value.e_tag.strip('"'))

    tree = _to_tree(objects)
    return Root({pathlib.PurePath(key).name: _to_entity(key, value)
                 for key, value in tree.items()})
610709
function (path, data) {
        var i = 0,
            len = path.length;
        for (;i<len;i++) {
            if (isObject(data) && (path[i] in data)) {
                data = data[path[i]];
            } else {
                data = undefined;
                break;
            }
        }
        return data;
    }
1210781
def to_path_globs(self, relpath, conjunction):
    """"""
    return PathGlobs(
      include=tuple(os.path.join(relpath, glob) for glob in self._file_globs),
      exclude=tuple(os.path.join(relpath, exclude) for exclude in self._excluded_file_globs),
      conjunction=conjunction)
920615
def _unpack_paths(cls, objs, items, counts):
        
        if type(objs) is cls:
            objs = objs.items()
        for item in objs:
            path, obj = item if isinstance(item, tuple) else (None, item)
            if type(obj) is cls:
                cls._unpack_paths(obj, items, counts)
                continue
            new = path is None or len(path) == 1
            path = util.get_path(item) if new else path
            new_path = util.make_path_unique(path, counts, new)
            items.append((new_path, obj))
1030530
def join_paths(path1: Optional[str], path2: Optional[str]) -> Optional[str]:
    
    if path1 is not None and path2 is not None:
        return os.path.join(path1, path2)
712828
def _iter_path_collection(paths, path_transforms, offsets, styles):
        """"""
        N = max(len(paths), len(offsets))

        if not path_transforms:
            path_transforms = [np.eye(3)]

        edgecolor = styles['edgecolor']
        if np.size(edgecolor) == 0:
            edgecolor = ['none']
        facecolor = styles['facecolor']
        if np.size(facecolor) == 0:
            facecolor = ['none']

        elements = [paths, path_transforms, offsets,
                    edgecolor, styles['linewidth'], facecolor]

        it = itertools
        return it.islice(py3k.zip(*py3k.map(it.cycle, elements)), N)
1137092
def normalize_paths(value, parent=os.curdir):
    
    if not value:
        return []
    if isinstance(value, list):
        return value
    paths = []
    for path in value.split(','):
        path = path.strip()
        if '/' in path:
            path = os.path.abspath(os.path.join(parent, path))
        paths.append(path.rstrip('/'))
    return paths
1140293
def path2route(path: SchemaPath) -> SchemaRoute:
        
        if path == "/" or path == "":
            return []
        nlist = path.split("/")
        prevns = None
        res = []
        for n in (nlist[1:] if path[0] == "/" else nlist):
            p, s, loc = n.partition(":")
            if s:
                if p == prevns:
                    raise InvalidSchemaPath(path)
                res.append((loc, p))
                prevns = p
            elif prevns:
                res.append((p, prevns))
            else:
                raise InvalidSchemaPath(path)
        return res
234098
def paths=(raw_paths)
    raw_paths = [raw_paths] unless raw_paths.respond_to? :each

    @paths = raw_paths.map { |path| Pathname.new(path) }
  end
620838
def nested_dict_to_list(path, dic, exclusion=None):
    
    result = []
    exclusion = ['__self'] if exclusion is None else exclusion

    for key, value in dic.items():

        if not any([exclude in key for exclude in exclusion]):
            if isinstance(value, dict):
                aux = path + key + "/"
                result.extend(nested_dict_to_list(aux, value))
            else:
                if path.endswith("/"):
                    path = path[:-1]

                result.append([path, key, value])

    return result
1182448
function chainTransform (obj, path = []) {
  return flatmap(Object.keys(obj), function (key) {
    if (key === 'required') {
      // starts array with `true` or `false` and makes the
      // deepest-nested expression first in the array
      return [path.concat(obj[key]).reverse()];
    } else {
      return chainTransform(obj[key], path.concat(key));
    }
  });
}
619766
function pathsort(paths, sep, algorithm) {
  sep = sep || '/'

  return paths.map(function(el) {
    return el.split(sep)
  }).sort(algorithm || levelSorter).map(function(el) {
    return el.join(sep)
  })
}
771346
function setPathSet(
    value, path, depth, root, parent, node,
    requestedPaths, optimizedPaths, requestedPath, optimizedPath,
    version, expired, lru, comparator, errorSelector, replacedPaths) {

    var note = {};
    var branch = depth < path.length - 1;
    var keySet = path[depth];
    var key = iterateKeySet(keySet, note);
    var optimizedIndex = optimizedPath.index;

    do {

        requestedPath.depth = depth;

        var results = setNode(
            root, parent, node, key, value,
            branch, false, requestedPath, optimizedPath,
            version, expired, lru, comparator, errorSelector, replacedPaths
        );
        requestedPath[depth] = key;
        requestedPath.index = depth;
        optimizedPath[optimizedPath.index++] = key;
        var nextNode = results[0];
        var nextParent = results[1];
        if (nextNode) {
            if (branch) {
                setPathSet(
                    value, path, depth + 1,
                    root, nextParent, nextNode,
                    requestedPaths, optimizedPaths, requestedPath, optimizedPath,
                    version, expired, lru, comparator, errorSelector
                );
            } else {
                requestedPaths.push(requestedPath.slice(0, requestedPath.index + 1));
                optimizedPaths.push(optimizedPath.slice(0, optimizedPath.index));
            }
        }
        key = iterateKeySet(keySet, note);
        if (note.done) {
            break;
        }
        optimizedPath.index = optimizedIndex;
    } while (true);
}
52317
function includePaths(object, pathsRemaining) {
  debugPrint('INCLUDE', { object, pathsRemaining });
  const path = pathsRemaining.shift();
  const target = object && object[path];

  if (target) {
    if (Array.isArray(target)) {
      object[path] = target.map(pointer => {
        const fetched = fetchObjectByPointer(pointer);
        includePaths(fetched, _.cloneDeep(pathsRemaining));
        return fetched;
      });
    } else {
      if (object[path].__type === 'Pointer') {
        object[path] = fetchObjectByPointer(target);
      }
      includePaths(object[path], pathsRemaining);
    }
  }

  return object;
}
1178493
def _relative_paths(xs, base_path):
    
    if isinstance(xs, six.string_types):
        if xs.startswith(base_path):
            return xs.replace(base_path + "/", "", 1)
        else:
            return xs
    elif isinstance(xs, (list, tuple)):
        return [_relative_paths(x, base_path) for x in xs]
    elif isinstance(xs, dict):
        out = {}
        for k, v in xs.items():
            out[k] = _relative_paths(v, base_path)
        return out
    else:
        return xs