Iterates over (valid) attributes of a class.

    Args:
        cls (object): the class to iterate over

    Yields:
        (str, obj) tuples: the class-level attributes.
934
def iterclass(cls):
    
    for field in dir(cls):
        if hasattr(cls, field):
            value = getattr(cls, field)
            yield field, value
952156
def _set_attributes(self, kwds):
    
    cls = self.__class__
    for name, value in kwds.iteritems():
      prop = getattr(cls, name)  # Raises AttributeError for unknown properties.
      if not isinstance(prop, Property):
        raise TypeError('Cannot set non-property %s' % name)
      prop._set_value(self, value)
923235
def _new_cls_attr(self, clazz, name, cls=None, mult=MULT_ONE, cont=True,
                      ref=False, bool_assignment=False, position=0):
        """"""
        attr = MetaAttr(name, cls, mult, cont, ref, bool_assignment,
                        position)
        clazz._tx_attrs[name] = attr
        return attr
1285602
def GetAttributes(self):
    
    for attribute_name, attribute_value in iter(self.__dict__.items()):
      # Not using startswith to improve performance.
      if attribute_name[0] == '_' or attribute_value is None:
        continue

      yield attribute_name, attribute_value
1220356
def render_attrs(attrs):
    
    if attrs is not None:
        def parts():
            for key, value in sorted(attrs.items()):
                if value is None:
                    continue
                if value is True:
                    yield '%s' % (key, )
                    continue
                if key == 'class' and isinstance(value, dict):
                    if not value:
                        continue
                    value = render_class(value)
                if key == 'style' and isinstance(value, dict):
                    if not value:
                        continue
                    value = render_style(value)
                yield '%s="%s"' % (key, ('%s' % value).replace('"', '&quot;'))
        return mark_safe(' %s' % ' '.join(parts()))
    return ''
1087138
def create_attributes(klass, attributes, previous_object=None):
        

        result = {}

        if previous_object is not None:
            result = {k: v for k, v in previous_object.to_json().items() if k != 'sys'}

        result.update(attributes)

        return result
572266
def each_attribute # :yields: attribute
      each_value do |val|
        if val.kind_of? Attribute
          yield val
        else
          val.each_value { |atr| yield atr }
        end
      end
    end
22152
def iterate_with_name(cls):
        
        for attr_name, field in cls.iterate_over_fields():
            structure_name = field.structue_name(attr_name)
            yield attr_name, structure_name, field
954712
def call(cls, iterable, *a, **kw):
    

    return cls(x(*a, **kw) for x in iterable)
976404
def create(cls, class_name, **attributes):
        
        object_class = cls.extend(class_name)
        return object_class(**attributes)
1366419
def structure_attrs_fromtuple(self, obj, cl):
        # type: (Tuple, Type[T]) -> T
        """"""
        conv_obj = []  # A list of converter parameters.
        for a, value in zip(cl.__attrs_attrs__, obj):  # type: ignore
            # We detect the type by the metadata.
            converted = self._structure_attr_from_tuple(a, a.name, value)
            conv_obj.append(converted)

        return cl(*conv_obj)
752034
def cls_sets(cls, wanted_cls, registered=True):
    
    sets = []
    for attr in dir(cls):
        if attr.startswith('_'):
            continue
        val = getattr(cls, attr, None)
        if not isinstance(val, wanted_cls):
            continue
        if (not registered) and getattr(val, '_registered', False):
            continue
        sets.append(val)
    return sets
469228
def dir_instance(inst):
    
    # Skip instance attributes; __slots__ is automatically defined, and
    # descriptors are used to define attributes. Instead, go straight to class
    # attributes (including methods).
    for name, value in vars_class(type(inst)).items():
        if isinstance(value, ObjectMethod):
            if value.has_instancemethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        elif isinstance(value, (classmethod, staticmethod)):
            pass  # Hide this; not interesting here.
        else:
            yield name
567132
def rules(cls, attr=None):
        
        try:
            if attr is None:
                attr = cls._rules_attr()
            return getattr(cls, attr).keys()
        except TypeError:
            return ()
612284
def unmarshall(self, cls):
        
        for k, v in self.all_settings().items():
            setattr(cls, k, v)

        return cls
1047386
def typed_fields_with_attrnames(cls):
        
        # Checking cls._typed_fields could return a superclass _typed_fields
        # value. So we check our class __dict__ which does not include
        # inherited attributes.
        klassdict = cls.__dict__

        try:
            return klassdict["_typed_fields_with_attrnames"]
        except KeyError:
            # No typed_fields set on this Entity yet. Find them and store
            # them in the _typed_fields class attribute.
            from . import fields
            typed_fields = tuple(fields.iterfields(cls))
            cls._typed_fields_with_attrnames = typed_fields
        return typed_fields
954601
def coll_to_tuples(cls, coll):
        
        if isinstance(coll, basestring):
            raise exc.CollectionCoerceError(
                passed=coll,
                colltype=cls,
            )
        if isinstance(coll, collections.Mapping):
            i = 0
            for k in sorted(coll.keys()):
                yield (i, coll[k])
        elif isinstance(coll, (collections.Sequence, types.GeneratorType)) or (
            hasattr(coll, "next") and callable(coll.next)
        ) or (
            hasattr(coll, "__iter__") and callable(coll.__iter__)
        ):
            i = 0
            for v in coll:
                yield i, v
                i += 1
        elif not coll:
            return
        else:
            raise exc.CollectionCoerceError(
                passed=coll,
                colltype=cls,
            )