<s> '''<STR_LIT>''' <EOL> from IPython . external import argparse <EOL> from IPython . core . error import UsageError <EOL> from IPython . utils . process import arg_split <EOL> class MagicArgumentParser ( argparse . ArgumentParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> prog = None , <EOL> usage = None , <EOL> description = None , <EOL> epilog = None , <EOL> version = None , <EOL> parents = None , <EOL> formatter_class = argparse . HelpFormatter , <EOL> prefix_chars = '<STR_LIT:->' , <EOL> argument_default = None , <EOL> conflict_handler = '<STR_LIT:error>' , <EOL> add_help = False ) : <EOL> if parents is None : <EOL> parents = [ ] <EOL> super ( MagicArgumentParser , self ) . __init__ ( prog = prog , usage = usage , <EOL> description = description , epilog = epilog , version = version , <EOL> parents = parents , formatter_class = formatter_class , <EOL> prefix_chars = prefix_chars , argument_default = argument_default , <EOL> conflict_handler = conflict_handler , add_help = add_help ) <EOL> def error ( self , message ) : <EOL> """<STR_LIT>""" <EOL> raise UsageError ( message ) <EOL> def parse_argstring ( self , argstring ) : <EOL> """<STR_LIT>""" <EOL> argv = arg_split ( argstring ) <EOL> return self . parse_args ( argv ) <EOL> def construct_parser ( magic_func ) : <EOL> """<STR_LIT>""" <EOL> kwds = getattr ( magic_func , '<STR_LIT>' , { } ) <EOL> if '<STR_LIT:description>' not in kwds : <EOL> kwds [ '<STR_LIT:description>' ] = getattr ( magic_func , '<STR_LIT>' , None ) <EOL> arg_name = real_name ( magic_func ) <EOL> parser = MagicArgumentParser ( arg_name , ** kwds ) <EOL> group = None <EOL> for deco in magic_func . decorators [ : : - <NUM_LIT:1> ] : <EOL> result = deco . add_to_parser ( parser , group ) <EOL> if result is not None : <EOL> group = result <EOL> help_text = parser . format_help ( ) <EOL> if help_text . startswith ( '<STR_LIT>' ) : <EOL> help_text = help_text . replace ( '<STR_LIT>' , '<STR_LIT:%>' , <NUM_LIT:1> ) <EOL> else : <EOL> help_text = '<STR_LIT:%>' + help_text <EOL> magic_func . __doc__ = help_text <EOL> return parser <EOL> def parse_argstring ( magic_func , argstring ) : <EOL> """<STR_LIT>""" <EOL> return magic_func . parser . parse_argstring ( argstring ) <EOL> def real_name ( magic_func ) : <EOL> """<STR_LIT>""" <EOL> magic_name = magic_func . __name__ <EOL> if magic_name . startswith ( '<STR_LIT>' ) : <EOL> magic_name = magic_name [ len ( '<STR_LIT>' ) : ] <EOL> return getattr ( magic_func , '<STR_LIT>' , magic_name ) <EOL> class ArgDecorator ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , func ) : <EOL> if not getattr ( func , '<STR_LIT>' , False ) : <EOL> func . has_arguments = True <EOL> func . decorators = [ ] <EOL> func . decorators . append ( self ) <EOL> return func <EOL> def add_to_parser ( self , parser , group ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class magic_arguments ( ArgDecorator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = None ) : <EOL> self . name = name <EOL> def __call__ ( self , func ) : <EOL> if not getattr ( func , '<STR_LIT>' , False ) : <EOL> func . has_arguments = True <EOL> func . decorators = [ ] <EOL> if self . name is not None : <EOL> func . argcmd_name = self . name <EOL> func . parser = construct_parser ( func ) <EOL> return func <EOL> class argument ( ArgDecorator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> self . args = args <EOL> self . kwds = kwds <EOL> def add_to_parser ( self , parser , group ) : <EOL> """<STR_LIT>""" <EOL> if group is not None : <EOL> parser = group <EOL> parser . add_argument ( * self . args , ** self . kwds ) <EOL> return None <EOL> class argument_group ( ArgDecorator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> self . args = args <EOL> self . kwds = kwds <EOL> def add_to_parser ( self , parser , group ) : <EOL> """<STR_LIT>""" <EOL> return parser . add_argument_group ( * self . args , ** self . kwds ) <EOL> class kwds ( ArgDecorator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwds ) : <EOL> self . kwds = kwds <EOL> def __call__ ( self , func ) : <EOL> func = super ( kwds , self ) . __call__ ( func ) <EOL> func . argcmd_kwds = self . kwds <EOL> return func <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] </s>
