Iterate values at specified depth.
548070
def values_at(self, depth):
        
        if depth < 1:
            yield self
        else:
            for dict_tree in self.values():
                for value in dict_tree.values_at(depth - 1):
                    yield value
64695
def values(self, **kwargs):
        """"""
        result = yield self.get(**kwargs)

        if not result['rows']:
            raise Return([])

        raise Return([x['value'] for x in result['rows']])
1351797
def iterate_date_values(d, start_date=None, stop_date=None, default=0):
    
    dataiter = iter(d)
    cur_day, cur_val = next(dataiter)

    start_date = start_date or cur_day

    while cur_day < start_date:
        cur_day, cur_val = next(dataiter)

    for d in iterate_date(start_date, stop_date):
        if d != cur_day:
            yield default
            continue

        yield cur_val
        try:
            cur_day, cur_val = next(dataiter)
        except StopIteration:
            if not stop_date:
                raise
445983
def iterative_select(obj, dimensions, selects, depth=None):
    
    ndims = len(dimensions)
    depth = depth if depth is not None else ndims
    items = []
    if isinstance(selects, dict):
        for k, v in selects.items():
            items += iterative_select(obj.select(**{dimensions[ndims-depth]: k}),
                                      dimensions, v, depth-1)
    else:
        for s in selects:
            items.append((s, obj.select(**{dimensions[-1]: s[-1]})))
    return items
447785
def update(self, *iterables):
        """"""
        _set = self._set
        values = set(chain(*iterables))
        if (4 * len(values)) > len(_set):
            _list = self._list
            _set.update(values)
            _list.clear()
            _list.update(_set)
        else:
            _add = self.add
            for value in values:
                _add(value)
        return self
101580
def depth_first_sub(expr,values):
  ""
  arr=treepath.sub_slots(expr,lambda elt:elt is sqparse2.SubLit)
  if len(arr)!=len(values): raise ValueError('len',len(arr),len(values))
  for path,val in zip(arr,values):
    # todo: does ArrayLit get us anything? tree traversal?
    if isinstance(val,(basestring,int,float,type(None),dict)): expr[path] = sqparse2.Literal(val)
    elif isinstance(val,(list,tuple)): expr[path] = sqparse2.ArrayLit(val)
    else: raise TypeError('unk_sub_type',type(val),val) # pragma: no cover
  return expr
306189
def iflatten(L):
    """"""
    for sublist in L:
        if hasattr(sublist, '__iter__'):
            for item in iflatten(sublist): yield item
        else: yield sublist
128431
def depth(self):
        """"""
        if self.indentation is None:
            yield
        else:
            previous = self.previous_indent
            self.previous_indent = self.indent
            self.indent += self.indentation
            yield
            self.indent = self.previous_indent
            self.previous_indent = previous
1260645
def iterate_flattened(d):
    
    for key in sorted(d.keys()):
        value = d[key]
        if isinstance(value, dict) and value:
            for k, v in iterate_flattened(d[key]):
                yield join_paths(key, k), v
        else:
            yield key, value
548369
def chunk(iterable, chunk_size=20):
    """"""
    items = []
    for value in iterable:
        items.append(value)
        if len(items) == chunk_size:
            yield items
            items = []
    if items:
        yield items
222663
def iteritems(self):
        """"""
        for key in self:
            vals = self._container[key.lower()]
            for val in vals[1:]:
                yield vals[0], val
606637
def apply_projection(projection, value):
    """"""
    if isinstance(value, Sequence):
        # Apply projection to each item in the list.
        return [
            apply_projection(projection, item)
            for item in value
        ]
    elif not isinstance(value, Mapping):
        # Non-dictionary values are simply ignored.
        return value

    # Extract projection for current level.
    try:
        current_projection = [p[0] for p in projection]
    except IndexError:
        return value

    # 
    for name in list(value.keys()):
        if name not in current_projection:
            value.pop(name)
        elif isinstance(value[name], dict):
            # Apply projection recursively.
            value[name] = apply_projection(
                [p[1:] for p in projection if p[0] == name],
                value[name]
            )

    return value
1048187
def v_depth(d, depth):
        
        if depth == 0:
            yield d
        else:
            for node in DictTree.v(d):
                for node1 in DictTree.v_depth(node, depth-1):
                    yield node1
653929
def discretize(value, factor=100):
    """"""
    if not isinstance(value, Iterable):
        return int(value * factor)
    int_value = list(deepcopy(value))
    for i in range(len(int_value)):
        int_value[i] = int(int_value[i] * factor)
    return int_value
269344
def recurse(self, fn, *args):
        """"""
        fn(self, *args)
        for i in self.items:
            if isinstance(i, Hypercat):
                self.recurse(i, *args)
1241486
def update(self, iterable):
        """"""
        _lists = self._lists
        _maxes = self._maxes
        values = sorted(iterable)

        if _maxes:
            if len(values) * 4 >= self._len:
                values.extend(chain.from_iterable(_lists))
                values.sort()
                self._clear()
            else:
                _add = self.add
                for val in values:
                    _add(val)
                return

        _load = self._load
        _lists.extend(values[pos:(pos + _load)]
                      for pos in range(0, len(values), _load))
        _maxes.extend(sublist[-1] for sublist in _lists)
        self._len = len(values)
        del self._index[:]
480525
def range(start, finish, step):
        """"""
        value = start
        while value <= finish:
            yield value
            value += step