def __getattribute__(self,name):

        """
        Private method.

        This function tests all attributes of the *SimpleModel* if they are
        instances of *meta_query*.
        If they are a *meta_query*, columns from the Model are mapped
        to the InstanceMethods' arguments, as appropriate.
        """

        attr = object.__getattribute__(self,name)
        if name == '__load__':
            d_out("skipping: %s" % name)
            return attr

        if attr is None and name in object.__getattribute__(self, 'table') and not object.__getattribute__(self,'_loaded'):
            should_lazyload = hasattr(self,'__lazyload__')
        else:
            should_lazyload = False

        if should_lazyload:
            d_out("lazyloading {0} on {1}".format(self.__class__, name))
            attrs = object.__getattribute__(self, '__dict__')
            attrs['_loaded'] = True
            rs = self.__lazyload__(options={'handle':self.handle})
            if not rs:
                raise NotFoundError("__lazyload__ returned: {0}".format(rs))
            if isinstance(rs, psycopg2.extras.DictRow):
                loaded_attrs = dict(rs)
            elif isinstance(rs, SimpleModel):
                #python 2.7+:
                #loaded_attrs = {_ for _ in rs.__dict__.iteritems() if _[0] in self.table}
                loaded_attrs = {}
                for col in self.table:
                    loaded_attrs[col] = rs.__dict__[col]
            else:
                raise Exception("__lazyload__ returned unexpected type: {0}".format(type(rs)))
            SimpleModel.merge_base_attrs(loaded_attrs)
            attrs.update(loaded_attrs)
            return attrs[name]

        if isinstance(attr, meta_query):

            d_out("SimpleModel.__getattribute__: Found meta_query %s" % name)
            def instance(*args,**kwargs):

                if args:
                    raise FunctionError("This function can only take keyword arguments.")
                my_args = kwargs.copy()
                d_out("SimpleModel.__getattribute__ InstanceMethod: kwargs: %s" % repr(kwargs))
                d_out("SimpleModel.__getattribute__ InstanceMethod: self.__dict__: %s" % self.__dict__)
                for arg in attr.args:
                    d_out("SimpleModel.__getattribute__ InstanceMethod: checking arg %s" % arg)
                    if arg not in kwargs:
                        d_out("not in my_args")
                        if hasattr(self, arg):
                            d_out("SimpleModel.__getattribute__ InstanceMethod: found %s in col.." % arg)
                            my_args[arg] = getattr(self, arg)
                        else:
                            my_args[arg] = None

                if 'options' not in kwargs:
                    d_out("SimpleModel.__getattribute__ InstanceMethod: Didn't find options.")
                    my_args['options'] = {}

                # pass self to the query object
                my_args['options']['model'] = self

                d_out("SimpleModel.__getattribute__: InstanceMethod: Setting handle.")
                my_args['options']['handle'] = self.handle
                rs = attr(*args, **my_args)
                d_out("SimpleModel.__getattribute__: InstanceMethod: model :{model} attrib name: {name} (attrib value: {value}) constructor returned {rs}".format(model=self, name=name, value=attr, rs=rs))
                return rs

            if attr.is_property:
                return instance()
            else:
                return instance

        else:
            return attr
def __getattribute__ ( self , name ) : attr = object . __getattribute__ ( self , name ) if name == '__load__' : d_out ( "skipping: %s" % name ) return attr if attr is None and name in object . __getattribute__ ( self , 'table' ) and not object . __getattribute__ ( self , '_loaded' ) : should_lazyload = hasattr ( self , '__lazyload__' ) else : should_lazyload = False if should_lazyload : d_out ( "lazyloading {0} on {1}" . format ( self . __class__ , name ) ) attrs = object . __getattribute__ ( self , '__dict__' ) attrs [ '_loaded' ] = True rs = self . __lazyload__ ( options = { 'handle' : self . handle } ) if not rs : raise NotFoundError ( "__lazyload__ returned: {0}" . format ( rs ) ) if isinstance ( rs , psycopg2 . extras . DictRow ) : loaded_attrs = dict ( rs ) elif isinstance ( rs , SimpleModel ) : loaded_attrs = { } for col in self . table : loaded_attrs [ col ] = rs . __dict__ [ col ] else : raise Exception ( "__lazyload__ returned unexpected type: {0}" . format ( type ( rs ) ) ) SimpleModel . merge_base_attrs ( loaded_attrs ) attrs . update ( loaded_attrs ) return attrs [ name ] if isinstance ( attr , meta_query ) : d_out ( "SimpleModel.__getattribute__: Found meta_query %s" % name ) def instance ( * args , ** kwargs ) : if args : raise FunctionError ( "This function can only take keyword arguments." ) my_args = kwargs . copy ( ) d_out ( "SimpleModel.__getattribute__ InstanceMethod: kwargs: %s" % repr ( kwargs ) ) d_out ( "SimpleModel.__getattribute__ InstanceMethod: self.__dict__: %s" % self . __dict__ ) for arg in attr . args : d_out ( "SimpleModel.__getattribute__ InstanceMethod: checking arg %s" % arg ) if arg not in kwargs : d_out ( "not in my_args" ) if hasattr ( self , arg ) : d_out ( "SimpleModel.__getattribute__ InstanceMethod: found %s in col.." % arg ) my_args [ arg ] = getattr ( self , arg ) else : my_args [ arg ] = None if 'options' not in kwargs : d_out ( "SimpleModel.__getattribute__ InstanceMethod: Didn't find options." ) my_args [ 'options' ] = { } my_args [ 'options' ] [ 'model' ] = self d_out ( "SimpleModel.__getattribute__: InstanceMethod: Setting handle." ) my_args [ 'options' ] [ 'handle' ] = self . handle rs = attr ( * args , ** my_args ) d_out ( "SimpleModel.__getattribute__: InstanceMethod: model :{model} attrib name: {name} (attrib value: {value}) constructor returned {rs}" . format ( model = self , name = name , value = attr , rs = rs ) ) return rs if attr . is_property : return instance ( ) else : return instance else : return attr
Private method.

        This function tests all attributes of the *SimpleModel* if they are
        instances of *meta_query*.
        If they are a *meta_query*, columns from the Model are mapped
        to the InstanceMethods' arguments, as appropriate.