Return a dict of vars for the given class, including all ancestors.

    This differs from the usual behaviour of `vars` which returns attributes
    belonging to the given class and not its ancestors.
558858
def vars_class(cls):
    
    return dict(chain.from_iterable(
        vars(cls).items() for cls in reversed(cls.__mro__)))
982301
def _var(self):
        
        class Variables(object):
            def __getitem__(_self, name):
                return self.getVariable(name)

            def __setitem__(_self, name, value):
                self.getVariable(name).setValue(value)

            def __iter__(_self):
                return self.getVariables()

        return Variables()
494714
def check_static_member_vars(class_, fpath=None, only_init=True):
    
    #import ast
    #import astor
    import utool as ut

    if isinstance(class_, six.string_types):
        classname = class_
        if fpath is None:
            raise Exception('must specify fpath')
    else:
        # We were given a live object
        if not isinstance(class_, type):
            # We were given the class instance not the class
            class_instance = class_
            class_ = class_instance.__class__
        classname = class_.__name__
        if fpath is None:
            module = ut.get_module_from_class(class_)
            fpath = ut.get_modpath(module)

    sourcecode = ut.readfrom(fpath)

    import redbaron
    # Pares a FULL syntax tree that keeps blockcomments
    baron = redbaron.RedBaron(sourcecode)

    for node in baron:
        if node.type == 'class' and node.name == classname:
            classnode = node
            break

    def find_parent_method(node):
        par = node.parent_find('def')
        if par is not None and par.parent is not None:
            if par.parent.type == 'class':
                return par
            else:
                return find_parent_method(par)

    # TODO: Find inherited attrs
    #classnode.inherit_from
    # inhertied_attrs = ['parent']
    # inhertied_attrs = []

    class_methods = []
    for node in classnode:
        if node.type == 'def':
            if only_init:
                if node.name == '__init__':
                    class_methods.append(node)
            else:
                class_methods.append(node)

    class_vars = []
    self_vars = []
    for method_node in class_methods:
        self_var = method_node.arguments[0].dumps()
        self_vars.append(self_var)
        for assign in method_node.find_all('assignment'):
            # method_node = find_parent_method(assign)
            if assign.target.dumps().startswith(self_var + '.'):
                class_vars.append(assign.target.value[1].dumps())
    static_attrs = ut.unique(class_vars)
    return static_attrs

    # class_members = ut.unique(class_vars + class_methods + inhertied_attrs)
    if False:
        self_var = self_vars[0]

        # Find everything that is used
        complex_cases = []
        simple_cases = []
        all_self_ref = classnode.find_all(
            'name_', value=re.compile('.*' + self_var + '\\.*'))
        for x in all_self_ref:
            if x.parent.type == 'def_argument':
                continue
            if x.parent.type == 'atomtrailers':
                atom = x.parent
                if ut.depth(atom.fst()) <= 3:
                    simple_cases.append(atom)
                else:
                    complex_cases.append(atom)
                #print(ut.depth(atom.value.data))
                #print(atom.value)
                #print(atom.dumps())
                #if len(atom.dumps()) > 200:
                #    break

        accessed_attrs = []
        for x in simple_cases:
            if x.value[0].dumps() == self_var:
                attr = x.value[1].dumps()
                accessed_attrs.append(attr)
        accessed_attrs = ut.unique(accessed_attrs)

        ut.setdiff(accessed_attrs, class_vars)
216712
def get_ancestors(self, include_self=False, depth=None):
        """"""
        if self.is_root_node():
            if not include_self:
                return self._toplevel().objects.none()
            else:
                # Filter on pk for efficiency.
                return self._toplevel().objects.filter(pk=self.pk)

        params = {"%s__child" % self._closure_parentref():self.pk}
        if depth is not None:
            params["%s__depth__lte" % self._closure_parentref()] = depth
        ancestors = self._toplevel().objects.filter(**params)
        if not include_self:
            ancestors = ancestors.exclude(pk=self.pk)
        return ancestors.order_by("%s__depth" % self._closure_parentref())
521649
def _get_virtual_variable(variables, key, level_vars=None, dim_sizes=None):
    
    if level_vars is None:
        level_vars = {}
    if dim_sizes is None:
        dim_sizes = {}

    if key in dim_sizes:
        data = pd.Index(range(dim_sizes[key]), name=key)
        variable = IndexVariable((key,), data)
        return key, key, variable

    if not isinstance(key, str):
        raise KeyError(key)

    split_key = key.split('.', 1)
    if len(split_key) == 2:
        ref_name, var_name = split_key
    elif len(split_key) == 1:
        ref_name, var_name = key, None
    else:
        raise KeyError(key)

    if ref_name in level_vars:
        dim_var = variables[level_vars[ref_name]]
        ref_var = dim_var.to_index_variable().get_level_variable(ref_name)
    else:
        ref_var = variables[ref_name]

    if var_name is None:
        virtual_var = ref_var
        var_name = key
    else:
        if _contains_datetime_like_objects(ref_var):
            ref_var = xr.DataArray(ref_var)
            data = getattr(ref_var.dt, var_name).data
        else:
            data = getattr(ref_var, var_name).data
        virtual_var = Variable(ref_var.dims, data)

    return ref_name, var_name, virtual_var
337547
def ancestors(self, typename):
        """"""
        xs = []
        for parent in self._hier[typename][0]:
            xs.append(parent)
            xs.extend(self.ancestors(parent))
        return xs
1007082
def value(parent, vars = {})
			# this has all the attributes as an array. they will be [attribute, attributes]
			# attributes will then be [attribute and attributes] and so on

			current_obj = elements[0].value(parent, vars)
			# no right association, so we are the last attribute
			return current_obj if elements[1].nil?

			# has right association, which means we need to get the value of the current attribute and pass into the
			# next one
			return elements[1].value(current_obj, vars)
		end
1262610
def get_keys_from_class(cc):
    
    return [prop.name for prop in cc.properties.values() \
            if 'key' in prop.qualifiers]
1040570
def all_subclasses(cls):
    
    subclasses = cls.__subclasses__()
    descendants = (descendant for subclass in subclasses
                   for descendant in all_subclasses(subclass))
    return set(subclasses) | set(descendants)
1026949
def set_class_dict(self):
        

        self.class_dict = {}
        for name, cls_defs in self.defs.items():
            def_type = set(cls_defs.get(self.rdf_type, []))
            if name.type == 'bnode':
                continue
            # a class can be determined by checking to see if it is of an
            # rdf_type listed in the classes_key or has a property that is
            # listed in the inferred_key
            if def_type.intersection(self.classes_key) or \
                    list([cls_defs.get(item) for item in self.inferred_key]):
                self.class_dict[name] = cls_defs
843727
def get_var(self, name):
        
        if name not in self._vars:
            raise VarNotDefinedError

        return self._vars[name]
800316
def reset_defaults
      names_set = {}
      self.class.ancestors.each do |klass| # look at all ancestors
        defaults =
          klass.instance_variable_defined?("@defaults") &&
          klass.instance_variable_get("@defaults")
        next unless defaults
        defaults.each do |key, value|
          next if names_set[key]
          names_set[key] = true
          self[key] = Proc === value ? value.call : value
        end
      end
    end
1286336
def get_ancestors(self):
        
        ancestors = []
        if self._meta.proxy_for_model:
            # the current node is a proxy model; our result set
            # should use the same proxy model, so we need to
            # explicitly fetch instances of that model
            # when following the 'parent' relation
            cls = self.__class__
            node = self
            while node.parent_id:
                node = cls.objects.get(pk=node.parent_id)
                ancestors.insert(0, node)
        else:
            node = self.parent
            while node:
                ancestors.insert(0, node)
                node = node.parent
        return ancestors
1248111
def get_variables(self, entity = None):
        
        if not entity:
            return self.variables
        else:
            return {
                variable_name: variable
                for variable_name, variable in self.variables.items()
                # TODO - because entities are copied (see constructor) they can't be compared
                if variable.entity.key == entity.key
                }
352306
def dir_class(cls):
    
    # Class attributes (including methods).
    for name, value in vars_class(cls).items():
        if isinstance(value, ObjectMethod):
            if value.has_classmethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
    # Metaclass attributes.
    for name, value in vars_class(type(cls)).items():
        if name == "mro":
            pass  # Hide this; not interesting.
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
1268353
def get_ancestors(self):
        
        if self.is_root():
            return get_result_class(self.__class__).objects.none()

        paths = [
            self.path[0:pos]
            for pos in range(0, len(self.path), self.steplen)[1:]
        ]
        return get_result_class(self.__class__).objects.filter(
            path__in=paths).order_by('depth')
813283
def vals(cls):
        
        if cls._vals:
            return cls._vals

        # If `_vals` is not yet defined, create it
        # ----------------------------------------
        _vals = []
        # get the keys from all base-classes aswell (when this is subclasses)
        for mro in cls.__bases__:
            # base classes below `KeyCollection` (e.g. `object`) wont work
            if issubclass(mro, KeyCollection):
                _vals.extend(mro.vals())

        # Get the keys from this particular subclass
        # Only non-hidden (no '_') and variables (non-callable)
        _vals.extend([
            vv for kk, vv in vars(cls).items()
            if not kk.startswith('_') and not callable(getattr(cls, kk))
        ])
        # Store for future retrieval
        cls._vals = _vals
        return cls._vals