Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/pyclbr.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZddlZddlZddlZddlmZmZmZddlm	Z	ddddgZ
iZddd	��YZddd
��YZ
dd�Zdd�Zdd
�Zd�Zd�Zd�Zedkr��ndS(s�Parse a Python module and describe its classes and methods.

Parse enough of a Python file to recognize imports and class and
method definitions, and to find out the superclasses of a class.

The interface consists of a single function:
        readmodule_ex(module [, path])
where module is the name of a Python module, and path is an optional
list of directories where the module is to be searched.  If present,
path is prepended to the system search path sys.path.  The return
value is a dictionary.  The keys of the dictionary are the names of
the classes defined in the module (including classes that are defined
via the from XXX import YYY construct).  The values are class
instances of the class Class defined here.  One special key/value pair
is present for packages: the key '__path__' has a list as its value
which contains the package search path.

A class is described by the class Class in this module.  Instances
of this class have the following instance variables:
        module -- the module name
        name -- the name of the class
        super -- a list of super classes (Class instances)
        methods -- a dictionary of methods
        file -- the file in which the class was defined
        lineno -- the line in the file on which the class statement occurred
The dictionary of methods uses the method names as keys and the line
numbers on which the method was defined as values.
If the name of a super class is not recognized, the corresponding
entry in the list of super classes is not a class instance but a
string giving the name of the super class.  Since import statements
are recognized and imported modules are scanned as well, this
shouldn't happen often.

A function is described by the class Function in this module.
Instances of this class have the following instance variables:
        module -- the module name
        name -- the name of the class
        file -- the file in which the class was defined
        lineno -- the line in the file on which the class statement occurred
i�N(tNAMEtDEDENTtOP(t
itemgettert
readmodulet
readmodule_extClasstFunctioncBs eZdZd�Zd�ZRS(s"Class to represent a Python class.cCsO||_||_|dkr'g}n||_i|_||_||_dS(N(tmoduletnametNonetsupertmethodstfiletlineno(tselfRR	RR
R((s/sys/lib/python2.7/pyclbr.pyt__init__7s						cCs||j|<dS(N(R(RR	R((s/sys/lib/python2.7/pyclbr.pyt
_addmethodAs(t__name__t
__module__t__doc__RR(((s/sys/lib/python2.7/pyclbr.pyR5s	
cBseZdZd�ZRS(s.Class to represent a top-level Python functioncCs(||_||_||_||_dS(N(RR	R
R(RRR	R
R((s/sys/lib/python2.7/pyclbr.pyRFs			(RRRR(((s/sys/lib/python2.7/pyclbr.pyRDscCsRi}xEt||pg�j�D](\}}t|t�r"|||<q"q"W|S(s}Backwards compatible interface.

    Call readmodule_ex() and then only keep Class objects from the
    resulting dictionary.(t_readmoduletitemst
isinstanceR(Rtpathtrestkeytvalue((s/sys/lib/python2.7/pyclbr.pyRLs
(cCst||pg�S(s�Read a module file and return a dictionary of classes.

    Search for MODULE in PATH and sys.path, read and parse the
    module and return a dictionary with one entry for each class
    found in the module.
    (R(RR((s/sys/lib/python2.7/pyclbr.pyRXsc&CsZ|dk	rd||f}n|}|tkr9t|Si}|tjkrh|dkrh|t|<|S|jd�}|dkr|| }||d}t|||�}|dk	r�d||f}nd|kr�dj|���nt||d|�Sd}	|dk	r=tj	||�\}	}
\}}}
n+tj	||tj
�\}	}
\}}}
|
tjkr�|
g|d<|
g|}tj	d|
g�\}	}
\}}}
n|t|<|
tjkr�	j
�|Sg}tj|	j�}y>x7|D]/\}}}}}|tkr\|\}}x�rX|dd|krX|d=q4Wq|d	kr2|\}}x%|r�|dd|kr�|d=qwW|j�dd
!\}}}|tkr�qn|r|dd}t|t�r|j||�qnt|||
|�||<|jd|f�q|dkr�|\}}x%|rq|dd|krq|d=qMW|j�dd
!\}}}|tkr�qn|j�dd
!\}}}d}|dkr]g}d}g}xqtrS|j�dd
!\}}}|dkr�|dkr�dj|�}||krE||}nj|jd�}t|�dkr�|d} |d}| tkr�t| }!||!kr�|!|}q�q�n|j|�g}n|dkr�|d7}q�d
kr|d8}|dkrPPqPq�dkr"|dkr"q�ttfkr�dkr�j|�q��|}nt||||
|�}|s�|||<n|j||f�q|dkr?|ddkr?t|�}"xj|"D]k\}#}$yU|dkr�|#|�n5yt|#||�Wntk
r,t|#g�nXWq�q�Xq�Wq|dkr|ddkrt|�\}#}|#s|dkr�qnt|�}yt|#||�}!Wn
qnXx{|D]p\}}%||!kr�!|||%p�<q�|dkr�x2|!D]'}|ddkr�|||<q�Wq�q�WqqWWnt k
rKnX|	j
�|S(s.Do the hard work for readmodule[_ex].

    If INPACKAGE is given, it must be the dotted name of the package in
    which we are searching for a submodule, and then PATH must be the
    package search path; otherwise, we are searching for a top-level
    module, and PATH is combined with sys.path.
    s%s.%st.iit__path__sNo package named {}Ri�tdefitclasst(t)t,ti�timporttfromt*t_N(R!R"(!R
t_modulestsystbuiltin_module_namestrfindRtImportErrortformattimptfind_moduleRt
PKG_DIRECTORYt	PY_SOURCEtclosettokenizetgenerate_tokenstreadlineRtnextRRRRRtappendtTruetjointsplittlenRt_getnamelistt_getnamet
StopIteration(&RRt	inpackaget
fullmoduletdicttitpackaget	submoduletparenttftfnamet_st_mttytstacktgt	tokentypettokentstartt_endt_lineRt
thisindentt	meth_namet	cur_classt
class_nametinherittnamestlevelRtntctmtdtmodulestmodt_mod2tn2((s/sys/lib/python2.7/pyclbr.pyRas	

'+

*

		




	

	


'

cCs�g}x�tr�t|�\}}|s+Pn|dkrLt|�\}}nd}|j||f�x,|dkr�d|kr�|j�d}qhW|dkr	Pq	q	W|S(NtasR"s
i(R8R=R
R7R6(RLRWR	RNtname2((s/sys/lib/python2.7/pyclbr.pyR<s	cCs�g}|j�dd!\}}|tkrA|dkrAd|fS|j|�xitr�|j�dd!\}}|dkr�Pn|j�dd!\}}|tkr�Pn|j|�qQWdj|�|fS(NiiR&R(R6RR
R7R8R9(RLtpartsRMRN((s/sys/lib/python2.7/pyclbr.pyR=+s

	c	Csbddl}tjd}|jj|�rw|jj|�g}|jj|�}|j�jd�r}|d }q}ng}t	||�}|j
�}|jd��x�|D]�}t|t
�r5dG|jG|jG|jGHt|jj�dtd��}xX|D](\}}|dkrd	G|G|GHqqWq�t|t�r�d
G|jG|jGHq�q�WdS(Ni�is.pyi�cSs%tt|dd�t|dd��S(NRi(tcmptgetattr(tatb((s/sys/lib/python2.7/pyclbr.pyt<lambda>KsRRRs  defR(tosR)targvRtexiststdirnametbasenametlowertendswithRtvaluestsortRRR	RRtsortedRt	iteritemsRR(	RiR^RRAtobjstobjRR	R((s/sys/lib/python2.7/pyclbr.pyt_main>s(

!t__main__(((RR)R.R3RNRRRtoperatorRt__all__R(RRR
RRRR<R=RvR(((s/sys/lib/python2.7/pyclbr.pyt<module>(s"	�		

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].