Yf@s:dZdgZdZdZdZddlZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZd d Zd d ZddZddZ ddZ!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,Z0Gd-d.d.e1Z2d/d0Z3did1d2Z4Gd3d4d4Z5Gd5d6d6eZ6Gd7d8d8e5Z7Gd9d:d:eZ8Gd;d<d<e5Z9Gd=d>d>e9Z:d?d@a;dAdBZ<dCdDZ=dEdFZ>dGdHZ?dIdJZ@dKdLZAdMdNZBdOdPZCddQdRZDe9ZEe:ZFe7ZGddSdTZHdUdddVdWZIdUdddXdYZJddZd[ZKd\dd]d^ZLGd_d`d`ZMeMZNGdadbdbZOdcddZPdedfZQdgdhdiZRddjdkdldmZSdndoZTdpdqZUeVdrkr6eUdS)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 https://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}xstjD]h}tjj|p.d}tjj|}||krtjj|r|j||j|qW|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr*/opt/alt/python35/lib64/python3.5/pydoc.pypathdirsMs rcCsCtj|ptj|}|r?tjdd|jpBdS)z-Get the doc string or comments for an object.z^ * )inspectgetdocZ getcommentsresubrstrip)objectresultrrrrYsrcCs|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$cCs-|j}|j|kr)|jd|}|S)z@Get a class name and qualify it with a module name if necessary.r)__name__ __module__)rmodnamenamerrr classnamegs 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)rrrrisdatansr-cGsAx:|r<|dj|j|d}|dd}qW|S)z/Do a series of global replacements on a string.rrrN)r!r)textZpairsrrrreplacets  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.maxlenZpreZpostrrrcram{s *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||rPrSr\rUrWrRrTrVrQrYrZr]rXr&r[r%) startswithendswithhasattr)r(allr9rrr visiblenames   recCs^g}xQtj|D]@\}}}}tj|r=d}|j||||fqW|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.zdata descriptor)rclassify_class_attrsisdatadescriptorr )rresultsr(kindclsrHrrrrfs "rfcCsPtjj|rLx7dD]/}tjjtjj|d|rdSqWdS)z3Guess whether a path refers to a package directory..py.pyc__init__TF)rkrl)r rr isfiler!)rextrrr ispackages  %rpcCs|j}x:|dddks2|j rH|j}|sPqW|j}|dddkr{|dd}|dddkr |dd}|d ddkr|dd }x#|js|j}|sPqW|jddj}nd}|S) Nr#zr"""r0z"""\rrt)readlinerr)filelinerrrrsource_synopsiss& &   rxc Cstj|j}|j|d\}}|dksB||kr||jttjjrltjj }n0|jttjj rtjj }nd}|dkryt j |}Wntk rdSYnX|t|}WdQRXn{|d|}tjjd|d|}ytjj|} Wn dSYnXtjd=| jrf| jjdnd}||f||<|S)z.Get the one-line summary out of a module file.NZ__temp__loaderr)NN)r statst_mtimegetrbtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrxutilspec_from_file_location _bootstrap_loadrmodulesrU splitlines) filenamecachemtimeZ lastupdaterZ loader_clsrvryspecmodulerrrsynopsiss4      "rc@s.eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs%||_|\|_|_|_dS)N)rexcrHtb)r>rexc_inforrrrms zErrorDuringImport.__init__cCs#|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr%rrH)r>rrrr__str__s zErrorDuringImport.__str__N)r%r&r[rUrmrrrrrrs  rc Cstjj}t|d4}|jt|}||tjjfk}WdQRXtjj |}tjj |\}}|rtj j ||}ntj j ||}tjj||d|} ytjj| SWnt|tjYnXdS)zKs zsafeimport..Nrr)rrbuiltin_module_names __import__rrrV SyntaxErrorr ImportErrorr(rr<AttributeError) r forceloadrZsubsrGrrrHrinfopartr)rr safeimport7s.   rc@seZdZejjddejddZdddZ dddZ e Z Z Z ZZZejjejd d ejddd d ZdS) Doc PYTHONDOCSz%https://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(argsrrrdocumentms"      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(rmessagerrrfails&zDoc.faillibz python%d.%dcCsytj|}Wntk r-d}YnXtjjd|j}tjj|}t |t tr|j dks|j |r|j tjj |d  r|j dkr|j drd|jd|j jf}qtjj ||j jd}nd}|S)z*Return the location of module docs or Nonez (built-in)rerrno exceptionsgcimpmarshalposixsignalr_thread zipimportz site-packages xml.etreetest.pydoc_modhttp://https://z%s/%s/z.htmlN) rrrrrrrrrr)rr)rr)r getabsfilerr environr|rrr rrr%rar!rlower)r>rZbasedirrvdoclocrrr getdoclocs$   %%z Doc.getdocloc)r%r&r[r rr|r version_inforrrrrrrrrrr!base_exec_prefixrrrrrrgs  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)rrmmaxlistmaxtuplemaxdict maxstringmaxother)r>rrrrms  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||||S|jttt ||j S)Nr%repr_r_) rcrr!r%rr<rr3r5rr)r>rNlevel methodnamerrrrepr1s "zHTMLRepr.repr1cCst||j}t|}d|krcdt|ddkrcd|d|j||dStjdd|j|S)Nrsz\\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[rUrmrrrrrepr_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 Csw|dkrdd|d}d|||f} |rT| 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.preformatrrcCsd}t||d|}xt|D]r}|dd|}xMt|||||D]0}|t|kr_||||d}q_W|d}q+Wd|S)z0Format a list of items into a multi-column list.rrzrz
zz7%s
)r range)r>listformatZcolsrrowscolirrr multicolumns"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%rrr|r&rcr<r))r>rr'r(rrrr classlink#s $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(rrpshadowedurlr.rrr modpkglink/s   zHTMLDoc.modpkglinkcCsd||fS)zMake a link to source file.z%sr)r>r rrrrfilelink>szHTMLDoc.filelinkcCs|p |j}g}d}tjd}x|j||} | sFP| j\} } |j|||| | j\} } }}}}| r|| jdd}|jd||fn|rdt|}|jd||| fn|r7dt|}|jd||| fn|r|| | dd krw|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.rfuncsclassesrFrhherepatternmatchstartendrdschemeZrfcZpepZselfdotr(r rrrmarkupBs<   " zHTMLDoc.markupc Csd}x|D]}t|tfkr|\}}|d}||j||}|r||fkrg}x'|D]} |j|j| |qyW|ddj|d}|d}q t|tgkr |d|j|||}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'parentrentrycbasesparentsrIrrrrms       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/krx|d0dd krx|dd1j}|jd j|t|d r|jjt|j|r| d dj|} j|}|dk rdt}nd}j| ddd| |}tj|tj}gi}}xtj|tjD]n\}}|dk stj|p||krft|||rf|j||fd|||<||%sz)%sz (built-in)r] $z Revision: z version %srTz (%s)z, z-
Module Referencerz#ffffffz#7799eezindex
rqz.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
rPZAuthorrSZCreditsrtz $Revision: rtrt)6r%__all__rrrr r r!rrurllibparseZquoter rrcstrr]rrrTrlocalsrr@r*r+ getmodulererAr&rrr|r<r,r8r6r-rrrpkgutil iter_modulesrZsortrr rr getclasstreerrPrS)#r>rr(modignoredrdpartsZlinksrZ linkednameheadrr r rversionrrrrZcdictrGrHrIr'rrZfdictdatar"modpkgsimporterispkgr classlistr)r>rrs    -   ,   " ! " " $!"   !& &    zHTMLDoc.docmodulecsj}|p|}j}g} | jGfddd} | ttj} t| dkrjdx+| D]#} dj| j qWdfdd} fd d }fd d }fd dt D}ix|D]w\}}}}d|d||<}yt |}Wnt k rYnXy||.HorizontalRulecSs d|_dS)Nr)needone)r>rrrrmsz1HTMLDoc.docclass..HorizontalRule.__init__cs |jrdd|_dS)Nz
r)r>)r>)pushrrmaybes  z.HTMLDoc.docclass..HorizontalRule.maybeN)r%r&r[rmr@r)r?rrHorizontalRules  rArz&
Method resolution order:
z
%s
z
cst||\}}|rj|x|D]\}}}}yt|}Wn+tk rj||Yn&Xj||dq6W|S)Nr)rOr@r< Exception_docdescriptorr)msgattrsrKokr(rihomeclsrH)rrhrmdictr4rr?r>rrspills   zHTMLDoc.docclass..spillcsit||\}}|rej|x3|D]+\}}}}j||q6W|S)N)rOr@rC)rDrErKrFr(rirGrH)rHr4r?r>rrspilldescriptors)s  z*HTMLDoc.docclass..spilldescriptorsc s t||\}}|r j|x|D]\}}}}jt||}t|stj|rt|dd} nd} | dkrd|nBjt|j } d| } d|| fdq6W|S)NrUz
%s
z
%sz
%s%s
r) rOr@rr<callablerrgrrr) rDrErKrFr(rirGrHrIr")rrrHrIr4rr?r>rr spilldata2s"    z#HTMLDoc.docclass..spilldatacs@g|]6\}}}}t|dr||||fqS)r9)re)rr(rirjrH)rrrrGs z$HTMLDoc.docclass..rq-rcs|dkS)Nrr)r') thisclassrrr(`sz"HTMLDoc.docclass..z defined herezinherited from %sz:
rGcSs|dS)Nrr)r'rrrr(msz Methods %scSs|ddkS)Nrmethodr)r'rrrr(qszClass methods %scSs|ddkS)Nrz class methodr)r'rrrr(sszStatic methods %scSs|ddkS)Nrz static methodr)r'rrrr(uszData descriptors %scSs|ddkS)Nrzdata descriptorr)r'rrrr(wszData and other attributes %scSs|ddkS)Nrr9r)r'rrrr(ysrz*class %sz/%s = class %sz(%s)z, z%s
 
z#000000z#ffc8d8r0)r%rAr rrgetmror r@rr&rfr<rBrpopleftrObuiltinsrr2r!rrrr)r>rr(r4rrr5realnamer#rrAmrorIrJrKrMrErGrirGrHanchor inheritedtagrr$r"r) rrrHrIr4rr?r>rOrrs         ' '    !              $zHTMLDoc.docclasscCs|jd|j|S)z)Format an argument default value as text.=)rr)r>rrrr formatvalueszHTMLDoc.formatvaluecCsT|j}|p|}|r$|jp'dd|} d} d} t|r|jj} |r| |k rd|j| |} nD|jdk rd|j|jj|} nd|j| |} ||krd| |f} ne|r0||jkr0|j||kr0d |jd||f}d } n|}d | ||f} d}tj|rytj|}Wnt t fk rd}YnX|rt |}|d krd |} |d d}|sd}| |j || o|j d| }| rd|S|jt||j|||}|o?d|}d||fSdS)z;Produce HTML documentation for a function or method object.rrNrz from Nz method of %s instancez unbound %s methodz$%sz%srz)%s = %szz$%s lambda z(...)z'%sz
%s
z
%s
z
%s
%s
rt)r%r?r;rr__dict__rr, signature ValueErrorrr-rrrrr)r>rr(r4rrrFrErTrVnoteskipdocsimclassrZreallinkargspecr\declr"rrrrsZ            zHTMLDoc.docroutinecCsrg}|j}|r#|d||jdk r[|jt||j}|d||ddj|S)Nz!
%s
z
%s
z
r)r rUrrrr!)r>r(rHr4rhr?r"rrrrCs  zHTMLDoc._docdescriptorcCs|j|||S)z*Produce html documentation for a property.)rC)r>rr(r4rErrrrszHTMLDoc.docpropertycGs'|rd|pd}||j|S)z-Produce HTML documentation for a data object.z%s = r)r)r>rr(r4r5ZlhsrrrrszHTMLDoc.docothercCs|j|||S)z1Produce html documentation for a data descriptor.)rC)r>rr(r4rErrrrszHTMLDoc.docdatacCsg}|dkri}xhtj|gD]T\}}}tdd|DrVq+|j|d|||kfd||sz HTMLDoc.index..rrz#ffffffz#ee77aa)r0r1anyr r2rr r)r>rr r:r;r(r<rrrrindexs " z HTMLDoc.index)r%r&r[rUr_repr_instancerrrrrrrrrrrrr r rrrrrZrrCrrrrgrrrrrs:              +y ; rc@sLeZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs:tj|d|_|_d|_d|_|_dS)Nrrr)rrmrrrrr)r>rrrrms  zTextRepr.__init__cCsxtt|dr\ddjt|jj}t||r\t||||Sttt||j S)Nr%rr_) rcrr!r%rr<r3r5rr)r>rNrrrrrrs "zTextRepr.repr1cCs^t||j}t|}d|krZdt|ddkrZd|d||dS|S)Nrsz\\rrr)r3rrr/)r>rNrrrrrrr s  $zTextRepr.repr_stringc Cs=y ttt||jSWnd|jjSYnXdS)Nz <%s instance>)r3r5rrrr%)r>rNrrrrrs zTextRepr.repr_instanceN) r%r&r[rUrmrrrrrrrrris    ric@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)rrdrrrre$szTextDoc.bold..)r!)r>r.rrrbold"sz TextDoc.boldz csS|s dSfdd|jdD}|rF|dj|d.rrrtrt)rrr!)r>r.rmr#r)rmrindent&s "zTextDoc.indentcCs.|j|j}|j|d|dS)z&Format a section with a given heading.rz )rnrrl)r>rrZclean_contentsrrrr-szTextDoc.sectionNrc sd}x|D]}t|tfkr|\}}||t|}|r||fkrfdd|D} |ddj| }|d}q t|tgkr ||j|||d}q W|S)zBRender in text a class tree as returned by inspect.getclasstree().rc3s|]}t|VqdS)N)r))rr")r'rrre<sz%TextDoc.formattree..z(%s)z, rz )rr)r!r) r>rr'r rmrr!r"r#r$r)r'rr4s    zTextDoc.formattreec Cs|j}tt|\}}|jd||o:d|}t|dd}|j|}|dk r||jd|d}|r||jd|}g} xotj|tjD]X\} } |dk stj | p||krt | ||r| j | | fqWg} xxtj|tj D]a\} } |dk sttj | sttj | |kr8t | ||r8| j | | fq8Wg} xEtj|tD]1\} } t | ||r| j | | fqWg}t}t|drxWtj|jD]C\}}}|j||rR|j |d q|j |qW|j||jd d j|}g}xRtj|tjD];\} } | jj|d r| |kr|j | qW|r|j||jd d j|}| rdd| D}|jtj|d|g}x0| D](\} } |j |j| | |qWW||jdd j|}| rg}x0| D](\} } |j |j| | |qW||jdd j|}| rdg}x6| D].\} } |j |j| | |ddqW||jdd j|}t|drt|j}|ddd#kr|d$ddkr|dd%j}||jd|}t|dr||jdt|j }t|dr6||jdt|j!}t|drd||jd t|j"}ytj#|}Wnt$k rd!}YnX||jd"|}|S)&z5Produce text documentation for a given module object.NAMEz - r*NzMODULE 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]r%r&z Revision: VERSIONrTZDATErPZAUTHORrSZCREDITSz (built-in)ZFILEz $Revision: rtrt)%r%r$rrr<rrr@r+r/rer r,r8r-setrcr0r1rZaddr2r!r*rarr3rrr-r]rrTrPrSrr)r>rr(r4ZsynopdescrrdrrrGrHrr9r:Z modpkgs_namesr;r'r<Z submodulesr=rr8rvrrrrDs    " " $ "   ""    &,  zTextDoc.docmodulecs-j}|p|}j}jdd}||krRdj|}nj|d|}|rt||} |ddj| }t} | r| dgpg} | jtt j } t | dkr#d x"| D]} d || qWd Gfd d d }|fdd}fdd}fdd}fddt D}x0|r| r| j n|ddt|fdd\}}tjkr#|}qn+kr8d}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))r"rrrrmakenamesz"TextDoc.docclass..makenamezclass z = class z(%s)z, rrzMethod resolution order:z rcs.eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dS)Nr)r>)r>rrrrmsz1TextDoc.docclass..HorizontalRule.__init__cs$|jrddd|_dS)NrNrrr)r>)r>)r?rrr@s z.TextDoc.docclass..HorizontalRule.maybeN)r%r&r[rmr@r)r?rrrAs  rAcst||\}}|rj|xw|D]o\}}}}yt|}Wn+tk rj||Yq6Xj||q6W|S)N)rOr@r<rBrCr)rDrErKrFr(rirGrH)rHr4rr?r>rrrJs    zTextDoc.docclass..spillcsit||\}}|rej|x3|D]+\}}}}j||q6W|S)N)rOr@rC)rDrErKrFr(rirGrH)rHr4r?r>rrrKs  z*TextDoc.docclass..spilldescriptorsc st||\}}|rj|x|D]\}}}}t|sctj|rrt|}nd}yt|} Wntk r|j|} YnXj | |ddd|dq6W|S)Nr2rrr"r) rOr@rLrrgrr<rr[r) rDrErKrFr(rirGrHr"r9)rHr4rr?r>rrrMs   ! z#TextDoc.docclass..spilldatacs@g|]6\}}}}t|dr||||fqS)r9)re)rr(rirjrH)rrrrs z$TextDoc.docclass..rcs|dkS)Nrr)r')rOrrr(sz"TextDoc.docclass..z defined herezinherited from %sz Methods %s: cSs|ddkS)NrrPr)r'rrrr(szClass methods %s: cSs|ddkS)Nrz class methodr)r'rrrr(szStatic methods %s: cSs|ddkS)Nrz static methodr)r'rrrr(szData descriptors %s: cSs|ddkS)Nrzdata descriptorr)r'rrrr(szData and other attributes %s: cSs|ddkS)Nrr9r)r'rrrr(sz | )r%rAr&rlmapr!rr rrrQr rfrRrOrSrr)r2rnr)r>rr(r4r5rTr#rwrr$r"rrUrIrArJrKrMrErWrXr)rHr4rr?r>rOrrsl            !           zTextDoc.docclasscCsd|j|S)z)Format an argument default value as text.rY)r)r>rrrrrZ&szTextDoc.formatvaluec Cs|j}|p|}d}d}t|r|jj}|ra||k rdt||}n>|jdk rdt|jj|}ndt||}||kr|j|} nE|r||jkr|j||krd}|j|d|} d} tj|rytj |} Wnt t fk rJd} YnX| rt | } |d kr|j|d } | dd } | sd } | | |} |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(...)rrt)r%r?r;rr)rlr[rr,r\r]rr-rrnr)r>rr(r4rErTr^r_r`rrar\rbr"rrrr*sJ         zTextDoc.docroutinecCstg}|j}|r2||j||dt|pAd}|rg||j||ddj|S)Nrr)r rlrrnr!)r>r(rHr4rhr?r"rrrrC\s   zTextDoc._docdescriptorcCs|j|||S)z*Produce text documentation for a property.)rC)r>rr(r4rErrrriszTextDoc.docpropertycCs|j|||S)z1Produce text documentation for a data descriptor.)rC)r>rr(r4rErrrrmszTextDoc.docdatac Cs|j|}|r_|r%|dp(d|}|t|} | dkr_|d| d}|rx|j|dp{d|}|dk r|d|jt|7}|S)z-Produce text documentation for a data object.z = rrNz...r)rr rlrnr-) r>rr(r4r r2r"rrwZchoprrrrqs # zTextDoc.docother)r%r&r[rUrirhrrlrnrrrrrZrrCrrrrrrrrjs     e} 2 rjc@s"eZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|S)Nr)r>r.rrrrlsz_PlainTextDoc.boldN)r%r&r[rUrlrrrrry}s rycCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpager)r.rrrr{s r{c CsttjdstSttjds,tStjj sLtjj rPtSdtjkrtjdkrxddStjj ddkrd dSd dStjj ddkrtStjdkrd dSttd rtj d dkrddSddl }|j \}}tj |z:ttd rgtj d|dkrgddStSWdtj|XdS)z2Decide what method to use for paging through text.isattyPAGERwin32cSstt|tjdS)Nr}) tempfilepagerplainr r)r.rrrr(szgetpager..ZTERMdumbemacscSstt|tjdS)Nr}) pipepagerrr r)r.rrrr(scSst|tjdS)Nr})rr r)r.rrrr(scSstt|dS)Nzmore <)rr)r.rrrr(ssystemz(less) 2>/dev/nullrcSs t|dS)NZless)r)r.rrrr(sNz more "%s"cSs t|dS)NZmore)r)r.rrrr(s)rr)rr)rcrstdin plainpagerstdoutr|r rplatformr|rtempfileZmkstempclosettypagerunlink)rfdrrrrrzs4     $   ( rzcCstjdd|S)z%Remove boldface formatting from text.z.r)rr)r.rrrrsrc Csddl}|j|ddd|j}yLtj|jdd-}y|j|Wntk rmYnXWdQRXWntk rYnXx(y|j PWqtk rYqXqWdS)z3Page through text by feeding it to another program.rNshellTrerrorsbackslashreplace) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)r.cmdrprocpiperrrrs      rcCsvddl}|j}t|ddd}|j|WdQRXztj|d|dWdtj|XdS)z.cSs!tjjddddS)Nrrt)rrrurrrrr(sZLINESrz -- more --qQz  bB)rr)rr)rrr)rrrttyrrfilenoZ tcgetattrZ setcbreakrrrUnsupportedOperationrr rr|r]rrr!flushZ tcsetattrZ TCSAFLUSH) r.r#rroldZgetcharhrZincr"rrrrsL     '       /rcCs tjjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrr)r.rrrrsrcCs$tj|rQ|jtjkr,d|jSt|drFd|jSd|jStj|rkd|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%rrrcr8r __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)rrrrrr#s zlocate..rNrr)Nr)rr rr!rSr<r)rrr6rnZ nextmodulerrrrrlocate!s  &   rcCsyt|trDt||}|dkr:td|||fSt|dd}|t|trn|ndfSdS)zDGiven an object or a path to an object, get the object and its name.Nz~No Python documentation found for %r. Use help() to get the interactive help utility. Use help(str) for help on the str class.r%)rr-rrr<)rrrr(rrrresolve:s   rz Python Library Documentation: %scCs'|dkrt}t||\}}t|}tj|}|rxd|krx|d|d|jd7}n#|r||k r|d|j7}tj|ptj|ptj |ptj |ptj |pt |t s t|}|d7}||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(rvrrrr render_docHs$  $  rcCsyE|dkr(tt|||n|jt|||tWn5ttfk r|}zt|WYdd}~XnXdS)zCDisplay text documentation, given an object or a path to an object.N)r{rr plaintextrrprint)rrroutputrHrrrr"as   r"cCsy~t||\}}tjt|tj||}t|dddd}|j|WdQRXtd|dWn5tt fk r}zt|WYdd}~XnXdS)zdd?d!d@d#d$d%dAd'dBd)dd*dd+dCd,dDd.dEddFd/dGddHd2dIi!Zd3dJd<dKd$dLdQdMdRdNd_dOd`dPiZdCdcd@dddedfdgdhdidjdkdldmdndod3dpdqdrdsdtdudvdwdxdwdydzd{dziZxaejD]S\ZZxDeD]<Z ej e eZ ee kre d|eZ e ee >r|^~rr<=>===!=<>ZUNARYAUGMENTEDASSIGNMENT+=-=*=/=%=&=|=^=<<=>>=**=//=ZBITWISEZCOMPLEXjJzOPERATORS FORMATTINGZPOWER,zTUPLES LISTS FUNCTIONSrz ATTRIBUTES FLOAT MODULES OBJECTSz...ELLIPSIS:zSLICINGS DICTIONARYLITERALS@z def classrsr_Z PRIVATENAMESr^zPRIVATENAMES SPECIALMETHODS`Z BACKQUOTESrzTUPLES FUNCTIONS CALLSr[zLISTS SUBSCRIPTS SLICINGS]rTYPEStypesRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspectstrings4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPESZ STRINGMETHODSstring-methodsSTRINGS FORMATTINGZ FORMATTING formatstringsUNICODE:encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPESZNUMBERSnumbersINTEGER FLOAT COMPLEX TYPESZINTEGERintegers int rangeZFLOATfloating float math imaginary complex cmathZ SEQUENCEStypesseq$STRINGMETHODS FORMATTING range LISTSZMAPPINGSZ DICTIONARIEStypesfunctions def TYPESZMETHODS typesmethodsclass def CLASSES TYPESZ CODEOBJECTSbltin-code-objectscompile FUNCTIONS TYPESZ TYPEOBJECTSbltin-type-objects types TYPESZ FRAMEOBJECTSZ TRACEBACKSZNONEbltin-null-objectbltin-ellipsis-objectSLICINGSZSPECIALATTRIBUTES specialattrsrp!class SPECIALMETHODS PRIVATENAMES typesmodulesZPACKAGES EXPRESSIONSoperator-summarylambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIESZ PRECEDENCEZOBJECTSobjectsZSPECIALMETHODS specialnamesbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES customizationhash repr str SPECIALMETHODSZATTRIBUTEMETHODSattribute-accessATTRIBUTES SPECIALMETHODSZCALLABLEMETHODScallable-typesCALLS SPECIALMETHODSsequence-types(SEQUENCES SEQUENCEMETHODS SPECIALMETHODSZMAPPINGMETHODSMAPPINGS SPECIALMETHODS NUMBERMETHODS numeric-types*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODSZ EXECUTION execmodel%NAMESPACES DYNAMICFEATURES EXCEPTIONSZ NAMESPACESnaming3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURESZDYNAMICFEATURESdynamic-featuresZSCOPINGZFRAMESrtry except finally raiseZ CONVERSIONS conversionsZ IDENTIFIERS identifierskeywords SPECIALIDENTIFIERSZSPECIALIDENTIFIERS id-classesatom-identifiersZLITERALS atom-literals=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALSZTUPLESZ TUPLELITERALS exprlistsTUPLES LITERALSZLISTStypesseq-mutable LISTLITERALSlistsLISTS LITERALS typesmappingDICTIONARYLITERALSrDICTIONARIES LITERALSZ ATTRIBUTESattribute-references(getattr hasattr setattr ATTRIBUTEMETHODSZ SUBSCRIPTS subscriptionsslicingsZCALLScallspowerunaryZBINARYbinaryZSHIFTINGshiftingbitwise comparisonsEXPRESSIONS BASICMETHODSbooleansEXPRESSIONS TRUTHVALUEZ ASSERTIONZ ASSIGNMENT assignment augassignZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGcompoundfor while break continuetruth if while and or not BASICMETHODSZ DEBUGGINGdebuggerpdbZCONTEXTMANAGERScontext-managersNcCs||_||_dS)N)_input_output)r>inputrrrrrm*s zHelper.__init__cCs|jptjS)N)r|rr)r>rrrr(.szHelper.cCs|jptjS)N)r}rr)r>rrrr(/scCs?tjdddkr%|dSd|jj|jjfS)Nrr0?rz<%s.%s instance>)rstackrr&r[)r>rrr__repr__1s  zHelper.__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__9s    zHelper.__call__cCs|jjdxy|jd}|s,PWnttfk rHPYnXt|ddddj}|jd krzP|dkr|jq|j |qWdS) Nrzhelp> r rrrquitr)rr) rrgetlinerEOFErrorr/rrrr)r>rrrrrFs  zHelper.interactcCsJ|jtjkrt|S|jj||jj|jjSdS)z.Read one line, using input() when appropriate.N)r~rrrrrru)r>promptrrrrUs   zHelper.getlinecCst|tdkro|j}|dkr=|jq|dkrV|jq|dkro|jq|dkr|jq|dddkr|j|jdq||jkr|j|q|dkrt t |d q||j kr|j |q||j kr7|j |q|rVt |d d |jqt td d |jn/t|tr|nt |d d |j|jjddS)Nrkeywordssymbolstopicsrzmodules rrrrz Help on %s:rr)rrr)rr listkeywords listsymbols listtopics listmodulesrr showsymbolr"evalr showtopicrr}r-rrrr)r>rrrrr^s6       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)rrr}rr8)r>rrrrss z Helper.introrrPc Cstt|}||}t||d|}xt|D]}xt|D]t}|||}|t|krT|jj||||dkrT|jjdd|dt||qTW|jjdqAWdS)Nrrr)rsortedr rrr) r>itemscolumnsrZcolwrrowrrrrrrs .z Helper.listcCs*|jjd|j|jjdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrrrrD)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. )rrrrrD)r>rrrrs zHelper.listsymbolscCs*|jjd|j|jjdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrrrrD)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|}|rddl }ddj|jd} |j| d } |jjd dj| dS) 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.topicsrrrrr|rrrrKeyErrorr{rtextwrapr!rZwrap) r>topic more_xrefs pydoc_datatargetlabelxrefsr"rr.Z wrapped_textrrrrs4   !    zHelper.showtopicc Csyddl}Wntk r(dSYnX|jj||jj|}|s\tdt|tr{|j||S|\}}|jj|}|r|pdd|}||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) rrrr|rr]rr- _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... cSsS|r0|dddkr0|ddd}|jddkrOd||.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". )rrrapropos ModuleScannerrunrrD)r>rGrrr)rrrs    zHelper.listmodules)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rrq)rr)rr)rr)rrq)rr)rr)rr)rr)rrrrrr rr)rrNrrrrrrrrrrrrrrrrrr)rrrrrrr)rNr) rrrr r r r r rrrr)rrrrrr)rr)rr)rr)r r!)r"r)rr$)r%r&)r'r()r)r*)r+r,)r-r.)r/r0)r1r2)r3r4)r5r6)r7r)r8r9)r:r)rr;)r<r)r>r?)r@r)rArB)rCrD)rErF)rGrH)rIrJ)rIrK)rMrN)rOrP)rQrR)rSr)rrT)rUr)rVrW)rXr)rYr)rZr[)r\r])r^r_)r`ra)rbrc)rrd)rerf)rgr)rhr)rir=)rjr=)rkr=)rlr=)rmr=)rnr=)rorp)rqrr)rsr)rtrL)rurv)rwrx)ryrz)r{r) r%r&r[rZ_symbols_inverserrrZsymbols_rr|rrmrr~rrrrrrrrrrrrrrrrrrrrrr~s4                rc@s+eZdZdZdddddZdS)rz7An interruptible scanner that searches module synopses.NcCs|r|j}d|_i}xtjD]}|dkr+d||<|dkrf|d|dq+t|jpxd}|jdd}|d|}|jj|dkr+|d||q+Wxtj d|D]\} }} |jrP|dkr|d|dqytj | |} Wnt k rCwYnX| j } t | d ry| j|} Wn%tk r|r||wYnXttj| pd}t | d r| j|}qNd}nrytjj| }Wn%tk r|r||wYnX|jr6|jjdnd}t|d d}|d|}|jj|dkr||||qW|r|dS) NF__main__rrrrz - r get_source get_filenamerV)rrrrrrUrrr0r _get_specrryrcrrBrxrStringIOrr~rrrrr<)r>rrGZ completerrseenr'r(rvr;r<rrysourcerrrrrrs`     "         "zModuleScanner.run)r%r&r[rUrrrrrrs rc CsVdd}dd}tj+tjdtj||d|WdQRXdS)zAPrint all the one-line module summaries that contain a substring.cSsE|dddkr*|ddd}t||o=d|dS)Nrz .__init__z (package)z- ii)r)rr'rvrrrrCszapropos..callbackcSsdS)Nr)r'rrrrGszapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rGrrrrrrAs     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) rrbZ 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)hostZaddressrrIrmhandlerr)r>portrrrrrms   z)_start_server..DocServer.__init__cs[xJ|jsLj|jjgggd\}}}|r|jqW|jdS)Nr)rselectZsocketrZhandle_requestZ server_close)r>ZrdwrZex)rrrserve_until_quits  -z1_start_server..DocServer.serve_until_quitcSs*|jj||jr&|j|dS)N)rIserver_activater)r>rrrrs z0_start_server..DocServer.server_activateN)r%r&r[rmrrr)rrr DocServers  rcsUeZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs>||_t||_jj|d|_d|_dS)NF)rrrThreadrmservingerror)r>rr) threadingrrrms   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 docserverrrBr)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[rmrrrr)rrrrrrr ServerThreads  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrrrrtimeZsleep)rrrZthreadr)rrrrrrr _start_serverOs8    "+" rz text/htmlc sGfdddt}|fddfddfddfd d fd d fd dfddfddfdd f dd}|jdr|dd}|dkr{tjjtjjt}tjj||}t|}dj|j SWdQRXn|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>r rrrrr sz'_url_handler.._HTMLDoc.filelinkN)r%r&r[rr r)rrr_HTMLDocs  rcsUjdtjtjdtjf}d|jtjddfS)Nz %s [%s, %s]raZ
Python %s
%s
ZterseT)rrZpython_versionZ python_buildZpython_compiler)r8)rrrr s 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 rgr!)rrnamesrrr)rrr html_index s   z _url_handler..html_indexc sgfdd}tj7tjddd}tj||d|WdQRXdd }g}jd d d }x+D]#\}}|j|||qW|jd |d ddj|}d|fS)zSearch results page.csK|dddkr*|ddd}j||o@d|fdS)Nrz .__init__z (package)z- ii)r )rr'rv) search_resultrrr9 sz3_url_handler..html_search..callbackrcSsdS)Nr)r'rrrr@ sz2_url_handler..html_search..onerrorrNcSsd||fS)Nz%sr)r(rrrrE sz4_url_handler..html_search..bltinlinkz5Search Resultsz#ffffffz#7799eezkey = %sz#ee77aaz
zSearch Results) rrrrrrr rr!) rGrrrrhrr(rvr)r)rr html_search4 s         z!_url_handler..html_searchc stjj|}tj|}j|j}WdQRXd|}jddd}|jd|dd|}d||fS) z-Get and display a source file listing safely.Nz

%s
z3File Listingz#ffffffz#7799eezFile: %sz#ee77aaz getfile %s) r+r,Zunquoterrrrrr)rfpr#Zbodyrr)rrr html_getfileR s   z"_url_handler..html_getfilecsndd}jddd}ttjj}j||}|jddd|}d|fS)zIndex of topic texts available.cSsd||fS)Nz%sr)r(rrrrb sz4_url_handler..html_topics..bltinlinkz,INDEXz#ffffffz#7799eeZTopicsz#ee77aa)rrrrrDrr)rrrr)rrr html_topics_ s   z!_url_handler..html_topicscsnjddd}ttjj}dd}j||}|jddd|}d|fS)zIndex of keywords.z,INDEXz#ffffffz#7799eecSsd||fS)Nz%sr)r(rrrrv sz6_url_handler..html_keywords..bltinlinkZKeywordsz#ee77aa)rrrrrDrr)rrrr)rrr html_keywordso s   z#_url_handler..html_keywordscstj}t||}|j|\}}||jkrHd}nd}jd|dd}dj|}j|dd|}|rt|j }dd }j ||}j d dd|}d ||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) rrrrrrrrrrrrr!)rZbufZhtmlhelprrrrr)rrrhtml_topicpage~ s&      z$_url_handler..html_topicpagecs^t|dd}|dkr6|dkr6tdt|}j||}||fS)Nrrrzcould not find object)rr]rr)r r9rcontent)rrr html_getobj s   z!_url_handler..html_getobjcspjddd}djfddtt||D}|j|dd|}d||fS) Nz,Errorz#ffffffz#7799eez
c3s|]}j|VqdS)N)r)rrw)rrrre sz3_url_handler..html_error..z#bb0000z Error - %s)rr!rrr)r rrr)rrr html_error s  z _url_handler..html_errorcs |}|jdr%|dd}y|dkrF\}}ny|dkrd\}}n[|dkr\}}n=d|kr|jd\}}}|d kr|\}}q|d kr|\}}q|d kr4y|\}}Wqtk r0|\}}YqXq|d kr|dkr^\}}qy|\}}Wqtk r|\}}YqXqtd n|\}}Wn:tk r}z||\}}WYdd}~XnXj||S)zGenerate an HTML page for url.z.htmlNrrgrrrYz search?keyz getfile?keyz topic?keyzget?keyz bad pydoc url)rrg)rrg)rbrr]rBr)r Z complete_urlrropr_r) rrrrrrrrrrr get_html_page sB           (z#_url_handler..get_html_pagerrNztext/cssrz text/htmlz"unknown content type %r for url %s) rrar rdirnamerealpathrVr!r readlinesr)r rrrZ path_hererrr) rrrrrrrrrrr _url_handlers,    **   r open_browserTcCs$ddl}tt|}|jr5t|jdS|jr d}|rZ|j|jzytd|jt|x^|jrtd}|j }|dkrPq}|dkr|j|jq}t|q}WWnt t fk rtYnXWd|jr|j tdXdS) 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) webbrowserrrrrrrr r~rrrr)rrrZ serverthreadZserver_help_msgrrrrbrowse s2            rcCs%t|to$|jtjdkS)Nr)rr-rr sep)rNrrrispath srcCsddl}Gdddt}dtjkr|tjjtjd}|tjkritjj|tjjddy|jtjddd\}}d }d }d }d}xp|D]h\} } | d krd }d }| d krt | dS| d krd }| }| dkrd }qW|r[|dkrGd}t |d|dS|sg|x|D]} t | rtjj |  rt d| Pyyt | rtjj| rt| } |r t | rtjj| rt| qt| n tj| Wqntk rL} zt | WYdd} ~ XqnXqnWWnc|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 rrrrzbk: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)getoptrBrrr rargvremoveinsertrrrexistsrrnrr rrrrrrrrr)rrZ scriptdirZoptsrZwritingZ start_serverrrZoptvalargrHrrrrcli sd %           %)rr)WrUr*rPrTrSrSZimportlib._bootstrapr~Zimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrr r0rrrrrZ urllib.parser+r collectionsrreprlibr tracebackrrrr$r)r-r/r3r IGNORECASEr4r5r:r?rCrOrerfrprxrrBrrrrrrrirjryr{rzrrrrrrrrr.rrrrr"rrrrrrrrrrrr%rrrr$s                           ' 0>*- d  !    ,        =  %  V