
    d9                         d Z dZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZ 	 	 ddZ	 	 ddZd Zd Zdd	Zdd
Zd ZddZd Zd Zy)zqProvides a variety of introspective-type support functions for
things like call tips and command auto completion.z(Patrick K. O'Brien <pobrien@orbtech.com>    N)BytesIOPY3string_typesc                     g }t        | d      }	 |t        ||      }nt        |      }t        ||||      }|S #  Y |S xY w)zsReturn list of auto-completion options for command.

    The list of options will be based on the locals namespace..
terminator)getRootevalgetAttributeNames)commandlocalsincludeMagicincludeSingleincludeDouble
attributesrootobjs           2/usr/lib/python3/dist-packages/wx/py/introspect.pygetAutoCompleteListr      sd    
 J7s+D	EtV$Ct*C 'sL'4mE
 s	   ; A c           	      X   g }i }t        |       s#g d}||D cg c]  }t        | |      r| c}z  }|rM|| j                         z  }t        | d      r.	 | j                         D ]  }||vst        | |      s||z  } 	 t	        t        |             }	|	dk(  r|t        |       z  }nxt        |       }
t        |       }|
j                         D ]O  \  \  }}}}t        |       j                  |k(  r|dk(  r||z  }-||D cg c]  }||vrt        | |      r| c}z  }Q |D ]  }d||<   	 t        |      }|D cg c]  }t        |      t        k(  r| }}|j                  d        |st        d |      }|st        d	 |      }|S c c}w #  Y OxY w#  Y xY wc c}w c c}w )
z?Return list of unique attributes, including inherited, for obj.)	__bases__	__class____dict____name__func_closure	func_codefunc_defaults	func_dictfunc_docfunc_globals	func_name	trait_getz<type 'array'>dirNc                 "    | j                         S N)upper)xs    r   <lambda>z#getAttributeNames.<locals>.<lambda>T   s    !'')     )keyc                 &    | d   dk7  xs | dd dk(  S )Nr   _       items    r   r)   z#getAttributeNames.<locals>.<lambda>V   s#    a# *.#Aay#~ r*   c                     | d d dk7  S )Nr/   __r0   r1   s    r   r)   z#getAttributeNames.<locals>.<lambda>Y   s    bq4 r*   )hasattrAlwaysReturnsTruehasattr_getAttributeNamesr#   strtyper$   getAllAttributeNamesitemsr   listsortfilter)r   r   r   r   r   dictspecial_attrsattristr_typeattrdictobj_dirobj_type_name	techniquecountattrlistr2   	attributes                     r   r   r   "   s    JD#C(O 	 .!#t,  . 	.
31133Z 3{# ,A
*"3?&!OJ, 49~H##c#h
',c(;C>>;K 	N7-]Iux Cy!!]2yE7Ih&
 N"&g"5'#t:L  $ N N
	N  T
dJ .8 -	)_+  -J -OO+O, ./9;
7D
]. 	 N-s4   FF F -F :F F"=F'FFc                     t        | d      S )Nbogu5_123_aTTri8ute)r6   )r   s    r   r5   r5   \   s    3-..r*   c                 ,   i }	 t        |       j                  }t        |       }~t        |       }|||dt	        |      f<   	 t        | j                        }|||dt	        |      f<   	 | j                  }|| u rn|j                  t        |             	 	 | j                  }t        |t              r3|D ].  }t        |      t         u r|j                  t        |             0 |S # t        $ r d}Y w xY w# t        $ r Y w xY w#  Y vxY w#  Y |S xY w)zReturn dict of all attributes, including inherited, for an object.

    Recursively walk through a class and all base classes.
    	anonymousr$   r   )r9   r   	Exceptionr$   lensortedr   r   updater:   r   
isinstancetuple)r   rD   r+   
wakeupcallr   klassbasesbases           r   r:   r:   _   s<   
 H 3i   SJSJ.8Hc5#j/*+BCLL)
 8B#z3z?34
9 C< OO078@ eU# @:%OO$8$>?@ OQ     Os;   C' C8 )D D 'C54C58	DDDDc                    d}t        | d      }	 |t        ||      }nt        |      }d}t        |      \  }}	 |j                  }d}d}t        j                  |      rnt        j                  |      ry	 t        t        j                  |            }|rS|j                  d      }	t        |	      dk(  rd}n1|	d	   dd
 dk(  rn%ddj!                  |	dd       j#                         z   }||z   }d}
t%        |      r	 t        j&                  |      }
|
rz|
j                  d      d	   j#                         }||k(  s|dt        |      dz    |dz   k(  rd}n|dz  }|
j                  d      }|d	   }dj!                  |dd       }||d|}n|}t)        j*                  d|      }|r|j-                  d      }|||j/                         f}|S #  |cY S xY w# t        $ r Y w xY w# t        $ rF t        st        j                  |      nt        j                  |      }t        j                  | }Y w xY w#  Y ,xY w)zFor a command, return a tuple of object name, argspec, tip text.

    The call tip information will be based on the locals namespace.) rZ   rZ   (r   NrZ   ,r.   ()r   r/   z(*
z

z\((.*)\))r
   r   getBaseObjectr   AttributeErrorinspect	isbuiltin
isfunctionr8   	signaturer   
getargspecgetfullargspecformatargspecsplitrP   joinlstripcallablegetdocresearchgroupstrip)r   r   calltipr   r   namedropSelftip1argspectempdoc	firstline	docpiecestip2tip3tipms                    r   
getCallTipr~      sO    G7s+DtV$Ct*C D!#&MC|| DG			C	 	6'++C01G  ==%D4yA~a!$ab 2 9 9 ;;g~
C}	..%C 
 IIdOA&--/	9	,3t9Q; 748 CDFNDIIf%	|{{9QR=)"D$/
		+w'A''!*Wciik*GNw
    	658g((-g>T>TUX>YG++W5G	6&	s;   G G 8G( >H: G	G%$G%(AH76H7:H?c                    | j                  d      d   } | j                  t        j                        r| t	        t        j                        d } | j                         } t        | |      } |dk(  rqt        |       }|r|d   d   t        j                  u r|d= |r|d   d   t        j                  u r|d= |sy|dk(  r$|d   d   dk7  s|d   d   t        j                  ury|r$| j                  |      rdt	        |      z
  }| d| } | j                         } t        |       }|j                          d}d}d}d}d}d}	|D ]  }
|
d   }|
d   }|
d	   }|t        j                  t        j                  fv r6t        r|t        j                   u r|} n|t        j"                  t        j$                  t        j&                  fv r|dk7  r|r||
d
   d      dk7  rd} n|t        j"                  t        j$                  t        j&                  fv s|t        j                  u r|dk(  r|rd} n4|
d   d   }n$t	        |      dk(  r|dv r||	v r|dv r n||z   }n n|}|} |t	        |      }||d }||	v r||z   }|S )a  Return the rightmost root portion of an arbitrary Python command.

    Return only the root portion that can be eval()'d without side
    effects.  The command would normally terminate with a '(' or
    '.'. The terminator and anything after the terminator will be
    dropped.r^   Nr   r   rZ   r.   )z[]r]   z{}       r/   z[({])}z[({)rh   
startswithsysps2rP   rj   rtrimTerminus	getTokenstokenize	ENDMARKERNEWLINEOPendswithrstripreverser   ENCODINGNAMESTRINGNUMBER)r   r	   tokenssizelinestartprefix
laststringlastline
emptyTypestoken	tokentypetokenstringr   s                 r   r
   r
      s    mmD!"%G#''"#cgg,-(nnGGZ0GS7#fRjmx'9'99r
fRjmx'7'77r
r
1$r
1X[[(H g&&z23z?"%4.nnGwF
NNDEFJH#J '!H	AhQx++X-=-=>>9 1 11DII#$uQx{+s2II$); a"{x'@ #(> $v-  
O'P }D	<D}Kr*   c                    t        | t              r	 | j                  d      } t	        |       }g 	 t
        s'fd}t        j                  |j                  |       S t        j                  |j                        D ]  }j                  |        	 S # t        $ r Y ~w xY w# t        j                  $ r Y S w xY w)z(Return list of token tuples for command.zutf-8c                  (    j                  |        y r&   )append)argsr   s    r   eaterzgetTokens.<locals>.eaterM  s    d#r*   )rS   r   encodeUnicodeEncodeErrorr   r   r   tokenize_loopreadliner   
TokenError)r   fr   tr   s       @r   r   r   :  s     'L)	nnW-G 	A F$""1::u5 M &&qzz2 !a ! M- " 		$   	M	s(   B +B& 5B& 	B#"B#&B=<B=c                 v    |r6| j                  |      }t        |      dkD  r|j                  |dd       |z   } | S )z@Return command minus anything that follows the final terminator.r.   Nr   )rh   rP   ri   )r   r	   piecess      r   r   r   Y  s<    z*v;? oofSbk2Z?GNr*   c                    t        j                  |       rd}| |fS t        j                  |       r"	 | j                  d}nd}| j                  } | |fS t        j                  |       rt        |       }||} d}| |fS d}| |fS t        |       r	 | j                  j                  } d}| |fS d}| |fS # t
        $ r d}Y | |fS w xY w# t
        $ r d}Y | |fS w xY w)z8Return base object and dropSelf indicator for an object.r   r.   )
ra   rb   ismethod__self____func__r`   isclassgetConstructorrk   __call__)r   rs   constructors      r   r_   r_   a  s,   B =A 
		#	
	||# ,,C( =# 
	$S)"CH = H = 
#	,,''CH
 = ='  	H$ ='	  	H =		s#   B1 C 1CCCCc                     	 | j                   j                  S # t        $ r' | j                  D ]  }t	        |      }||c cY S  Y yw xY w)z@Return constructor for class object, or None if there isn't one.N)__init__r   r`   r   r   )r   rX   r   s      r   r   r     sT    #||$$$ #MM 	#D(.K&""	# #s    %AAAA)rZ   Nr.   r.   r.   )r.   r.   r.   )rZ   Nr&   )__doc__
__author__rm   r   ra   r   typeswxsixr   r   r   r   r   r5   r:   r~   r
   r   r   r_   r   r0   r*   r   <module>r      sp   6 8
 	 
    	 * *>?78( :;$%8t/7rGRWr>%N	r*   