Traverse the object we receive with the given path. Path
    items can be either strings or lists of strings (or any
    nested combination thereof). Behavior in given cases is
    laid out line by line below.
518366
def traverse(obj, *path, **kwargs):
    
    if path:
        if isinstance(obj, list) or isinstance(obj, tuple):
            #If the current state of the object received is a
            #list, return a list of each of its children elements,
            #traversed with the current state of the string
            return [traverse(x, *path) for x in obj]
        elif isinstance(obj, dict):
            #If the current state of the object received is a
            #dictionary, do the following...
            if isinstance(path[0], list) or isinstance(path[0], tuple):
                #If the current top item in the path is a list,
                #return a dictionary with keys to each of the
                #items in the list, each traversed recursively.
                for branch in path[0]:
                    if not isinstance(branch, basestring):
                        raise TraversalError(obj, path[0])
                return {name: traverse(obj[name], *path[1:], split=True) for name in path[0]}
            elif not isinstance(path[0], basestring):
                #If the key isn't a string (or a list; handled
                #previously), raise an exception.
                raise TraversalError(obj, path[0])
            elif path[0] == '\\*':
                #If the key is a wildcard, return a dict containing
                #each item, traversed down recursively.
                return {name: traverse(item, *path[1:], split=True) for name, item in obj.items()}
            elif path[0] in obj:
                #The individual key is in the current object;
                #traverse it and return the result.
                return traverse(obj[path[0]], *path[1:])
            else:
                #The individual key doesn't exist in the
                #current object; raise an error
                raise TraversalError(obj, path[0])
        else:
            #If the current object isn't either a list or
            #a dict, then do one of two things:
            if kwargs.get('split', False):
                #If the previously-recursed operation caused
                #a split in a dict, just return the object; it's
                #been specifically called out, but it isn't
                #possible to recurse further.
                return obj
            else:
                #The object can't be traversed, and we didn't
                #specifically call it out to do something
                #else with. Raise an exception.
                raise TraversalError(obj, path[0])
    else:
        #If there's no path left, then just return the
        #object that we received.
        return obj
868058
function(path) {
      var t = this;

      // Get the parts
      var parts = Array.isArray(path) ? path : path.split('/').filter(function(item){return item;});

      // Return the item at this level
      if (parts.length === 1) {
        return t.get('leaves').get(parts[0]);
      }

      // Return the item from the tree below
      var sub = t.get('branches').get(parts[0]);
      if (sub) {
        return sub.getByPath(parts.slice(1));
      }

      // Branch not found
      return null;
    }
1285970
function traverseBroad(object, visitor) {
        var key, child;

        if (!object) {
            return;
        }

        if (visitor.call(null, object) === false) {
            return false;
        }
        for (key in object) {
            if (object.hasOwnProperty(key)) {
                child = object[key];
                if (typeof child === 'object' && child !== null) {
                    traverseBroad(child, visitor);
                }
            }
        }
    }
269430
function reachin( path, record ) {
	var context = record;
	var part;
	var _i;
	var _len;

	for ( _i = 0, _len = path.length; _i < _len; _i++ ) {
		part = path[_i];
		context = context[part];
		if ( sys.isNull( context ) || sys.isUndefined( context ) ) {
			break;
		}
	}

	return context;
}
374184
function getPath(pathType = 'array', _path) {
  return {
    _path: _path || (pathType === 'array' ? [] : ''),
    set(parent, key) {
      let nextPath;
      switch (pathType) {
        case 'array':
          nextPath = this._path.concat([key]);
          break;

        case 'nestedProperty':
          if (this._path.length === 0) {
            nextPath = key;
          } else if (Array.isArray(parent)) {
            nextPath = this._path + `[${key}]`;
          } else {
            nextPath = this._path + '.' + key;
          }
          break;

        default:
          throw new Error('unrecognized pathType ' + pathType);
      }

      return getPath(pathType, nextPath);
    },

    get(parent, key) {
      // in array mode we do not return the leaf node key.
      if (pathType === 'array') {
        return this._path;
      }

      // in nestedProperty mode we return full path including final key
      return this.set(parent, key)._path;
    },
  };
}
987408
function(obj, path, value) {
  const parts = path.split('.')

  /* traverse existing path to nearest object */
  while (parts.length > 1 && typeof obj[parts[0]] === 'object') {
    obj = obj[parts.shift()]
  }

  /* set value */
  obj[parts[0]] = partsToValue(parts.slice(1), value)
}
1346045
def path(self, path):
        """"""

        # pylint: disable=attribute-defined-outside-init
        if path is None:
            self._path = None
        else:
            # The provided path is deep copied because its keybindings may be
            # updated when setting properties (in __setitem__()).
            self._path = path.copy()

            # We perform this check after the initialization to avoid errors
            # in test tools that show the object with repr().
            assert isinstance(path, CIMInstanceName)
35594
def is_path(path):
    
    if not isinstance(path, basestring):
        return False
    portal_path = get_path(get_portal())
    if not path.startswith(portal_path):
        return False
    obj = get_object_by_path(path)
    if obj is None:
        return False
    return True
1210941
function setPath (obj, itemPath, value) {
  if (!isObj(obj) || typeof (itemPath) !== 'string') {
    return
  }

  const pathArr = itemPath.split('.')

  function noop (obj, i) {
    const item = pathArr[i]

    /**
     * Finally set the value when array is done
     */
    if (i + 1 === pathArr.length) {
      obj[item] = value
      return
    }

    if (!isNaN(parseInt(pathArr[i + 1])) && !Array.isArray(obj[item])) {
      obj[item] = []
    } else if (!isObj(obj[item])) {
      obj[item] = {}
    }

    /**
     * Carry on recursively.
     */
    return noop(obj[item], i + 1)
  }

  /**
   * Start recursion
   */
  return noop(obj, 0)
}
1352821
def get_object_by_path(path, default=_marker):
    

    # nothing to do here
    if not path:
        if default is not _marker:
            return default
        fail("get_object_by_path first argument must be a path; {} received"
             .format(path))

    portal = get_portal()
    portal_path = get_path(portal)
    portal_url = get_url(portal)

    # ensure we have a physical path
    if path.startswith(portal_url):
        request = get_request()
        path = "/".join(request.physicalPathFromURL(path))

    if not path.startswith(portal_path):
        if default is not _marker:
            return default
        fail("Not a physical path inside the portal.")

    if path == portal_path:
        return portal

    return portal.restrictedTraverse(path, default)
597686
def set_path(self, path):
        ''''''
        self._path = path
        return self._listitem.setPath(path)
12617
def _traverse_tree(tree, path):
        """"""
        path_steps = (step for step in path.split('.') if step != '')
        # Special handling for first step, because the first step isn't under 'objects'
        first_step = path_steps.next()
        subtree = tree[first_step]

        for step in path_steps:
            subtree = subtree['children'][step]
        return subtree
222923
function searchPath(object, path) {
    var currentChild = object;
    var comps = path.toLowerCase().split('/');
    for (var i = 0; i < comps.length; i++) {
        // Search for a child object with a case-insensitive matching key
        var matchingChild = null;
        for (var key in currentChild) {
            if (key.toLowerCase() === comps[i]) {
                matchingChild = currentChild[key];
                break;
            }
        }
        // Didn't find one. :'(
        if (matchingChild === null) {
            return null;
        }
        // Now check this child...
        currentChild = matchingChild;
    }
    return currentChild;
}
1096168
def walk(value, walker, path=None, seen=None):
  
  seen = seen or set()
  path = path or []

  # Recursion
  if id(value) in seen:
    walker.visitRecursion(path)
    return

  # Error
  if isinstance(value, Exception):
    walker.visitError(path, value)
    return

  # List
  if isinstance(value, list):
    # Not actually a tuple, but okay
    recurse = walker.enterList(value, path)
    if not recurse: return
    next_walker = walker if recurse is True else recurse

    with TempSetAdd(seen, id(value)):
      for i, x in enumerate(value):
        walk(x, next_walker, path=path + ['[%d]' % i], seen=seen)

      walker.leaveList(value, path)
    return

  # Scalar
  if not isinstance(value, framework.TupleLike):
    walker.visitScalar(path, value)
    return

  # Tuple
  recurse = walker.enterTuple(value, path)
  if not recurse: return
  next_walker = walker if recurse is True else recurse

  with TempSetAdd(seen, id(value)):
    keys = sorted(value.keys())
    for key in keys:
      key_path = path + [key]
      elm = get_or_error(value, key)
      walk(elm, next_walker, path=key_path, seen=seen)

    walker.leaveTuple(value, path)
398983
def relpath(path, start):
    
    path_items = path_list(path)
    start_items = path_list(start)

    # Find common parts of path.
    common = []
    for pth, stt in zip(path_items, start_items):
        if pth != stt:
            break
        common.append(pth)

    # Shared parts index in both lists.
    common_ind = len(common)
    parent_num = len(start_items) - common_ind

    # Start with parent traversal and add relative parts.
    rel_items = [PARENT] * parent_num + path_items[common_ind:]
    return path_join(*rel_items)
1084565
def traverse(self, callback):
        ''' 
        '''
        def _traverse_node(path, node, callback):
            ret_val = callback(path, node)
            if ret_val is not None:
                # replace node with the return value
                node = ret_val
            else:
                # traverse deep into the hierarchy
                if isinstance(node, YAMLDict):
                    for k, v in node.items():
                        node[k] = _traverse_node(path + [k], v,
                                                 callback)
                elif isinstance(node, list):
                    for i, v in enumerate(node):
                        node[i] = _traverse_node(path + ['[{0}]'.format(i)], v,
                                                 callback)
                else:
                    pass
            return node
        _traverse_node([], self, callback)
644627
def parse_path(path):
  """"""
  if not path:
    raise ValueError("Invalid path")

  if isinstance(path, str):
    if path == "/":
      raise ValueError("Invalid path")
    if path[0] != "/":
      raise ValueError("Invalid path")
    return path.split(_PATH_SEP)[1:]
  elif isinstance(path, (tuple, list)):
    return path
  else:
    raise ValueError("A path must be a string, tuple or list")