e fc@s1dZdgZdZdZdZddlZddlZddlZddl Zddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZd d Zd d ZddZddZddZ ddZ!ddZ"ej#dej$Z%ddZ&ddZ'ddZ(dd Z)d!d"Z*ddd#d$Z+d%d&Z,d'd(Z-d)d*Z.id+d,Z/Gd-d.d.e0Z1d/d0Z2did1d2Z3Gd3d4d4Z4Gd5d6d6eZ5Gd7d8d8e4Z6Gd9d:d:eZ7Gd;d<d<e4Z8Gd=d>d>e8Z9d?d@a:dAdBZ;dCdDZ<dEdFZ=dGdHZ>dIdJZ?dKdLZ@dMdNZAdOdPZBddQdRZCe8ZDe9ZEe6ZFddSdTZGdUdddVdWZHdUdddXdYZIddZd[ZJd\dd]d^ZKGd_d`d`ZLeLZMGdadbdbZNdcddZOdedfZPdgdhdiZQddjdkdldmZRdndoZSdpdqZTeUdrkr-eTndS)saGenerate Python documentation in HTML or text for interactive use. At the Python interactive prompt, calling help(thing) on a Python object documents the object, and calling help() starts up an interactive help session. Or, at the shell command line outside of Python: Run "pydoc " to show documentation on something. may be the name of a function, module, package, or a dotted reference to a class or function within a module or module in a package. If the argument contains a path segment delimiter (e.g. slash on Unix, backslash on Windows) it is treated as the path to a Python source file. Run "pydoc -k " to search for a keyword in the synopsis lines of all available modules. Run "pydoc -p " to start an HTTP server on the given port on the local machine. Port number 0 can be used to get an arbitrary unused port. Run "pydoc -b" to start an HTTP server on an arbitrary unused port and open a Web browser to interactively browse documentation. The -p option can be used with the -b option to explicitly specify the server port. Run "pydoc -w " to write out the HTML documentation for a module to a file named ".html". Module docs for core modules are assumed to be in http://docs.python.org/X.Y/library/ This can be overridden by setting the PYTHONDOCS environment variable to a different URL or to a local directory containing the Library Reference Manual pages. helpzKa-Ping Yee z26 February 2001zGuido van Rossum, for an excellent programming language. Tommy Burnette, the original creator of manpy. Paul Prescod, for all his work on onlinehelp. Richard Chamberlain, for the first implementation of textdoc. N)deque)Repr)format_exception_onlycCsg}g}xvtjD]k}tjj|p.d}tjj|}||krtjj|r|j||j|qqW|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr*/opt/alt/python34/lib64/python3.4/pydoc.pypathdirsLs rcCsCtj|ptj|}|r?tjdd|jpBdS)z-Get the doc string or comments for an object.z^ * )inspectgetdocZ getcommentsresubrstrip)objectresultrrrrXsrcCs|jjd}t|dkr5|ddfSt|dkry|dj ry|ddj|ddfSddj|fS)z>Split a doc string into a synopsis line (if any) and the rest. rrN)stripsplitlenrjoin)doclinesrrrsplitdoc]s #!r$cCs0|j}|j|kr,|jd|}n|S)z@Get a class name and qualify it with a module name if necessary.r)__name__ __module__)rmodnamenamerrr classnamefs r)cCsYtj|pWtj|pWtj|pWtj|pWtj|pWtj| S)z>Check if an object is of a type that probably means it's data.)rismoduleisclass isroutineZisframeZ istracebackZiscode)rrrrisdatamsr-cGsAx:|r<|dj|j|d}|dd}qW|S)z/Do a series of global replacements on a string.rrrN)r!r)textZpairsrrrreplacess  r/cCsnt||krjtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrNz...)r max)r.maxlenZpreZpostrrrcramzs *r3z at 0x[0-9a-f]{6,16}(>+)$cCstjd|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidr)r.rrrstripidsr5cCs:tj|p9tj|p9tj|p9tj|S)N)r isfunctionismethod isbuiltinZismethoddescriptor)objrrr_is_some_methodsr:cCsRtj|rdStj|rNt|dd}tj|pL|dk SdS)zo Returns True if fn is a bound method, regardless of whether fn was implemented in Python or in C. T__self__NF)rr7r8getattrr*)fnselfrrr_is_bound_methods r?cCsi}x*tj|tD]\}}d|| __author__ __package____file____doc__ __cached__ __credits__ __loader__ __module__ __qualname____date____path__ __slots__ __version__ __builtins____spec____name__) startswithendswithhasattr)r(allr9rrr visiblenames   rucCsag}xTtj|D]C\}}}}tj|r@d}n|j||||fqW|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.zdata descriptor)rclassify_class_attrsisdatadescriptorr )rresultsr(kindclsrHrrrrvs " rvcCsStjj|rOx:dD]/}tjjtjj|d|rdSqWndS)z3Guess whether a path refers to a package directory..py.pyc.pyo__init__TF)r{r|r})r rr isfiler!)rextrrr ispackages  % rcCs|j}x=|dddks2|j rK|j}|sPqqW|j}|dddkr|dd}n|dddkr|dd}|d ddkr|dd }nx&|js|j}|sPqqW|jddj}nd}|S) Nr#zr"""r0z"""\rr)readlinerr)filelinerrrrsource_synopsiss& &   rc Cstj|j}|j|d\}}|dksB||kr|jttjjrltjj }n0|jttjj rtjj }nd}|dkryt j |}Wntk rdSYnX|t|}WdQXn|d|}tjjd|d|}tjj|} y| j} Wn dSYnXtjd=| jrq| jjdnd}||f||rexc_inforrrr~s zErrorDuringImport.__init__cCs#|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr%rrH)r>rrrr__str__s zErrorDuringImport.__str__N)r%r&r[rUr~rrrrrrs  rc Cstjj}t|d"}||jt|k}WdQXtjj|}tjj |\}}|rtj j ||}ntj j ||}tjj ||d|}tj j|} y| jSWnt|tjYnXdS)zGs zsafeimport..Nrr)rrbuiltin_module_names __import__rrrV SyntaxErrorr ImportErrorr(rr<AttributeError) r forceloadrZsubsrGrrrHrinfopartr)rr safeimport3s.   rc@szeZdZejjddejddZdddZ dddZ e Z Z Z ZZZd d ZdS) Doc PYTHONDOCSz$http://docs.python.org/%d.%d/libraryNrc Gs||f|}tj|r,|j|Stj|rH|j|SyXtj|rg|j|Stj|r|j|Stj|r|j |SWnt k rYnXt |t r|j |S|j|S)z%Generate documentation for an object.)risgetsetdescriptordocdataismemberdescriptorr* docmoduler+docclassr, docroutiner isinstanceproperty docpropertydocother)r>rr(argsrrrdocumentis"      z Doc.documentcGs9d|odt|t|jf}t|dS)z+Raise an exception for unimplemented types.z.don't know how to document object%s of type %s N)reprtyper% TypeError)r>rr(rmessagerrrfail{s&zDoc.failcCs*ytj|}Wntk r-d}YnXtjjd|j}tjjt j ddt j dd}t |t tr |jdks|j|r |jtjj|d r |jdkr |jdrd|jd|jf}q&tjj||jd}nd}|S)z*Return the location of module docs or Nonez (built-in)rlibz python%d.%dNrerrno exceptionsgcimpmarshalposixsignalr_thread zipimportz site-packages xml.etreetest.pydoc_modzhttp://z%s/%s/z.html) zerrnoz exceptionszgcrzmarshalzposixzsignalzsysz_threadr)rr)r getabsfilerr environrrrr!rbase_exec_prefix version_inforrr%rqr)r>rrdoclocZbasedirrrr getdoclocs&   z Doc.getdocloc)r%r&r[r rrrrrrrrrrrrrrrrrrrcs  rc@sjeZdZdZddZddZddZdd Zd d ZeZ d d Z eZ dS)HTMLReprzBClass for safely making an HTML representation of a Python object.cCs:tj|d|_|_d|_d|_|_dS)N d)rr~maxlistmaxtuplemaxdict maxstringmaxother)r>rrrr~s  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)r/)r>r.rrrescapeszHTMLRepr.escapecCstj||S)N)rr)r>rrrrrsz HTMLRepr.reprcCstt|dr_ddjt|jj}t||r_t||||Sn|jttt ||j S)Nr%repr_r_) rsrr!r%rr<rr3r5rr)r>rNlevel methodnamerrrrepr1s "zHTMLRepr.repr1cCst||j}t|}d|krcdt|ddkrcd|d|j||dStjdd|j|S)Nrz\\rrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r3rrr/rrr)r>rNrtesttestreprrrr repr_strings $! zHTMLRepr.repr_stringc CsOy)|jttt||jSWn|jd|jjSYnXdS)Nz <%s instance>)rr3r5rr __class__r%)r>rNrrrr repr_instances)zHTMLRepr.repr_instanceN) r%r&r[rUr~rrrrrepr_strrZ repr_unicoderrrrrs       rc@seZdZdZeZejZejZddZdddZ dddd d d Z d d Z ddZ dddZ ddZddZddZddZddZddZdiiidd Zdd!d"Zddd#d$Zddiid%d&Zd'd(Zddiiidd)d*Zd+d,Zdddd-d.Zddd/d0Zdddd1d2Zdd3d4ZdS)5HTMLDocz'Formatter class for HTML documentation.cCsd||fS)zFormat an HTML page.z Python: %s %s r)r>titlecontentsrrrpagesz HTMLDoc.pagercCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
z r)r>rfgcolbgcolZextrasrrrheadings zHTMLDoc.headingNz c Csz|dkr!dd|d}nd|||f} |rW| d||||f} n| d|||f} | d|S) z Format a section with a heading.Nzz zz

zR z( z'
 
%s
%s %s
%s
%s%s%s
r) r>rrrrwidthZpreludeZ marginaliaZgaprrrrsections zHTMLDoc.sectioncGsd|}|j||S)z$Format a section with a big heading.z%s)r)r>rrrrr bigsections zHTMLDoc.bigsectionc Cs7|j|j}t|dddddddd S)z!Format literal preformatted text.z z rz rz
)r expandtabsr/)r>r.rrr preformatszHTMLDoc.preformatrcCsd}t||d|}xt|D]u}|dd|}xPt|||||D]3}|t|kr_||||d}q_q_W|d}q+Wd|S)z0Format a list of items into a multi-column list.rrzrz
zz7%s
)r range)r>listformatZcolsrrowscolirrr multicolumn s"zHTMLDoc.multicolumncCsd|S)Nz%sr)r>r.rrrgreysz HTMLDoc.greycGs3x,|D]$}||krd|||fSqW|S)z:Make a link for an identifier, given name-to-URL mappings.z%sr)r>r(Zdictsdictrrrnamelinks  zHTMLDoc.namelinkcCsm|jtjj|j}}t||r`t|||kr`d|j|t||fSt||S)zMake a link for a class.z%s)r%rrrr&rsr<r))r>rr'r(rrrr classlinks $zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.z%s)r%)r>rrrr modulelink&szHTMLDoc.modulelinkcCso|\}}}}|r%|j|S|r>d||f}n d|}|r[d|}n|}d||fS)z;Make a link for a module or package to display in an index.z %s.%s.htmlz%s.htmlz"%s (package)z%s)r)r>Z modpkginfor(rrshadowedurlr.rrr modpkglink*s   zHTMLDoc.modpkglinkcCsd||fS)zMake a link to source file.z%sr)r>rrrrrfilelink9szHTMLDoc.filelinkcCs|p |j}g}d}tjd}x|j||} | sIPn| j\} } |j|||| | j\} } }}}}| r|| jdd}|jd||fn|rdt|}|jd||| fn|r:dt|}|jd||| fn|r|| | dd krz|jd |j ||q|jd |nU|| | dd kr|j|j ||||n|j|j ||| }q-W|j|||d d j |S)zMark up some plain text, given a context of symbols to look for. Each context dictionary maps object names to anchor names.rzD\b((http|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?(\w+))"z"z%sz'http://www.rfc-editor.org/rfc/rfc%d.txtz(http://www.python.org/dev/peps/pep-%04d/r(zself.zself.%sNr) rrcompilesearchspanr groupsr/intrr!)r>r.rfuncsclassesrFrxherepatternmatchstartendrtschemeZrfcZpepZselfdotr(rrrrmarkup=s<   " zHTMLDoc.markupc Cs d}x|D]}t|tfkr|\}}|d}||j||}|r||fkrg}x'|D]} |j|j| |qyW|ddj|d}n|d}q t|tgkr |d|j|||}q q Wd|S) zAProduce HTML for a class tree as given by inspect.getclasstree().rz"

rz, )z
z
%s
z
%s
)rrr r! formattree) r>treer'parentrentrycbasesparentsrIrrrr,hs       zHTMLDoc.formattreec#s|j}y |j}Wntk r0d}YnX|jd}g}xPtt|dD]8}|jddj|d|d||fq]Wdj||d.d} d| } y7tj |} t j j | } j | | } Wntk rd} YnXg}t|drt|j}|ddd/kr{|d0dd kr{|dd1j}n|jd j|nt|d r|jjt|jn|r| d dj|} nj|}|dk rdt}nd}j| ddd| |}tj|tj}gi}}xtj|tjD]t\}}|dk stj|p||krrt|||r|j||fd|||<||%sz)%sz (built-in)r] $z Revision: z version %srTz (%s)z, z-
Module Referencerz#ffffffz#7799eezindex
rz.html#z#-z %sz

%s

rZrzPackage Contentsz#aa55cccsj|dS)Nr)r)t)r>rrsz#HTMLDoc.docmodule..ModulescSsg|]\}}|qSrr)rrGrHrrrrs z%HTMLDoc.docmodule..ZClassesz#ee77aarZ Functionsz#eeaa77ZDataz#55aa55z
rPZAuthorrSZCreditsrz $Revision: rr)6r%__all__rrr r r r!rrurllibparseZquoterrrsstrr]rrrTrlocalsrr@r*r+ getmodulerurAr&rrrr<r,r8r6r-r*rr pkgutil iter_modulesrZsortrrrr, getclasstreerrPrS)#r>rr(modignoredrtpartsZlinksrZ linkednameheadrrrrversionrrrr#ZcdictrGrHrIr'rr"Zfdictdatar"modpkgsimporterispkgr classlistr)r>rr{s    -   ,"   "  ! + " $!"   !& &    zHTMLDoc.docmodulecsj}|p|}j}g} | jGfddd} | ttj} t| dkrjdx+| D]#} dj| j qWdnfdd} fd d }fd d }fd dt D}ix|D]w\}}}}d|d||<}yt |}Wnt k rYnXy||.HorizontalRulecSs d|_dS)Nr)needone)r>rrrr~sz1HTMLDoc.docclass..HorizontalRule.__init__cs#|jrdnd|_dS)Nz
r)rL)r>)pushrrmaybes  z.HTMLDoc.docclass..HorizontalRule.maybeN)r%r&r[r~rNr)rMrrHorizontalRules  rOrz&
Method resolution order:
z
%s
z
cst||\}}|rj|x|D]\}}}}yt|}Wn+tk rj||Yn&Xj||dq6Wn|S)Nr)rOrNr< Exception_docdescriptorr)msgattrsrKokr(ryhomeclsrH)r#r"hrmdictrBrrMr>rrspills   zHTMLDoc.docclass..spillcslt||\}}|rhj|x6|D]+\}}}}j||q6Wn|S)N)rOrNrQ)rRrSrKrTr(ryrUrH)rVrBrMr>rrspilldescriptors$s   z*HTMLDoc.docclass..spilldescriptorsc st||\}}|r j|x|D]\}}}}jt||}t|stj|rt|dd} nd} | dkrd|nBjt|j } d| } d|| fdq6Wn|S)NrUz
%s
z
%sz
%s%s
r) rOrNrr<callablerrwr*rr ) rRrSrKrTr(ryrUrHrIr")r#r"rVrWrBrrMr>rr spilldata-s"    z#HTMLDoc.docclass..spilldatacs@g|]6\}}}}t|dr||||fqS)r9)ru)rr(ryrzrH)rrrrBs z$HTMLDoc.docclass..r-rcs|dkS)Nrr)r5) thisclassrrr6[sz"HTMLDoc.docclass..z defined herezinherited from %sz:
rGcSs|dS)Nrr)r5rrrr6hsz Methods %scSs|ddkS)Nrmethodr)r5rrrr6lszClass methods %scSs|ddkS)Nrz class methodr)r5rrrr6nszStatic methods %scSs|ddkS)Nrz static methodr)r5rrrr6pszData descriptors %scSs|ddkS)Nrzdata descriptorr)r5rrrr6rszData and other attributes %scSs|ddkS)NrrGr)r5rrrr6tsrz*class %sz/%s = class %sz(%s)z, z%s
 
z#000000z#ffc8d8r0)r%rAr rrgetmror rNrr&rvr<rPrpopleftrObuiltinsrr@r!r*rr r)r>rr(rBr"r#rCrealnamer1rrOmrorIrXrYr[rSrGryrUrHanchor inheritedtagrr2r"r) r#r"rVrWrBrrMr>r]rrs         ' '    !              $zHTMLDoc.docclasscCs|jd|j|S)z)Format an argument default value as text.=)rr)r>rrrr formatvalueszHTMLDoc.formatvaluecCsf|j}|p|}|r$|jp'dd|} d} d} t|r|jj} |r| |k rd|j| |} qq|jdk rd|j|jj|} qd|j| |} n||krd| |f} ne|r6||jkr6|j||kr6d |jd||f}d } n|}d | ||f} d}tj|rytj|}Wnt t fk rd}YnX|rt |}|d krd |} |d d}qqn|sd}n| |j || o|j d| }| r d|S|jt||j|||}|oQd|}d||fSdS)z;Produce HTML documentation for a function or method object.rr\rz from Nz method of %s instancez unbound %s methodz$%sz%srz)%s = %szz$%s lambda z(...)z'%sz
%s
z
%s
z
%s
%s
r)r%r?r;rr__dict__rr, signature ValueErrorrr;rrr*rr )r>rr(rBr"r#rFrErbrdnoteskipdocsimclassrZreallinkargspecrjdeclr"rrrrsZ             zHTMLDoc.docroutinecCsxg}|j}|r&|d|n|jdk ra|jt||j}|d|n|ddj|S)Nz!
%s
z
%s
z
r)r rUr*rr r!)r>r(rHrBrxrMr"rrrrQs  zHTMLDoc._docdescriptorcCs|j|||S)z*Produce html documentation for a property.)rQ)r>rr(rBrErrrrszHTMLDoc.docpropertycGs'|rd|pd}||j|S)z-Produce HTML documentation for a data object.z%s = r)r)r>rr(rBrCZlhsrrrrszHTMLDoc.docothercCs|j|||S)z1Produce html documentation for a data descriptor.)rQ)r>rr(rBrErrrrszHTMLDoc.docdatacCsg}|dkri}nxktj|gD]W\}}}tdd|Dr\q.n|j|d|||kfd||sz HTMLDoc.index..rrz#ffffffz#ee77aa)r>r?anyr r@rrr)r>rrrHrIr(rJrrrrindexs " z HTMLDoc.index)r%r&r[rUr_repr_instancerrrrrrr rrrrrrrr*r,rrrhrrQrrrrurrrrrs:              +y ; rc@sLeZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs:tj|d|_|_d|_d|_|_dS)Nrrr)rr~rrrrr)r>rrrr~s  zTextRepr.__init__cCs{tt|dr_ddjt|jj}t||r_t||||Snttt||j S)Nr%rr_) rsrr!r%rr<r3r5rr)r>rNrrrrrrs "zTextRepr.repr1cCs^t||j}t|}d|krZdt|ddkrZd|d||dS|S)Nrz\\rrr)r3rrr/)r>rNrrrrrrrs  $zTextRepr.repr_stringc Cs=y ttt||jSWnd|jjSYnXdS)Nz <%s instance>)r3r5rrrr%)r>rNrrrrrs zTextRepr.repr_instanceN) r%r&r[rUr~rrrrrrrrrws    rwc@seZdZdZeZejZddZdddZddZ d d d d Z d d d dZ d d ddZ ddZ d d d ddZddZd d d ddZd d d ddZd d d d d ddZd S)TextDocz'Formatter class for text documentation.cCsdjdd|DS)z(Format a string in bold by overstriking.rcss|]}|d|VqdS)Nr)rrrrrrrsszTextDoc.bold..)r!)r>r.rrrboldsz TextDoc.boldz csV|s dSfdd|jdD}|rI|dj|d.rrrr)rrr!)r>r.r{r#r)r{rindent!s "zTextDoc.indentcCs.|j|j}|j|d|dS)z&Format a section with a given heading.rz )r|rrz)r>rrZclean_contentsrrrr(szTextDoc.sectionNrc sd}x|D]}t|tfkr|\}}||t|}|r||fkrfdd|D} |ddj| }n|d}q t|tgkr ||j|||d}q q W|S)zBRender in text a class tree as returned by inspect.getclasstree().rc3s|]}t|VqdS)N)r))rr0)r'rrrs7sz%TextDoc.formattree..z(%s)z, rz )rr)r!r,) r>r-r'r.r{rr/r0r1r2r)r'rr,/s    zTextDoc.formattreec Cs|j}tt|\}}|jd||o:d|}t|dd}|j|}|dk r||jd|d}n|r||jd|}ng} xutj|tjD]^\} } |dk stj | p||krt | ||r$| j | | fq$qqWg} x~tj|tj D]g\} } |dk stj | stj | |krDt | ||r| j | | fqqDqDWg} xHtj|tD]4\} } t | ||r| j | | fqqWg}t}t|drxWtj|jD]C\}}}|j||rg|j |d q1|j |q1W|j||jd d j|}ng}xUtj|tjD]>\} } | jj|d r| |kr|j | qqW|r4|j||jd d j|}n| rdd| D}|jtj|d|g}x0| D](\} } |j |j| | |quW||jdd j|}n| r$g}x0| D](\} } |j |j| | |qW||jdd j|}n| rg}x6| D].\} } |j |j| | |ddq7W||jdd j|}nt|drt|j}|ddd#kr|d$ddkr|dd%j}n||jd|}nt|dr8||jdt|j }nt|dri||jdt|j!}nt|dr||jd t|j"}nytj#|}Wnt$k rd!}YnX||jd"|}|S)&z5Produce text documentation for a given module object.NAMEz - r8NzMODULE REFERENCEa. The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. Z DESCRIPTIONrZz (package)zPACKAGE CONTENTSrrZ SUBMODULEScSsg|]\}}|qSrr)rrGrHrrrrs z%TextDoc.docmodule..rCLASSES FUNCTIONSr2FZDATAr]r3r4z Revision: VERSIONrTZDATErPZAUTHORrSZCREDITSz (built-in)ZFILEz $Revision: rr)%r%r$rrr<rrr@r+r=rur r,r8r-setrsr>r?rZaddr@r!r*rqr,rArrr;r]rrTrPrSrr)r>rr(rBZsynopdescrrtrr#rGrHr"rGrHZ modpkgs_namesrIr'rJZ submodulesrKrrFrrrrr?s   " " $ "   ""   " "&","""  zTextDoc.docmodulecs3j}|p|}j}jdd}||krRdj|}nj|d|}|rt||} |ddj| }nt} | r| dgpg} | jtt j } t | dkr)d x"| D]} d || qWd nGfd d d }|fdd}fdd}fdd}fddt D}x0|r| r| j n|ddt|fdd\}}tjkr)|}qn+kr>d}ndtj}|j|d||dd}|d||dd}|d||d d}|d!||d"d}|d#||d$d}|}qWdj| } | s|dS|dj| jd%dS)&z4Produce text documentation for a given class object.cSs t||S)N)r))r0rrrrmakenamesz"TextDoc.docclass..makenamezclass z = class z(%s)z, rrzMethod resolution order:z rcs.eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dS)Nr)rL)r>rrrr~sz1TextDoc.docclass..HorizontalRule.__init__cs'|jrddnd|_dS)Nr\rr)rL)r>)rMrrrNs z.TextDoc.docclass..HorizontalRule.maybeN)r%r&r[r~rNr)rMrrrOs  rOcst||\}}|rj|xz|D]o\}}}}yt|}Wn+tk rj||Yq6Xj||q6Wn|S)N)rOrNr<rPrQr)rRrSrKrTr(ryrUrH)rVrBrrMr>rrrXs    zTextDoc.docclass..spillcslt||\}}|rhj|x6|D]+\}}}}j||q6Wn|S)N)rOrNrQ)rRrSrKrTr(ryrUrH)rVrBrMr>rrrYs   z*TextDoc.docclass..spilldescriptorsc st||\}}|rj|x|D]\}}}}t|sctj|rrt|}nd}yt|} Wntk r|j|} YnXj | |ddd|dq6Wn|S)Nr2rr"r) rOrNrZrrwrr<rrir) rRrSrKrTr(ryrUrHr"r9)rVrBrrMr>rrr[s   !z#TextDoc.docclass..spilldatacs@g|]6\}}}}t|dr||||fqS)r9)ru)rr(ryrzrH)rrrrs z$TextDoc.docclass..rcs|dkS)Nrr)r5)r]rrr6sz"TextDoc.docclass..z defined herezinherited from %sz Methods %s: cSs|ddkS)Nrr^r)r5rrrr6szClass methods %s: cSs|ddkS)Nrz class methodr)r5rrrr6szStatic methods %s: cSs|ddkS)Nrz static methodr)r5rrrr6szData descriptors %s: cSs|ddkS)Nrzdata descriptorr)r5rrrr6szData and other attributes %s: cSs|ddkS)NrrGr)r5rrrr6sz | )r%rAr&rzmapr!rr rrr_r rvr`rOrarr)r@r|r)r>rr(rBrCrbr1rrr2r"rrcrIrOrXrYr[rSrerfr)rVrBrrMr>r]rrsl            !           zTextDoc.docclasscCsd|j|S)z)Format an argument default value as text.rg)r)r>rrrrrh!szTextDoc.formatvaluec Cs|j}|p|}d}d}t|r|jj}|rd||k rdt||}qq|jdk rdt|jj|}qdt||}n||kr|j|} nH|r||jkr|j||krd}n|j|d|} d} tj|rytj |} Wnt t fk rSd} YnX| rt | } |d kr|j|d } | dd } qqn| sd } n| | |} |r| d St |pd} | d | o|j| jd SdS)z;Produce text documentation for a function or method object.rrz from Nz method of %s instancez unbound %s methodrz = zz lambda z(...)rr)r%r?r;rr)rzrirr,rjrkrr;rr|r)r>rr(rBrErbrlrmrnrrorjrpr"rrrr%sJ           zTextDoc.docroutinecCszg}|j}|r5||j||dnt|pDd}|rm||j||dndj|S)Nrr)r rzrr|r!)r>r(rHrBrxrMr"rrrrQWs   zTextDoc._docdescriptorcCs|j|||S)z*Produce text documentation for a property.)rQ)r>rr(rBrErrrrdszTextDoc.docpropertycCs|j|||S)z1Produce text documentation for a data descriptor.)rQ)r>rr(rBrErrrrhszTextDoc.docdatac Cs|j|}|re|r%|dp(d|}|t|} | dkre|d| d}qen|r~|j|dpd|}|dk r|d|jt|7}n|S)z-Produce text documentation for a data object.z = rrNz...r)rr rzr|r;) r>rr(rBr.r2r"rrZchoprrrrls #  zTextDoc.docother)r%r&r[rUrwrvrrzr|rr,rrrhrrQrrrrrrrrxs     e} 2 rxc@s"eZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|S)Nr)r>r.rrrrzzsz_PlainTextDoc.boldN)r%r&r[rUrzrrrrrxs rcCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpager)r.rrrrs rc CsttjdstSttjds,tStjj sLtjj rPtSdtjkrtjdkrxddStjj ddkrd dSd dSntjj ddkrtStjdkrd dSttd r tj d dkr ddSddl }|j \}}tj |z:ttd rjtj d|dkrjddStSWdtj|XdS)z2Decide what method to use for paging through text.isattyPAGERwin32cSstt|tjdS)Nr) tempfilepagerplainr r)r.rrrr6szgetpager..ZTERMdumbemacscSstt|tjdS)Nr) pipepagerrr r)r.rrrr6scSst|tjdS)Nr)rr r)r.rrrr6scSstt|dS)Nzmore <)rr)r.rrrr6ssystemz(less) 2>/dev/nullrcSs t|dS)NZless)r)r.rrrr6sNz more "%s"cSs t|dS)NZmore)r)r.rrrr6s)rr)rr)rsrstdin plainpagerstdoutrr rplatformrrtempfileZmkstempclosettypagerunlink)rfdrrrrrs4     $   ( rcCstjdd|S)z%Remove boldface formatting from text.z.r)rr)r.rrrrsrcCsddl}|j|ddd|j}yKtj|jdd-}y|j|Wntk rmYnXWdQXWntk rYnXx(y|j PWqtk rYqXqWdS)z3Page through text by feeding it to another program.rNshellTrerrorsbackslashreplace) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)r.cmdrprocpiperrrrs      rcCsuddl}|j}t|ddd}|j|WdQXztj|d|dWdtj|XdS)z.cSs!tjjddddS)Nrr)rrrrrrrr6sZLINESrz -- more --qQz  bB)rr)rr)rrr)rrrttyrrfilenoZ tcgetattrZ setcbreakrrrUnsupportedOperationr!r rrrkrrr!flushZ tcsetattrZ TCSAFLUSH) r.r#rroldZgetcharhrZincr0rrrrsL      '       /rcCs tjjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrr)r.rrrrsrcCs'tj|rT|jtjkr,d|jSt|drFd|jSd|jSntj|rnd|jStj|rd|jj |jj|jfStj |rd|jj |jj|jfStj |rd|jStj |rd |jStj |rd |jSt|jS) z/Produce a short description of the given thing.zbuilt-in module rZzpackage zmodule zbuilt-in function zgetset descriptor %s.%s.%szmember descriptor %s.%s.%szclass z function zmethod )rr*r%rrrsr8r __objclass__r&rr+r6r7r)thingrrrdescribes.        rc Csdd|jdD}d\}}xW|t|krtdj|d|d|}|r}||d}}q+Pq+W|r|}nt}xD||dD]2}yt||}Wqtk rdSYqXqW|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|]}|r|qSrr)rrrrrrs zlocate..rNrr)Nr)rr rr!rar<r)rrrDrnZ nextmodulerrrrrlocates  &   rcCs|t|trGt||}|dkr=td|n||fSt|dd}|t|trq|ndfSdS)zDGiven an object or a path to an object, get the object and its name.Nz$no Python documentation found for %rr%)rr;rrr<)rrrr(rrrresolve5s  rz Python Library Documentation: %scCs0|dkrt}nt||\}}t|}tj|}|r{d|kr{|d|d|jd7}n&|r||k r|d|j7}ntj|ptj|ptj |ptj |ptj |pt |t st|}|d7}n||d|j||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module z objectz )r.rrrr=rfindr%r*r+r,rrrrrr)rrrZrendererrr(rrrrr render_doc@s$   $  rcCsyE|dkr(tt|||n|jt|||tWn5ttfk r|}zt|WYdd}~XnXdS)zCDisplay text documentation, given an object or a path to an object.N)rrr plaintextrrprint)rrroutputrHrrrr"Ys   r"cCsy~t||\}}tjt|tj||}t|dddd}|j||jtd|dWn5t t fk r}zt|WYdd}~XnXdS)z walk_packagesr)rpkgpathdonerIr'rJrrr writedocsps  %rc@seZdZi!dd6dd6dd6dd6dd6d5d 6d6d 6d7d 6d8d6d9d6d:d6dd6d;d6dd6dd6d<d6dd6d=d6d>d6d?d6d@d!6d#d$6dAd%6dBd'6dd)6dd*6dCd+6dDd,6dEd.6dFd6dGd/6dHd6dId26ZidJd;6dKdP6dLd#6dMdQ6dNd^6dOd_6dPdb6ZidcdB6ddd?6dedf6dgdh6didj6dkdl6dmdn6d;do6dpdq6drds6dtdu6dvdw6dvdx6dydz6dyd{6ZxdejD]V\ZZxGeD]?Z ej e eZ ee kre d|eZ ne ee >r|^~rr<=>===!=<> OPERATORSZUNARY+=-=*=/=%=&=|=^=<<=>>=**=//=AUGMENTEDASSIGNMENTZBITWISEjJZCOMPLEXzOPERATORS FORMATTINGZPOWERzTUPLES LISTS FUNCTIONS,z ATTRIBUTES FLOAT MODULES OBJECTSrELLIPSISz...zSLICINGS DICTIONARYLITERALS:z def class@rZ PRIVATENAMESr_zPRIVATENAMES SPECIALMETHODSr^Z BACKQUOTES`zTUPLES FUNCTIONS CALLSrr+zLISTS SUBSCRIPTS SLICINGS[]rtypesRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspectTYPESstrings4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPESstring-methodsSTRINGS FORMATTINGZ STRINGMETHODS formatstringsZ FORMATTING:encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPESUNICODEnumbersINTEGER FLOAT COMPLEX TYPESZNUMBERSintegers int rangeZINTEGERfloating float mathZFLOAT imaginary complex cmathtypesseq$STRINGMETHODS FORMATTING range LISTSZ SEQUENCESZ DICTIONARIESZMAPPINGStypesfunctions def TYPES typesmethodsclass def CLASSES TYPESZMETHODSbltin-code-objectscompile FUNCTIONS TYPESZ CODEOBJECTSbltin-type-objects types TYPESZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSbltin-null-objectZNONEbltin-ellipsis-objectSLICINGS specialattrsZSPECIALATTRIBUTES!class SPECIALMETHODS PRIVATENAMESr~ typesmodulesZPACKAGESoperator-summarylambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIES EXPRESSIONSZ PRECEDENCEobjectsZOBJECTS specialnamesbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSESZSPECIALMETHODS customizationhash repr str SPECIALMETHODSattribute-accessATTRIBUTES SPECIALMETHODSZATTRIBUTEMETHODScallable-typesCALLS SPECIALMETHODSZCALLABLEMETHODSsequence-types(SEQUENCES SEQUENCEMETHODS SPECIALMETHODSMAPPINGS SPECIALMETHODSZMAPPINGMETHODS numeric-types*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS NUMBERMETHODS execmodel%NAMESPACES DYNAMICFEATURES EXCEPTIONSZ EXECUTIONnaming3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURESZ NAMESPACESdynamic-featuresZDYNAMICFEATURESZSCOPINGZFRAMESrtry except finally raise conversionsZ CONVERSIONS identifierskeywords SPECIALIDENTIFIERSZ IDENTIFIERS id-classesZSPECIALIDENTIFIERSatom-identifiers atom-literals=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALSZLITERALSZTUPLES exprlistsTUPLES LITERALSZ TUPLELITERALStypesseq-mutable LISTLITERALSZLISTSlistsLISTS LITERALS typesmappingDICTIONARYLITERALSrDICTIONARIES LITERALSattribute-references(getattr hasattr setattr ATTRIBUTEMETHODSZ ATTRIBUTES subscriptionsZ SUBSCRIPTSslicingscallsZCALLSpowerunarybinaryZBINARYshiftingZSHIFTINGbitwise comparisonsEXPRESSIONS BASICMETHODSbooleansEXPRESSIONS TRUTHVALUEZ ASSERTION assignmentZ ASSIGNMENT augassignZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALcompoundfor while break continueZLOOPINGtruth if while and or not BASICMETHODSdebuggerpdbZ DEBUGGINGcontext-managersZCONTEXTMANAGERSNcCs||_||_dS)N)_input_output)r>inputrrrrr~#s zHelper.__init__cCs|jptjS)N)rrr)r>rrrr6'szHelper.cCs|jptjS)N)rrr)r>rrrr6(scCs)tjdddkr%|dSdS)Nrr0?rz)rstack)r>rrr__repr__*szHelper.__repr__cCsG||jk r|j|n$|j|j|jjddS)Na You are now leaving help and returning to the Python interpreter. If you want to ask for help on a particular object directly from the interpreter, you can type "help(object)". Executing "help('string')" has the same effect as typing a particular string at the help> prompt. )_GoInteractiverintrointeractrr)r>requestrrr__call__1s    zHelper.__call__cCs|jjdx~y|jd}|s/PnWnttfk rKPYnXt|ddddj}|jdkrPn|j|qWdS) Nrzhelp> rrrrquit)rzquit) rrgetlinerEOFErrorr/rlowerr)r>rrrrr>szHelper.interactcCsJ|jtjkrt|S|jj||jj|jjSdS)z.Read one line, using input() when appropriate.N)rrrrrrr)r>promptrrrrJs   zHelper.getlinecCst|tdkrr|j}|dkr=|jq|dkrV|jq|dkro|jq|dkr|jq|dkr|jq|dddkr|j|jd q||jkr|j |q|dkrt t |d q||j kr1|j |q||jkrP|j |q|rt |d d|jqn/t|tr|nt |d d|j|jjddS)Nrrkeywordssymbolstopicsrzmodules rrrrz Help on %s:rr)zTruezFalsezNone)rrr listkeywords listsymbols listtopics listmodulesrr showsymbolr"evalr showtopicrrrrrr)r>rrrrrSs8        z Helper.helpcCs2|jjdttjddgddS)Na Welcome to Python %s's help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://docs.python.org/%s/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". r0r)rrrrrF)r>rrrrhs z Helper.introrPc Cstt|}||}t||d|}xt|D]}xt|D]z}|||}|t|krT|jj||||dkr|jjdd|dt||qqTqTW|jjdqAWdS)Nrrr)r sortedr r rr) r>itemscolumnsrZcolwrrowrrrrrr ys 4z Helper.listcCs*|jjd|j|jjdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrr rrD)r>rrrrs zHelper.listkeywordscCs*|jjd|j|jjdS)Nzx Here is a list of the punctuation symbols which Python assigns special meaning to. Enter any symbol to get more help. )rrr rrD)r>rrrrs zHelper.listsymbolscCs*|jjd|j|jjdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrr rrD)r>rrrrs zHelper.listtopicsc Csyddl}Wn&tk r8|jjddSYnX|jj||jj|}|s~|jjdt|dSt|tdkr|j ||S|\}}y|jj|}Wn0t k r|jjdt|dSYnXt |j d|r*|pdd|}n|rddl }ddj|jd} |j| d } |jjd dj| ndS) Nrzt Sorry, topic and keyword documentation is not available because the module "pydoc_data.topics" could not be found. zno documentation found for %s rrrzRelated help topics: z, Hz %s )pydoc_data.topicsrrrrrrrrrKeyErrorrrtextwrapr!rZwrap) r>topic more_xrefs pydoc_datatargetlabelxrefsr"rr.Z wrapped_textrrrrs4   !    zHelper.showtopicc Csyddl}Wntk r(dSYnX|jj||jj|}|s_tdnt|tr~|j||S|\}}|jj|}|r|pdd|}n||fS)a*Return unbuffered tuple of (topic, xrefs). If an error occurs here, the exception is caught and displayed by the url handler. This function duplicates the showtopic method but returns its result directly so it can be formatted for display in an html page. rNt Sorry, topic and keyword documentation is not available because the module "pydoc_data.topics" could not be found. rzcould not find topicr)rr) rrrrrrkrr; _gettopic)r>rrrrrrr"rrrrs   ! zHelper._gettopiccCs9|j|}|jd\}}}|j||dS)Nr)r partitionr)r>symbolrrr_rrrrrs zHelper.showsymbolcs|r,|jjdj|t|np|jjdi}|ddfdd}tjd||j|j|jjddS) Nzy Here is a list of modules whose name or summary contains '{}'. If there are any, enter a module name to get more help. zI Please wait a moment while I gather a list of all available modules... cSsY|r3|dddkr3|ddd}n|jddkrUd||.callbackcsd|ddS)Nr)r')rrronerrorsz#Helper.listmodules..onerrorrz Enter any module name to get more help. Or, type "modules spam" to search for modules whose name or summary contain the string "spam". )rrr apropos ModuleScannerrunr rD)r>rGrrr)rrrs    zHelper.listmodules)zassertr)zbreakr)zclassr)zcontinuer)rr)zdelr)zelser)zforr)zglobalr)zifr)importr)zinr)zlambda FUNCTIONS)znonlocalr)zpassr)zraiser)zreturnr)ztryr)zwhiler)withr)zyieldr)rrrrrrrr)rr\rrrrrrr rr r r rrr rrrr)rrr rrrr)r\r ) rrrrrrrrrrrr)rr rr r r )r r!)typesr*)r,r-)r.r/)r0r)r,r1)r3r4)r5r6)r7r8)r9r:)r;r<)r=r>)r?r@)rArB)rCrD)rEr)rFrG)rHr)rrI)rJr)rKrL)rNr+)rOrP)rQrR)rSrT)rUrV)rWrX)rWrY)rZr[)r]r^)r_r`)rar)z exceptionsrb)rcr)rdre)rfr)rgr)rhri)rjrk)rlrm)rnro)rprq)zdictrr)rsrt)rur)rvr)rwrM)rxrM)ryrM)rzrM)r{rM)r|rM)r}r~)rr)rr)rr\)rr)ztruthr)rr)rr) r%r&r[rZ_symbols_inverserrrZsymbols_rrrr~rrrrrrrrrrrr rrrrrrrrrrrrws<               rc@s+eZdZdZdddddZdS)rz7An interruptible scanner that searches module synopses.NcCs|r|j}nd|_i}xtjD]}|dkr.d||<|dkri|d|dqt|jp{d}|jdd}|d|}|jj|dkr|d||qq.q.Wxtj d|D]\} }} |jrPn|dkr"|d|dqytj | |} Wnt k rOwYnX| j } t | d ry| j|} Wn(tk r|r||nwYnXttj| pd}t | d r| j|}qld}ntjj| }y|j}Wn(tk r7|r0||nwYnX|jrT|jjdnd}t|d d}|d|}|jj|dkr||||qqW|r|ndS) NF__main__rrrrz - r get_source get_filenamerV)rrrrrrUrrr>r _get_specrrrsrrPrrStringIOrrrrrrrr<)r>rrGZ completerrseenr'r(rrIrJrrsourcerrrrrrrsb    "         "zModuleScanner.run)r%r&r[rUrrrrrrs rc CsUdd}dd}tj+tjdtj||d|WdQXdS)zAPrint all the one-line module summaries that contain a substring.cSsH|dddkr-|ddd}nt||o@d|dS)Nrz .__init__z (package)z- ii)r)rr'rrrrr9szapropos..callbackcSsdS)Nr)r'rrrr=szapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rGrrrrrr7s     rcsddlddlddlddlGdddjjGfdddjjGfdddj}|||}|jx%|j r|j rt j d qW|S) a7Start an HTTP server thread on a specific port. Start an HTML/text server thread, so HTML or text documents can be browsed dynamically and interactively with a Web browser. Example use: >>> import time >>> import pydoc Define a URL handler. To determine what the client is asking for, check the URL and content_type. Then get or generate some text or HTML code and return it. >>> def my_url_handler(url, content_type): ... text = 'the URL sent was: (%s, %s)' % (url, content_type) ... return text Start server thread on port 0. If you use port 0, the server will pick a random port number. You can then use serverthread.port to get the port number. >>> port = 0 >>> serverthread = pydoc._start_server(my_url_handler, port) Check that the server is really started. If it is, open browser and get first page. Use serverthread.url as the starting page. >>> if serverthread.serving: ... import webbrowser The next two lines are commented out so a browser doesn't open if doctest is run on this module. #... webbrowser.open(serverthread.url) #True Let the server do its thing. We just need to monitor its status. Use time.sleep so the loop doesn't hog the CPU. >>> starttime = time.time() >>> timeout = 1 #seconds This is a short timeout for testing purposes. >>> while serverthread.serving: ... time.sleep(.01) ... if serverthread.serving and time.time() - starttime > timeout: ... serverthread.stop() ... break Print any errors that may have occurred. >>> print(serverthread.error) None rNc@s(eZdZddZddZdS)z!_start_server..DocHandlercSsx|jjdrd}nd}|jd|jdd||j|jj|j|j|jddS) zProcess a request from an HTML browser. The URL received is in self.path. Get an HTML page from self.urlhandler and send it. z.cssztext/cssz text/htmlz Content-Typez%s; charset=UTF-8zutf-8N) rrrZ send_responseZ send_headerZ end_headersZwfiler urlhandlerr)r> content_typerrrdo_GETs   z(_start_server..DocHandler.do_GETcWsdS)Nr)r>rrrr log_messagesz-_start_server..DocHandler.log_messageN)r%r&r[rrrrrr DocHandlers  rcs:eZdZddZfddZddZdS)z _start_server..DocServercSsMd|_|j|f|_||_|jj||j|jd|_dS)NZ localhostF)hostZaddressrrIr~handlerr)r>portrrrrr~s   z)_start_server..DocServer.__init__cs^xM|jsOj|jjgggd\}}}|r|jqqW|jdS)Nr)rselectZsocketrZhandle_requestZ server_close)r>ZrdwrZex)rrrserve_until_quits  -z1_start_server..DocServer.serve_until_quitcSs-|jj||jr)|j|ndS)N)rIserver_activater)r>rrrrs z0_start_server..DocServer.server_activateN)r%r&r[r~rrr)rrr DocServers  rcsUeZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs>||_t||_jj|d|_d|_dS)NF)rr!rThreadr~servingerror)r>rr) threadingrrr~s   z,_start_server..ServerThread.__init__csyejj__jj_t|j_|j |j }||_ |j Wn.t k r}z||_WYdd}~XnXdS)zStart the server.N)server HTTPServerrIrrZMessageZ MessageClass staticmethodrrready docserverrrPr)r>Zdocsvre)rremailhttprrrs  z'_start_server..ServerThread.runcSs>d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr)r>rrrrrs   z)_start_server..ServerThread.readycSs"d|j_d|_d|_dS)z&Stop the server and this thread nicelyTFN)rrrr)r>rrrstops  z(_start_server..ServerThread.stopN)r%r&r[r~rrrr)rrrrrrr ServerThreads  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrr'rrtimeZsleep)rrrZthreadr)rrrrrrr _start_serverEs8    "+" rz text/htmlc sGfdddt}|fddfddfddfd d fd d fd dfddfddfdd f dd}|jdr|dd}n|dkr}tjjtjjt}tjj||}t|}dj|j SWdQXn|dkr||St d||fdS)aThe pydoc url handler for use with the pydoc server. If the content_type is 'text/css', the _pydoc.css style sheet is read and returned if it exits. If the content_type is 'text/html', then the result of get_html_page(url) is returned. cs.eZdZfddZddZdS)z_url_handler.._HTMLDoccs'd}d|}d|||fS)zFormat an HTML page.zpydoc_data/_pydoc.cssz1a  Pydoc: %s %s%s
%s
r)r>rrcss_pathZcss_link) html_navbarrrrsz#_url_handler.._HTMLDoc.pagecSsd||fS)Nz%sr)r>rrrrrrsz'_url_handler.._HTMLDoc.filelinkN)r%r&r[rrr)rrr_HTMLDocs  rcsUjdtjtjdtjf}d|jtjddfS)Nz %s [%s, %s]raZ
Python %s
%s
ZterseT)rrZpython_versionZ python_buildZpython_compiler)rF)rrrrs z!_url_handler..html_navbarcsdd}jddd}ddtjD}j||}|djd dd |g}i}x*tjD]}|jj||q{W|jd d d j|fS)zModule Index page.cSsd||fS)Nz%sr)r(rrr bltinlink sz3_url_handler..html_index..bltinlinkz7Index of Modulesz#ffffffz#7799eecSs"g|]}|dkr|qS)rr)rr(rrrr s z4_url_handler..html_index..z

zBuilt-in Modulesz#ee77aaz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr) rrrrrrr rur!)rrnamesrrr)rrr html_index s   z _url_handler..html_indexc sgfdd}tj7tjddd}tj||d|WdQXdd }g}jd d d }x+D]#\}}|j|||qW|jd |d ddj|}d|fS)zSearch results page.csN|dddkr-|ddd}nj||oCd|fdS)Nrz .__init__z (package)z- ii)r )rr'r) search_resultrrr/ sz3_url_handler..html_search..callbackrcSsdS)Nr)r'rrrr6 sz2_url_handler..html_search..onerrorrNcSsd||fS)Nz%sr)r(rrrr; sz4_url_handler..html_search..bltinlinkz5Search Resultsz#ffffffz#7799eezkey = %sz#ee77aaz
zSearch Results) rrrrrrr rr!) rGrrrrxrr(rr)r)rr html_search* s        z!_url_handler..html_searchc stjj|}tj|}j|j}WdQXd|}jddd}|jd|dd|}d||fS) z-Get and display a source file listing safely.Nz

%s
z3File Listingz#ffffffz#7799eezFile: %sz#ee77aaz getfile %s) r9r:Zunquoterrrrrr)rfpr#Zbodyrr)rrr html_getfileH s   z"_url_handler..html_getfilecsndd}jddd}ttjj}j||}|jddd|}d|fS)zIndex of topic texts available.cSsd||fS)Nz%sr)r(rrrrX sz4_url_handler..html_topics..bltinlinkz,INDEXz#ffffffz#7799eeZTopicsz#ee77aa)rrrrrDrr)rrrr)rrr html_topicsU s   z!_url_handler..html_topicscsnjddd}ttjj}dd}j||}|jddd|}d|fS)zIndex of keywords.z,INDEXz#ffffffz#7799eecSsd||fS)Nz%sr)r(rrrrl sz6_url_handler..html_keywords..bltinlinkZKeywordsz#ee77aa)rrrrrDrr)rrrr)rrr html_keywordse s   z#_url_handler..html_keywordscs tj}t||}|j|\}}||jkrHd}nd}jd|dd}dj|}j|dd|}|rt|j }dd }j ||}j d dd|}nd ||fd j |||ffS) zTopic or keyword help page.ZKEYWORDZTOPICz)%sz#ffffffz#7799eez
%s
z#ee77aacSsd||fS)Nz%sr)r(rrrr sz7_url_handler..html_topicpage..bltinlinkzRelated help topics: z%s %sr) rrrrrrr*rrrrrr!)rZbufZhtmlhelprrrrr)rrrhtml_topicpaget s&      z$_url_handler..html_topicpagecsat|dd}|dkr9|dkr9tdnt|}j||}||fS)Nrrrzcould not find object)rrkrr)rr9rcontent)rrr html_getobj s  z!_url_handler..html_getobjcspjddd}djfddtt||D}|j|dd|}d||fS) Nz,Errorz#ffffffz#7799eez
c3s|]}j|VqdS)N)r)rr)rrrrs sz3_url_handler..html_error..z#bb0000z Error - %s)rr!rrr)rrrr)rrr html_error s  z _url_handler..html_errorcs|}|jdr(|dd}ny|dkrI\}}ny|dkrg\}}n[|dkr\}}n=d|kr|jd\}}}|d kr|\}}q|d kr|\}}q|d kr7y|\}}Wqtk r3|\}}YqXq|d kr|dkra\}}qy|\}}Wqtk r|\}}YqXqtd n|\}}Wn:tk r}z||\}}WYdd}~XnXj||S)zGenerate an HTML page for url.z.htmlNrrurrrgz search?keyz getfile?keyz topic?keyzget?keyz bad pydoc url)rindex)rr)rrrrkrPr)rZ complete_urlrropr_r) rrrrrrrrrrr get_html_page sB           (z#_url_handler..get_html_pagerrNztext/cssrz text/htmlz"unknown content type %r for url %s) rrqr rdirnamerealpathrVr!r readlinesr)rrrrZ path_hererrr) rrrrrrrrrrr _url_handlers,    **   r open_browserTcCs-ddl}tt|}|jr5t|jdS|jr)d}|r]|j|jnzytd|jt|x^|jrtd}|j }|dkrPq|dkr|j|jqt|qWWnt t fk rtYnXWd|jr%|j tdnXndS) zStart the enhanced pydoc Web server and open a Web browser. Use port '0' to start the server on an arbitrary port. Set open_browser to False to suppress opening a browser. rNz"Server commands: [b]rowser, [q]uitzServer ready atzserver> rrzServer stopped) webbrowserrrrrrrrrrrrr)rrrZ serverthreadZserver_help_msgrrrrbrowse s2            rcCs%t|to$|jtjdkS)Nr)rr;rr sep)rNrrrispath sr cCsddl}Gdddt}dtjkrtjjtjd}|tjkrltjj|ntjjddny|jtjddd\}}d }d }d }d}xy|D]q\} } | d krd }d }n| d kr t | dS| d kr%d }| }n| dkrd }qqW|rm|dkrYd}nt |d|dS|s||nx|D]} t | rtjj |  rt d| Pny|t | rtjj| rt| } n|r(t | rtjj| rt| q5t| n tj| Wqtk rg} zt | WYdd} ~ XqXqWWnc|j|fk rtjjtjjtjdd} t djd| dtjYnXdS)z@Command-line interface (looks at sys.argv to decide what to do).rNc@seZdZdS)zcli..BadUsageN)r%r&r[rrrrBadUsage s r rrrzbk:p:wFz-bTz-kz-pz-wrzfile %r does not existapydoc - the Python documentation tool {cmd} ... Show text documentation on something. may be the name of a Python keyword, topic, function, module, or package, or a dotted reference to a class or function within a module or module in a package. If contains a '{sep}', it is used as the path to a Python source file to document. If name is 'keywords', 'topics', or 'modules', a listing of these things is displayed. {cmd} -k Search for a keyword in the synopsis lines of all available modules. {cmd} -p Start an HTTP server on the given port on the local machine. Port number 0 can be used to get an arbitrary unused port. {cmd} -b Start an HTTP server on an arbitrary unused port and open a Web browser to interactively browse documentation. The -p option can be used with the -b option to explicitly specify the server port. {cmd} -w ... Write out the HTML documentation for a module to a file in the current directory. If contains a '{sep}', it is treated as a filename; if it names a directory, documentation is written for all the contents. rr)getoptrPrrr rargvremoveinsertrrr existsrrrr rrrrrrrr r)r r Z scriptdirZoptsrZwritingZ start_serverrrZoptvalargrHrrrrcli sd %              %)rr)VrUr8rPrTrSraZimportlib._bootstraprimportlib.machineryimportlib.utilrrr r>rrrrrZ urllib.parser9r collectionsrreprlibr tracebackrrrr$r)r-r/r3r IGNORECASEr4r5r:r?rCrOrurvrrrrPrrrrrrrwrxrrrrrrrrrrrr.rrrrr"rrrrrrrrrr rr%rrrr$s                          ( 0=*- d  !    ,         >  %  V