Will unwrap a `wrapt` attribute
    :param obj: base object
    :param attr: attribute on `obj` to unwrap
336334
def unwrap(obj, attr):
    
    f = getattr(obj, attr, None)
    if f and isinstance(f, wrapt.ObjectProxy) and hasattr(f, '__wrapped__'):
        setattr(obj, attr, f.__wrapped__)
325922
def wrap(x):
    
    # Detect the type so we can call the proper serialization routine
    if isinstance(x, G1Element):
        return _wrap(x, serializeG1)

    elif isinstance(x, G2Element):
        return _wrap(x, serializeG2)

    elif isinstance(x, GtElement):
        return _wrap(x, serializeGt)

    elif isinstance(x, str):        
        return x

    elif isinstance(x, (int, long, BigInt)):
        return hex(long(x))

    # All other items
    else:
        raise NotImplementedError("Cannot unwrap {}; only types {} supported".
            format(type(x), 
                [G1Element, G2Element, GtElement, int, long, BigInt]) )
1159288
def unwrap(klass, value):
        
        assert isinstance(value, Value), value
        V = value.value
        try:
            T = klass.typeMap[type(V)]
        except KeyError:
            raise ValueError("Can't unwrap value of type %s" % type(V))
        try:
            return T(value.value)._store(value)
        except Exception as e:
            raise ValueError("Can't construct %s around %s (%s): %s" % (T, value, type(value), e))
889370
def resolve_attr(obj, name):
    """"""
    # TODO: setup some hinting, so we can go directly to the correct
    # Maybe it's a dict ? Let's try dict lookup, it's the fastest
    try:
        return obj[name]
    except TypeError:
        pass
    except KeyError:
        raise exceptions.MissingField('Dict {0} has no attribute or key "{1}"'.format(obj, name))

    # Okay, it's not a dict, what if we try to access the value as for a regular object attribute?
    try:
        # Slight hack for better speed, since accessing dict is fast
        return obj.__dict__[name]
    except (KeyError, AttributeError):
        pass

    try:
        # Lookup using regular attribute
        return getattr(obj, name)
    except AttributeError:
        pass

    # Last possible choice, it's an iterable
    if isinstance(obj, collections.Iterable):
        return IterableAttr(obj, name)

    raise exceptions.MissingField('Object {0} has no attribute or key "{1}"'.format(obj, name))
881619
def _maybe_wrap(attribute):
    """"""
    if iscoroutinefunction(attribute):
        return asynchronous(attribute)
    if isinstance(attribute, (classmethod, staticmethod)):
        if iscoroutinefunction(attribute.__func__):
            return attribute.__class__(asynchronous(attribute.__func__))
    return attribute
868972
def unwrap_single(self):
        
        try:
            return next(self.itervalues())
        except AttributeError:
            return next(iter(self.values()))
167425
def _original_attr(self, attr_name):
        
        try:
            return getattr(
                getattr(self.obj.__class__, attr_name), '_doubles_target_method', None
            )
        except AttributeError:
            return None
528151
def get_attr_chain(obj, attr_chain, sep='.'):
    
    if sep is None:
        sep = '.'

    attr_names = attr_chain.split(sep)

    new_obj = obj

    for attr_name in attr_names:
        new_obj = getattr(new_obj, attr_name)

    return new_obj
1305499
def get_deep_attr(obj, keys):
    
    cur = obj
    for k in keys:
        if isinstance(cur, Mapping) and k in cur:
            cur = cur[k]
            continue
        else:
            try:
                cur = getattr(cur, k)
                continue
            except AttributeError:
                pass
        raise DataError(error='Unexistent key')
    return cur
593988
def attributes(atts = {}, for_definition = false)
      wrapped_attributes atts, for_definition
      attributes_assignments atts, false, for_definition
      atts
    end
1013822
def __new_attr(self, name, attr):
        
        if isinstance(attr, Pref):
            # Child attribute already has a Pref wrapping
            if VERBOSE_PREF:
                print('[pref.__new_attr]: %s.%s = %r' % (self._intern.name, name, attr.value()))
            new_childx = len(self._tree.child_names)
            # Children know about parents
            attr._tree.parent = self     # Give child parent
            attr._intern.name = name     # Give child name
            if attr._intern.depeq is None:
                attr._intern.depeq = self._intern.depeq  # Give child parent dependencies
            if attr._intern.hidden:
                self._tree.hidden_children.append(new_childx)
                self._tree.hidden_children.sort()
            # Used for QTIndexing
            attr._intern.aschildx = new_childx
            # Parents know about children
            self._tree.child_names.append(name)  # Add child to tree
            self._tree.child_list.append(attr)
            self.__dict__[name] = attr.value()   # Add child value to dict
        else:
            # The child attribute is not wrapped. Wrap with Pref and readd.
            pref_attr = Pref(default=attr)
            self.__new_attr(name, pref_attr)
32434
function attr(obj, key) {
    if (!obj[key]) {
      return '';
    }
    var val = obj[key];
    if (val === true) {
      return key;
    }
    return key + '="' + obj[key] + '"';
  }
143114
def remove_link(self, obj, attr=None):
        
        name = repr(self)
        if not name:
            return self
        l = self.__class__._get_links()
        v = WeakAttrLink(None, obj) if attr is None else WeakAttrLink(obj, attr)
        if name in l:
            if v in l[name]:
                l[name].remove(v)
            if not l[name]:
                l.pop(name)
        return self
144969
def unpatch(obj, name):
    
    setattr(obj, name, getattr(obj, name).original)
387963
def get_attr(item, name, default=None):
    '''  '''
    try:
        val = item[name]
    except (KeyError, TypeError):
        try:
            val = getattr(item, name)
        except AttributeError:
            val = default
    return val
163412
def _get_dynamic_attr(self, attname, obj, default=None):
        
        try:
            attr = getattr(self, attname)
        except AttributeError:
            return default
        if callable(attr):
            # Check co_argcount rather than try/excepting the function and
            # catching the TypeError, because something inside the function
            # may raise the TypeError. This technique is more accurate.
            try:
                code = six.get_function_code(attr)
            except AttributeError:
                code = six.get_function_code(attr.__call__)
            if code.co_argcount == 2:       # one argument is 'self'
                return attr(obj)
            else:
                return attr()
        return attr
1267970
def igetattr(self, attrname, context=None):
        
        if attrname == "start":
            yield self._wrap_attribute(self.lower)
        elif attrname == "stop":
            yield self._wrap_attribute(self.upper)
        elif attrname == "step":
            yield self._wrap_attribute(self.step)
        else:
            yield from self.getattr(attrname, context=context)