<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> __docformat__ = '<STR_LIT>' <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> import sys <EOL> old_sys_path = sys . path [ : ] <EOL> sys . path = [ p for p in sys . path if "<STR_LIT>" not in p ] <EOL> import inspect <EOL> sys . path = old_sys_path <EOL> try : <EOL> set <EOL> except NameError : <EOL> from sets import Set as set <EOL> def getinfo ( func ) : <EOL> """<STR_LIT>""" <EOL> assert inspect . ismethod ( func ) or inspect . isfunction ( func ) <EOL> regargs , varargs , varkwargs , defaults = inspect . getargspec ( func ) <EOL> argnames = list ( regargs ) <EOL> if varargs : <EOL> argnames . append ( varargs ) <EOL> if varkwargs : <EOL> argnames . append ( varkwargs ) <EOL> signature = inspect . formatargspec ( regargs , varargs , varkwargs , defaults , <EOL> formatvalue = lambda value : "<STR_LIT>" ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> _closure = func . __closure__ <EOL> _globals = func . __globals__ <EOL> else : <EOL> _closure = func . func_closure <EOL> _globals = func . func_globals <EOL> return dict ( name = func . __name__ , argnames = argnames , signature = signature , <EOL> defaults = func . __defaults__ , doc = func . __doc__ , <EOL> module = func . __module__ , dict = func . __dict__ , <EOL> globals = _globals , closure = _closure ) <EOL> def update_wrapper ( wrapper , model , infodict = None ) : <EOL> infodict = infodict or getinfo ( model ) <EOL> wrapper . __name__ = infodict [ '<STR_LIT:name>' ] <EOL> wrapper . __doc__ = infodict [ '<STR_LIT>' ] <EOL> wrapper . __module__ = infodict [ '<STR_LIT>' ] <EOL> wrapper . __dict__ . update ( infodict [ '<STR_LIT>' ] ) <EOL> wrapper . __defaults__ = infodict [ '<STR_LIT>' ] <EOL> wrapper . undecorated = model <EOL> return wrapper <EOL> def new_wrapper ( wrapper , model ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( model , dict ) : <EOL> infodict = model <EOL> else : <EOL> infodict = getinfo ( model ) <EOL> assert not '<STR_LIT>' in infodict [ "<STR_LIT>" ] , ( <EOL> '<STR_LIT>' ) <EOL> src = "<STR_LIT>" % infodict <EOL> funcopy = eval ( src , dict ( _wrapper_ = wrapper ) ) <EOL> return update_wrapper ( funcopy , model , infodict ) <EOL> def __call__ ( self , func ) : <EOL> return new_wrapper ( lambda * a , ** k : self . call ( func , * a , ** k ) , func ) <EOL> def decorator_factory ( cls ) : <EOL> """<STR_LIT>""" <EOL> attrs = set ( dir ( cls ) ) <EOL> if '<STR_LIT>' in attrs : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in attrs : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cls . __call__ = __call__ <EOL> return cls <EOL> def decorator ( caller ) : <EOL> """<STR_LIT>""" <EOL> if inspect . isclass ( caller ) : <EOL> return decorator_factory ( caller ) <EOL> def _decorator ( func ) : <EOL> infodict = getinfo ( func ) <EOL> argnames = infodict [ '<STR_LIT>' ] <EOL> assert not ( '<STR_LIT>' in argnames or '<STR_LIT>' in argnames ) , ( <EOL> '<STR_LIT>' ) <EOL> src = "<STR_LIT>" % infodict <EOL> dec_func = eval ( src , dict ( _func_ = func , _call_ = caller ) ) <EOL> return update_wrapper ( dec_func , func , infodict ) <EOL> return update_wrapper ( _decorator , caller ) <EOL> def getattr_ ( obj , name , default_thunk ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> return getattr ( obj , name ) <EOL> except AttributeError : <EOL> default = default_thunk ( ) <EOL> setattr ( obj , name , default ) <EOL> return default <EOL> @ decorator <EOL> def memoize ( func , * args ) : <EOL> dic = getattr_ ( func , "<STR_LIT>" , dict ) <EOL> if args in dic : <EOL> return dic [ args ] <EOL> else : <EOL> result = func ( * args ) <EOL> dic [ args ] = result <EOL> return result </s>
