<s> """<STR_LIT>""" <EOL> import re <EOL> from six import PY3 , binary_type <EOL> from six . moves import builtins <EOL> from sphinx . util import force_decode <EOL> inspect = __import__ ( '<STR_LIT>' ) <EOL> memory_address_re = re . compile ( r'<STR_LIT>' ) <EOL> if PY3 : <EOL> from functools import partial <EOL> def getargspec ( func ) : <EOL> """<STR_LIT>""" <EOL> if inspect . ismethod ( func ) : <EOL> func = func . __func__ <EOL> if type ( func ) is partial : <EOL> orig_func = func . func <EOL> argspec = getargspec ( orig_func ) <EOL> args = list ( argspec [ <NUM_LIT:0> ] ) <EOL> defaults = list ( argspec [ <NUM_LIT:3> ] or ( ) ) <EOL> kwoargs = list ( argspec [ <NUM_LIT:4> ] ) <EOL> kwodefs = dict ( argspec [ <NUM_LIT:5> ] or { } ) <EOL> if func . args : <EOL> args = args [ len ( func . args ) : ] <EOL> for arg in func . keywords or ( ) : <EOL> try : <EOL> i = args . index ( arg ) - len ( args ) <EOL> del args [ i ] <EOL> try : <EOL> del defaults [ i ] <EOL> except IndexError : <EOL> pass <EOL> except ValueError : <EOL> i = kwoargs . index ( arg ) <EOL> del kwoargs [ i ] <EOL> del kwodefs [ arg ] <EOL> return inspect . FullArgSpec ( args , argspec [ <NUM_LIT:1> ] , argspec [ <NUM_LIT:2> ] , <EOL> tuple ( defaults ) , kwoargs , <EOL> kwodefs , argspec [ <NUM_LIT:6> ] ) <EOL> while hasattr ( func , '<STR_LIT>' ) : <EOL> func = func . __wrapped__ <EOL> if not inspect . isfunction ( func ) : <EOL> raise TypeError ( '<STR_LIT>' % func ) <EOL> return inspect . getfullargspec ( func ) <EOL> else : <EOL> from functools import partial <EOL> def getargspec ( func ) : <EOL> """<STR_LIT>""" <EOL> if inspect . ismethod ( func ) : <EOL> func = func . __func__ <EOL> parts = <NUM_LIT:0> , ( ) <EOL> if type ( func ) is partial : <EOL> keywords = func . keywords <EOL> if keywords is None : <EOL> keywords = { } <EOL> parts = len ( func . args ) , keywords . keys ( ) <EOL> func = func . func <EOL> if not inspect . isfunction ( func ) : <EOL> raise TypeError ( '<STR_LIT>' % func ) <EOL> args , varargs , varkw = inspect . getargs ( func . __code__ ) <EOL> func_defaults = func . __defaults__ <EOL> if func_defaults is None : <EOL> func_defaults = [ ] <EOL> else : <EOL> func_defaults = list ( func_defaults ) <EOL> if parts [ <NUM_LIT:0> ] : <EOL> args = args [ parts [ <NUM_LIT:0> ] : ] <EOL> if parts [ <NUM_LIT:1> ] : <EOL> for arg in parts [ <NUM_LIT:1> ] : <EOL> i = args . index ( arg ) - len ( args ) <EOL> del args [ i ] <EOL> try : <EOL> del func_defaults [ i ] <EOL> except IndexError : <EOL> pass <EOL> return inspect . ArgSpec ( args , varargs , varkw , func_defaults ) <EOL> def isdescriptor ( x ) : <EOL> """<STR_LIT>""" <EOL> for item in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> if hasattr ( safe_getattr ( x , item , None ) , '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def safe_getattr ( obj , name , * defargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return getattr ( obj , name , * defargs ) <EOL> except Exception : <EOL> if defargs : <EOL> return defargs [ <NUM_LIT:0> ] <EOL> raise AttributeError ( name ) <EOL> def safe_getmembers ( object , predicate = None , attr_getter = safe_getattr ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> for key in dir ( object ) : <EOL> try : <EOL> value = attr_getter ( object , key , None ) <EOL> except AttributeError : <EOL> continue <EOL> if not predicate or predicate ( value ) : <EOL> results . append ( ( key , value ) ) <EOL> results . sort ( ) <EOL> return results <EOL> def object_description ( object ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> s = repr ( object ) <EOL> except Exception : <EOL> raise ValueError <EOL> if isinstance ( s , binary_type ) : <EOL> s = force_decode ( s , None ) <EOL> s = memory_address_re . sub ( '<STR_LIT>' , s ) <EOL> return s . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> def is_builtin_class_method ( obj , attr_name ) : <EOL> """<STR_LIT>""" <EOL> classes = [ c for c in inspect . getmro ( obj ) if attr_name in c . __dict__ ] <EOL> cls = classes [ <NUM_LIT:0> ] if classes else object <EOL> if not hasattr ( builtins , safe_getattr ( cls , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return False <EOL> return getattr ( builtins , safe_getattr ( cls , '<STR_LIT>' , '<STR_LIT>' ) ) is cls </s>
