<s> """<STR_LIT>""" <EOL> from . . import util <EOL> def _legacy_signature ( since , argnames , converter = None ) : <EOL> def leg ( fn ) : <EOL> if not hasattr ( fn , '<STR_LIT>' ) : <EOL> fn . _legacy_signatures = [ ] <EOL> fn . _legacy_signatures . append ( ( since , argnames , converter ) ) <EOL> return fn <EOL> return leg <EOL> def _wrap_fn_for_legacy ( dispatch_descriptor , fn , argspec ) : <EOL> for since , argnames , conv in dispatch_descriptor . legacy_signatures : <EOL> if argnames [ - <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> has_kw = True <EOL> argnames = argnames [ <NUM_LIT:0> : - <NUM_LIT:1> ] <EOL> else : <EOL> has_kw = False <EOL> if len ( argnames ) == len ( argspec . args ) and has_kw is bool ( argspec . keywords ) : <EOL> if conv : <EOL> assert not has_kw <EOL> def wrap_leg ( * args ) : <EOL> return fn ( * conv ( * args ) ) <EOL> else : <EOL> def wrap_leg ( * args , ** kw ) : <EOL> argdict = dict ( zip ( dispatch_descriptor . arg_names , args ) ) <EOL> args = [ argdict [ name ] for name in argnames ] <EOL> if has_kw : <EOL> return fn ( * args , ** kw ) <EOL> else : <EOL> return fn ( * args ) <EOL> return wrap_leg <EOL> else : <EOL> return fn <EOL> def _indent ( text , indent ) : <EOL> return "<STR_LIT:\n>" . join ( <EOL> indent + line <EOL> for line in text . split ( "<STR_LIT:\n>" ) <EOL> ) <EOL> def _standard_listen_example ( dispatch_descriptor , sample_target , fn ) : <EOL> example_kw_arg = _indent ( <EOL> "<STR_LIT:\n>" . join ( <EOL> "<STR_LIT>" % { "<STR_LIT>" : arg } <EOL> for arg in dispatch_descriptor . arg_names [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> ) , <EOL> "<STR_LIT:U+0020>" ) <EOL> if dispatch_descriptor . legacy_signatures : <EOL> current_since = max ( since for since , args , conv <EOL> in dispatch_descriptor . legacy_signatures ) <EOL> else : <EOL> current_since = None <EOL> text = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> if len ( dispatch_descriptor . arg_names ) > <NUM_LIT:3> : <EOL> text += ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> text %= { <EOL> "<STR_LIT>" : "<STR_LIT>" % <EOL> current_since if current_since else "<STR_LIT>" , <EOL> "<STR_LIT>" : fn . __name__ , <EOL> "<STR_LIT>" : "<STR_LIT>" if dispatch_descriptor . has_kw else "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:U+002CU+0020>" . join ( dispatch_descriptor . arg_names ) , <EOL> "<STR_LIT>" : example_kw_arg , <EOL> "<STR_LIT>" : sample_target <EOL> } <EOL> return text <EOL> def _legacy_listen_examples ( dispatch_descriptor , sample_target , fn ) : <EOL> text = "<STR_LIT>" <EOL> for since , args , conv in dispatch_descriptor . legacy_signatures : <EOL> text += ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { <EOL> "<STR_LIT>" : since , <EOL> "<STR_LIT>" : fn . __name__ , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> if dispatch_descriptor . has_kw else "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:U+002CU+0020>" . join ( args ) , <EOL> "<STR_LIT>" : sample_target <EOL> } <EOL> ) <EOL> return text <EOL> def _version_signature_changes ( dispatch_descriptor ) : <EOL> since , args , conv = dispatch_descriptor . legacy_signatures [ <NUM_LIT:0> ] <EOL> return ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { <EOL> "<STR_LIT>" : since , <EOL> "<STR_LIT>" : dispatch_descriptor . __name__ , <EOL> "<STR_LIT>" : "<STR_LIT:U+002CU+0020>" . join ( dispatch_descriptor . arg_names ) , <EOL> "<STR_LIT>" : "<STR_LIT>" if dispatch_descriptor . has_kw else "<STR_LIT>" <EOL> } <EOL> ) <EOL> def _augment_fn_docs ( dispatch_descriptor , parent_dispatch_cls , fn ) : <EOL> header = "<STR_LIT>" "<STR_LIT>" "<STR_LIT:\n>" <EOL> sample_target = getattr ( parent_dispatch_cls , "<STR_LIT>" , "<STR_LIT>" ) <EOL> text = ( <EOL> header + <EOL> _indent ( <EOL> _standard_listen_example ( <EOL> dispatch_descriptor , sample_target , fn ) , <EOL> "<STR_LIT:U+0020>" * <NUM_LIT:8> ) <EOL> ) <EOL> if dispatch_descriptor . legacy_signatures : <EOL> text += _indent ( <EOL> _legacy_listen_examples ( <EOL> dispatch_descriptor , sample_target , fn ) , <EOL> "<STR_LIT:U+0020>" * <NUM_LIT:8> ) <EOL> text += _version_signature_changes ( dispatch_descriptor ) <EOL> return util . inject_docstring_text ( fn . __doc__ , <EOL> text , <EOL> <NUM_LIT:1> <EOL> ) </s>
