<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> import sys , re , inspect <EOL> try : <EOL> from functools import partial <EOL> except ImportError : <EOL> class partial ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , func , * args , ** kw ) : <EOL> self . func = func <EOL> self . args = args <EOL> self . keywords = kw <EOL> def __call__ ( self , * otherargs , ** otherkw ) : <EOL> kw = self . keywords . copy ( ) <EOL> kw . update ( otherkw ) <EOL> return self . func ( * ( self . args + otherargs ) , ** kw ) <EOL> if sys . version >= '<STR_LIT:3>' : <EOL> from inspect import getfullargspec <EOL> else : <EOL> class getfullargspec ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , f ) : <EOL> self . args , self . varargs , self . varkw , self . defaults = inspect . getargspec ( f ) <EOL> self . kwonlyargs = [ ] <EOL> self . kwonlydefaults = None <EOL> self . annotations = getattr ( f , '<STR_LIT>' , { } ) <EOL> def __iter__ ( self ) : <EOL> yield self . args <EOL> yield self . varargs <EOL> yield self . varkw <EOL> yield self . defaults <EOL> DEF = re . compile ( '<STR_LIT>' ) <EOL> class FunctionMaker ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , func = None , name = None , signature = None , <EOL> defaults = None , doc = None , module = None , funcdict = None ) : <EOL> self . shortsignature = signature <EOL> if func : <EOL> self . name = func . __name__ <EOL> if self . name == '<STR_LIT>' : <EOL> self . name = '<STR_LIT>' <EOL> self . doc = func . __doc__ <EOL> self . module = func . __module__ <EOL> if inspect . isfunction ( func ) : <EOL> argspec = getfullargspec ( func ) <EOL> for a in ( '<STR_LIT:args>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> setattr ( self , a , getattr ( argspec , a ) ) <EOL> for i , arg in enumerate ( self . args ) : <EOL> setattr ( self , '<STR_LIT>' % i , arg ) <EOL> self . signature = inspect . formatargspec ( <EOL> formatvalue = lambda val : "<STR_LIT>" , * argspec ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> allargs = list ( self . args ) <EOL> if self . varargs : <EOL> allargs . append ( '<STR_LIT:*>' + self . varargs ) <EOL> if self . varkw : <EOL> allargs . append ( '<STR_LIT>' + self . varkw ) <EOL> try : <EOL> self . shortsignature = '<STR_LIT:U+002CU+0020>' . join ( allargs ) <EOL> except TypeError : <EOL> self . shortsignature = self . signature <EOL> self . dict = func . __dict__ . copy ( ) <EOL> if name : <EOL> self . name = name <EOL> if signature is not None : <EOL> self . signature = signature <EOL> if defaults : <EOL> self . defaults = defaults <EOL> if doc : <EOL> self . doc = doc <EOL> if module : <EOL> self . module = module <EOL> if funcdict : <EOL> self . dict = funcdict <EOL> assert hasattr ( self , '<STR_LIT:name>' ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> raise TypeError ( '<STR_LIT>' % func ) <EOL> def update ( self , func , ** kw ) : <EOL> "<STR_LIT>" <EOL> func . __name__ = self . name <EOL> func . __doc__ = getattr ( self , '<STR_LIT>' , None ) <EOL> func . __dict__ = getattr ( self , '<STR_LIT>' , { } ) <EOL> func . func_defaults = getattr ( self , '<STR_LIT>' , ( ) ) <EOL> func . __kwdefaults__ = getattr ( self , '<STR_LIT>' , None ) <EOL> callermodule = sys . _getframe ( <NUM_LIT:3> ) . f_globals . get ( '<STR_LIT>' , '<STR_LIT:?>' ) <EOL> func . __module__ = getattr ( self , '<STR_LIT>' , callermodule ) <EOL> func . __dict__ . update ( kw ) <EOL> def make ( self , src_templ , evaldict = None , addsource = False , ** attrs ) : <EOL> "<STR_LIT>" <EOL> src = src_templ % vars ( self ) <EOL> evaldict = evaldict or { } <EOL> mo = DEF . match ( src ) <EOL> if mo is None : <EOL> raise SyntaxError ( '<STR_LIT>' % src ) <EOL> name = mo . group ( <NUM_LIT:1> ) <EOL> names = set ( [ name ] + [ arg . strip ( '<STR_LIT>' ) for arg in <EOL> self . shortsignature . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> for n in names : <EOL> if n in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise NameError ( '<STR_LIT>' % ( n , src ) ) <EOL> if not src . endswith ( '<STR_LIT:\n>' ) : <EOL> src += '<STR_LIT:\n>' <EOL> try : <EOL> code = compile ( src , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exec code in evaldict <EOL> except : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> print >> sys . stderr , src <EOL> raise <EOL> func = evaldict [ name ] <EOL> if addsource : <EOL> attrs [ '<STR_LIT>' ] = src <EOL> self . update ( func , ** attrs ) <EOL> return func <EOL> @ classmethod <EOL> def create ( cls , obj , body , evaldict , defaults = None , <EOL> doc = None , module = None , addsource = True , ** attrs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , str ) : <EOL> name , rest = obj . strip ( ) . split ( '<STR_LIT:(>' , <NUM_LIT:1> ) <EOL> signature = rest [ : - <NUM_LIT:1> ] <EOL> func = None <EOL> else : <EOL> name = None <EOL> signature = None <EOL> func = obj <EOL> self = cls ( func , name , signature , defaults , doc , module ) <EOL> ibody = '<STR_LIT:\n>' . join ( '<STR_LIT:U+0020>' + line for line in body . splitlines ( ) ) <EOL> return self . make ( '<STR_LIT>' + ibody , <EOL> evaldict , addsource , ** attrs ) <EOL> def decorator ( caller , func = None ) : <EOL> """<STR_LIT>""" <EOL> if func is not None : <EOL> evaldict = func . func_globals . copy ( ) <EOL> evaldict [ '<STR_LIT>' ] = caller <EOL> evaldict [ '<STR_LIT>' ] = func <EOL> return FunctionMaker . create ( <EOL> func , "<STR_LIT>" , <EOL> evaldict , undecorated = func , __wrapped__ = func ) <EOL> else : <EOL> if isinstance ( caller , partial ) : <EOL> return partial ( decorator , caller ) <EOL> first = inspect . getargspec ( caller ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> evaldict = caller . func_globals . copy ( ) <EOL> evaldict [ '<STR_LIT>' ] = caller <EOL> evaldict [ '<STR_LIT>' ] = decorator <EOL> return FunctionMaker . create ( <EOL> '<STR_LIT>' % ( caller . __name__ , first ) , <EOL> '<STR_LIT>' % first , <EOL> evaldict , undecorated = caller , __wrapped__ = caller , <EOL> doc = caller . __doc__ , module = caller . __module__ ) </s>
