<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> import types <EOL> import CallTipWindow <EOL> from HyperParser import HyperParser <EOL> import __main__ <EOL> class CallTips : <EOL> menudefs = [ <EOL> ( '<STR_LIT>' , [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] ) <EOL> ] <EOL> def __init__ ( self , editwin = None ) : <EOL> if editwin is None : <EOL> self . editwin = None <EOL> return <EOL> self . editwin = editwin <EOL> self . text = editwin . text <EOL> self . calltip = None <EOL> self . _make_calltip_window = self . _make_tk_calltip_window <EOL> def close ( self ) : <EOL> self . _make_calltip_window = None <EOL> def _make_tk_calltip_window ( self ) : <EOL> return CallTipWindow . CallTip ( self . text ) <EOL> def _remove_calltip_window ( self , event = None ) : <EOL> if self . calltip : <EOL> self . calltip . hidetip ( ) <EOL> self . calltip = None <EOL> def force_open_calltip_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . open_calltip ( True ) <EOL> def try_open_calltip_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . open_calltip ( False ) <EOL> def refresh_calltip_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . calltip and self . calltip . is_active ( ) : <EOL> self . open_calltip ( False ) <EOL> def open_calltip ( self , evalfuncs ) : <EOL> self . _remove_calltip_window ( ) <EOL> hp = HyperParser ( self . editwin , "<STR_LIT>" ) <EOL> sur_paren = hp . get_surrounding_brackets ( '<STR_LIT:(>' ) <EOL> if not sur_paren : <EOL> return <EOL> hp . set_index ( sur_paren [ <NUM_LIT:0> ] ) <EOL> name = hp . get_expression ( ) <EOL> if not name or ( not evalfuncs and name . find ( '<STR_LIT:(>' ) != - <NUM_LIT:1> ) : <EOL> return <EOL> arg_text = self . fetch_tip ( name ) <EOL> if not arg_text : <EOL> return <EOL> self . calltip = self . _make_calltip_window ( ) <EOL> self . calltip . showtip ( arg_text , sur_paren [ <NUM_LIT:0> ] , sur_paren [ <NUM_LIT:1> ] ) <EOL> def fetch_tip ( self , name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> rpcclt = self . editwin . flist . pyshell . interp . rpcclt <EOL> except : <EOL> rpcclt = None <EOL> if rpcclt : <EOL> return rpcclt . remotecall ( "<STR_LIT>" , "<STR_LIT>" , <EOL> ( name , ) , { } ) <EOL> else : <EOL> entity = self . get_entity ( name ) <EOL> return get_arg_text ( entity ) <EOL> def get_entity ( self , name ) : <EOL> "<STR_LIT>" <EOL> if name : <EOL> namespace = sys . modules . copy ( ) <EOL> namespace . update ( __main__ . __dict__ ) <EOL> try : <EOL> return eval ( name , namespace ) <EOL> except ( NameError , AttributeError ) : <EOL> return None <EOL> def _find_constructor ( class_ob ) : <EOL> try : <EOL> return class_ob . __init__ . im_func <EOL> except AttributeError : <EOL> for base in class_ob . __bases__ : <EOL> rc = _find_constructor ( base ) <EOL> if rc is not None : return rc <EOL> return None <EOL> def get_arg_text ( ob ) : <EOL> """<STR_LIT>""" <EOL> arg_text = "<STR_LIT>" <EOL> if ob is not None : <EOL> arg_offset = <NUM_LIT:0> <EOL> if type ( ob ) in ( types . ClassType , types . TypeType ) : <EOL> fob = _find_constructor ( ob ) <EOL> if fob is None : <EOL> fob = lambda : None <EOL> else : <EOL> arg_offset = <NUM_LIT:1> <EOL> elif type ( ob ) == types . MethodType : <EOL> fob = ob . im_func <EOL> arg_offset = <NUM_LIT:1> <EOL> else : <EOL> fob = ob <EOL> if type ( fob ) in [ types . FunctionType , types . LambdaType ] : <EOL> argcount = fob . func_code . co_argcount <EOL> real_args = fob . func_code . co_varnames [ arg_offset : argcount ] <EOL> defaults = fob . func_defaults or [ ] <EOL> defaults = list ( map ( lambda name : "<STR_LIT>" % repr ( name ) , defaults ) ) <EOL> defaults = [ "<STR_LIT>" ] * ( len ( real_args ) - len ( defaults ) ) + defaults <EOL> items = map ( lambda arg , dflt : arg + dflt , real_args , defaults ) <EOL> if fob . func_code . co_flags & <NUM_LIT> : <EOL> items . append ( "<STR_LIT>" ) <EOL> if fob . func_code . co_flags & <NUM_LIT> : <EOL> items . append ( "<STR_LIT>" ) <EOL> arg_text = "<STR_LIT:U+002CU+0020>" . join ( items ) <EOL> arg_text = "<STR_LIT>" % re . sub ( "<STR_LIT>" , "<STR_LIT>" , arg_text ) <EOL> doc = getattr ( ob , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if doc : <EOL> doc = doc . lstrip ( ) <EOL> pos = doc . find ( "<STR_LIT:\n>" ) <EOL> if pos < <NUM_LIT:0> or pos > <NUM_LIT> : <EOL> pos = <NUM_LIT> <EOL> if arg_text : <EOL> arg_text += "<STR_LIT:\n>" <EOL> arg_text += doc [ : pos ] <EOL> return arg_text <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> def t1 ( ) : "<STR_LIT>" <EOL> def t2 ( a , b = None ) : "<STR_LIT>" <EOL> def t3 ( a , * args ) : "<STR_LIT>" <EOL> def t4 ( * args ) : "<STR_LIT>" <EOL> def t5 ( a , * args ) : "<STR_LIT>" <EOL> def t6 ( a , b = None , * args , ** kw ) : "<STR_LIT>" <EOL> def t7 ( ( a , b ) , c , ( d , e ) ) : "<STR_LIT>" <EOL> class TC ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , ai = None , * b ) : "<STR_LIT>" <EOL> def t1 ( self ) : "<STR_LIT>" <EOL> def t2 ( self , ai , b = None ) : "<STR_LIT>" <EOL> def t3 ( self , ai , * args ) : "<STR_LIT>" <EOL> def t4 ( self , * args ) : "<STR_LIT>" <EOL> def t5 ( self , ai , * args ) : "<STR_LIT>" <EOL> def t6 ( self , ai , b = None , * args , ** kw ) : "<STR_LIT>" <EOL> def t7 ( self , ( ai , b ) , c , ( d , e ) ) : "<STR_LIT>" <EOL> def test ( tests ) : <EOL> ct = CallTips ( ) <EOL> failed = [ ] <EOL> for t in tests : <EOL> expected = t . __doc__ + "<STR_LIT:\n>" + t . __doc__ <EOL> name = t . __name__ <EOL> try : <EOL> qualified_name = "<STR_LIT>" % ( t . im_class . __name__ , name ) <EOL> except AttributeError : <EOL> qualified_name = name <EOL> arg_text = ct . fetch_tip ( qualified_name ) <EOL> if arg_text != expected : <EOL> failed . append ( t ) <EOL> fmt = "<STR_LIT>" <EOL> print fmt % ( t . __name__ , expected , get_arg_text ( t ) ) <EOL> print "<STR_LIT>" % ( len ( failed ) , len ( tests ) ) <EOL> tc = TC ( ) <EOL> tests = ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , <EOL> TC , tc . t1 , tc . t2 , tc . t3 , tc . t4 , tc . t5 , tc . t6 , tc . t7 ) <EOL> test ( tests ) </s>
