Example #1
0
    def __getattribute__(self, name):
        # To see if name is an instanced attribute of Reference. Here we can
        # check the names of the class attributes and then return the instance
        # attribute with the same name.

        attr = Proxy.__getattribute__(self, name)
        if hasattr(Reference, name):
            return attr

        # Intercept all proxied attributes and methods and attempt to update
        # the Reference ._id and ._href attributes.

        def update_ref(item):
            try:
                id_ = item.id
                href_ = urljoin(analyzere.base_url, item._get_path(id_))
                self._id = id_
                self._href = href_
            except AttributeError:
                pass

        # Check to see if the attribute is a method that is being called.
        if hasattr(attr, '__call__'):
            # Intercept class method for the Resources, as they should not be
            # able to update the _id and _href for a reference. Class methods
            # should never update an instance in place.
            if isclass(attr.__self__) and issubclass(attr.__self__, Resource):
                return attr

            def newfunc(*args, **kwargs):
                retval = attr(*args, **kwargs)
                update_ref(retval)
                return retval

            return newfunc
        else:
            return attr
Example #2
0
 def resolve():
     r = load_reference(collection_name,
                        Proxy.__getattribute__(self, '_id'))
     self._resolved = True
     return r