#NEWLINE# def declared_mixin( * bases ) : #NEWLINE# #INDENT# 'Create mix-in class with all assignments turned into methods decorated\n    with declared_attr. Usage:\n\n        @declared_mixin\n        def FactoryFunction():\n\n    or with base mix-in class[es]:\n\n        @declared_mixin(BaseMixIn1, BaseMixIn2)\n        def FactoryFunction():\n\n    For example:\n\n        @declared_mixin\n        def WithParent():\n            parent_id = Column(ForeignKey(Parent.id))\n            parent = relationship(Parent)\n\n    is equivalent to\n\n        class WithParent(object):\n            @declared_attr\n            def parent_id(cls):\n                return Column(ForeignKey(Parent.id))\n            @declared_attr\n            def parent(cls):\n                return relationship(Parent)\n    ' #NEWLINE# def wrapper( func ) : #NEWLINE# #INDENT# attrs = weakref . WeakKeyDictionary ( ) #NEWLINE# def create_descriptor( name ) : #NEWLINE# #INDENT# def get_attr( cls ) : #NEWLINE# #INDENT# if ( cls not in attrs ) : #NEWLINE# #INDENT# attrs [ cls ] = return_locals ( func ) ( ) #NEWLINE# #UNINDENT# return attrs [ cls ] [ name ] #NEWLINE# #UNINDENT# get_attr . __name__ = name #NEWLINE# return declared_attr ( get_attr ) #NEWLINE# #UNINDENT# dict_ = { name : create_descriptor ( name ) for name in func . func_code . co_varnames } #NEWLINE# dict_ [ '__doc__' ] = func . __doc__ #NEWLINE# return type ( func . __name__ , bases , dict_ ) #NEWLINE# #UNINDENT# if ( ( len ( bases ) == 1 ) and ( not isinstance ( wrapper [ 0 ] , type ) ) ) : #NEWLINE# #INDENT# func = bases [ 0 ] #NEWLINE# bases = ( ) #NEWLINE# return wrapper ( func ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return wrapper