Lookup a transitive parent object that is an instance
            of a given class.
173127
def _lookup_parent(self, cls):
        """"""
        codeobj = self.parent
        while codeobj is not None and not isinstance(codeobj, cls):
            codeobj = codeobj.parent
        return codeobj
1182373
def parent(self):
        """"""
        if self.city:
            return Location(
                country=self.country, state=self.state, county=self.county)
        if self.county:
            return Location(country=self.country, state=self.state)
        if self.state:
            return Location(country=self.country)
        return Location()
1238328
public static Field lookupField( Class parentClass, String fieldName )
    {
        try {
            return parentClass.getDeclaredField( fieldName );
        }
        catch ( NoSuchFieldException e ) {
            Class superClass = parentClass.getSuperclass();
            return superClass != null ? lookupField( superClass, fieldName ) : null;
        }
    }
1051547
def instance(cls, *args, **kwgs):
        """"""
        if not hasattr(cls, "_instance"):
            cls._instance = cls(*args, **kwgs)
        return cls._instance
426782
def get_group_instance(self, parent):
        """"""
        o = copy.copy(self)
        o.init_instance(parent)
        return o
869466
def parent(self, key):
        """"""
        parent_key = '.'.join(key.split('.')[:-1])
        if not parent_key:
            return None
        else:
            return self[parent_key]
1254921
def base_object(self, data):
        
        obj = {'id': data.get(self.id)}
        if self.parent is not None:
            obj['$parent'] = data.get(self.parent.id)
        return obj
809965
def get_parent(self):
        
        if self._parent and self._parent.object_id == self.parent_id:
            return self._parent
        else:
            if self.parent_id:
                return self.drive.get_item(self.parent_id)
            else:
                # return the drive
                return self.drive
1087647
def _set_object_self(self, obj):
        
        from nefertari.elasticsearch import ES
        location = self.request.path_url
        route_kwargs = {}

        """ Check for parents """
        if self.request.matchdict:
            route_kwargs.update(self.request.matchdict)
        try:
            type_, obj_pk = obj['_type'], obj['_pk']
        except KeyError:
            return
        resource = (self.model_collections.get(type_) or
                    self.model_collections.get(ES.src2type(type_)))
        if resource is not None:
            route_kwargs.update({resource.id_name: obj_pk})
            location = self.request.route_url(
                resource.uid, **route_kwargs)
        obj.setdefault('_self', location)
1251183
def _assign_parent(self, ctx):
        
        def _assign(cls, _, obj):
            if obj == None:
                return

            if cls.is_produced(obj):
                if isinstance(obj, BaseObj):
                    obj._parent__ = self
            else:
                raise ValueError('Object is not instance of {0} but {1}'.format(cls.__swagger_ref_object__.__name__, obj.__class__.__name__))

        # set self as childrent's parent
        for name, (ct, ctx) in six.iteritems(ctx.__swagger_child__):
            obj = getattr(self, name)
            if obj == None:
                continue

            container_apply(ct, obj, functools.partial(_assign, ctx))
851969
def _find_class(self, class_name):
        ""
        classes = {}
        classes.update(globals())
        classes.update(self.INSTANCE_CLASSES)
        logger.debug(f'looking up class: {class_name}')
        cls = classes[class_name]
        logger.debug(f'found class: {cls}')
        return cls
753787
def get(cls, parent=None, id=None, data=None):
        """"""
        # TODO - allow fetching of parent based on child?

        if parent is not None:
            route = copy(parent.route)
        else:
            route = {}

        if id is not None and cls.ID_NAME is not None:
            route[cls.ID_NAME] = id

        obj = cls(key=parent.key, route=route, config=parent.config)

        if data:
            # This is used in "get all" queries
            obj.data = data
        else:
            obj.fetch()

        return obj
348491
def parent_resources(cls):
        """"""
        parent = cls.parent_resource
        parents = [parent]

        try:
            while True:
                parent = parent.parent_resource
                parents.append(parent)
        except AttributeError:
            pass

        parents.reverse()
        return parents
292044
def FindParentMember(cls, typecheck_parent, name):
    """"""
    if typecheck_parent and hasattr(typecheck_parent, name):
      return getattr(typecheck_parent, name)
    return None
580689
def InstanceOf(cls, **kwargs):
    """"""
    return Property(types=cls, load=cls.load, **kwargs)
1046930
def has_parent_group(self, group):
        """"""
        if isinstance(group, str):
            return self._has_parent_group_by_name(group)

        else:
            return self._has_parent_group_by_object(group)
688672
def get_parent(self, update=False):
        """"""
        if self._meta.proxy_for_model:
            # the current node is a proxy model; the returned parent
            # should be the same proxy model, so we need to explicitly
            # fetch it as an instance of that model rather than simply
            # following the 'parent' relation
            if self.parent_id is None:
                return None
            else:
                return self.__class__.objects.get(pk=self.parent_id)
        else:
            return self.parent