3 8)f1@sdZdgZdZdZdZddlZddlZddlZddl 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+dud#d$Z,d%d&Z-d'd(Z.d)d*Z/d+d,Z0ifd-d.Z1Gd/d0d0e2Z3d1d2Z4difd3d4Z5Gd5d6d6Z6Gd7d8d8eZ7Gd9d:d:e6Z8Gd;d<dd>e6Z:Gd?d@d@e:Z;dAdBadGdHZ?dIdJZ@dKdLZAdMdNZBdOdPZCdQdRZDdvdSdTZEe:ZFe;ZGe8ZHdwdUdVZIdxdXdYZJdydZd[ZKdzd\d]ZLd{d_d`ZMGdadbdbZNeNZOGdcddddZPdedfZQdgdhZRd|djdkZSd}dldmdndoZTdpdqZUdrdsZVeWdtkreVdS)~aGenerate 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_onlycCs`g}g}xRtjD]H}tjj|p d}tjj|}||krtjj|r|j||j|qW|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr/usr/lib64/python3.6/pydoc.pypathdirsLs   rcCs.tj|ptj|}|r*tjdd|jp,dS)z-Get the doc string or comments for an object.z^ * )inspectgetdocZ getcommentsresubrstrip)objectresultrrrrXsrcCsh|jjd}t|dkr&|ddfSt|dkrZ|dj rZ|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 classnamefs r)cCs>tj|p:tj|p:tj|p:tj|p:tj|p:tj| S)z>Check if an object is of a type that probably means it's data.)rismoduleisclass isroutineZisframeZ istracebackZiscode)rrrrisdatamsr-cGs2x,|r,|dj|j|d}|dd}qW|S)z/Do a series of global replacements on a string.rrrN)r!r)textZpairsrrrreplacessr/cCsXt||krTtd|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}(>+)$cCs tjd|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidr)r.rrrstripidsr5cCs(tj|p&tj|p&tj|p&tj|S)N)r isfunctionismethod isbuiltinZismethoddescriptor)objrrr_is_some_methods   r:cCs<tj|rdStj|r8t|dd}tj|p4|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?cCshi}x tj|tD]\}}d||<qWx|jD]}|jt|q.Wx|jD]}t||||<qNW|S)Nr)r getmembersr: __bases__update allmethodskeysr<)clmethodskeyvaluebaserrrrCs  rCcCs<g}g}x*|D]"}||r&|j|q|j|qW||fS)zSplit sequence s via predicate, and return pair ([true], [false]). The return value is a 2-tuple of lists, ([x for x in s if predicate(x)], [x for x in s if not predicate(x)]) )r )s predicateyesnoxrrr _split_lists  rOcCs\|dkr dS|jdr$|jdr$dS|jdrr]r[rRrTrZr&rSrVrPrUrYrQrWrXr%r\) startswithendswithhasattr)r(allr9rrr visiblenamesrecCsDg}x:tj|D],\}}}}tj|r*d}|j||||fqW|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.zdata descriptor)rclassify_class_attrsisdatadescriptorr )rresultsr(kindclsrHrrrrfs  rfc s\t|dgyfddtDWntk r>iYnXfdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namer`csi|]\}}|t|qSr)r ).0ir()fieldsrr sz#sort_attributes..csj|dd|dfS)Nr)get)attr) field_orderrrsz!sort_attributes..)rGN)r< enumerate TypeErrorsort)attrsrZkeyfuncr)rqrmrsort_attributess   rwcCs<tjj|r8x*dD]"}tjjtjj|d|rdSqWdS)z3Guess whether a path refers to a package directory..py.pyc__init__TF)rxry)r rr isfiler!)rextrrr ispackages   r}cCs|j}x,|dddks$|j r4|j}|s Pq W|j}|dddkrZ|dd}|dddkr|dd}|d ddkr|dd }x|js|j}|sPqW|jddj}nd}|S) Nr#zr"""r0z"""\rr)readlinerr)filelinerrrrsource_synopsiss&    rc Cstj|j}|j|d\}}|dks.||kr|jttjjrJtjj }n |jttjj rftjj }nd}|dkryt j |}Wntk rdSX|t|}WdQRXnZ|d|}tjjd||d}ytjj|} Wn dStjd=| jr| jjdnd}||f||<|S)z.Get the one-line summary out of a module file.NZ__temp__)loaderr)NN)r statst_mtimerorbtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrmodulesrU splitlines) filenamecachemtimeZ lastupdaterZ loader_clsrrspecmodulerrrsynopsiss4      rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dS)N)rexcrHtb)r>rexc_inforrrrz#szErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr%rrH)r>rrrr__str__'szErrorDuringImport.__str__N)r%r&r[rUrzrrrrrr!src Cstjj}t|d}||jt|k}WdQRXtjj|}tjj |\}}|r`tj j ||}ntj j ||}tjj |||d}y tjj|St|tjYnXdS)zQszsafeimport..Nrr)rrbuiltin_module_names __import__rrrV SyntaxErrorr issubclass ImportErrorr(rr<AttributeError) r forceloadrZsubsrGrrrHrinfopartr)rr safeimport=s.     rc@s|eZdZejjddejddZd ddZ dddZ e Z Z Z ZZZejjejd d ejddfd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrc Gs||f|}tj|r |j|Stj|r4|j|Sy@tj|rJ|j|Stj|r^|j|Stj|rr|j |SWnt k rYnXt |t r|j |S|j|S)z%Generate documentation for an object.)risgetsetdescriptordocdataismemberdescriptorr* docmoduler+docclassr, docroutiner isinstanceproperty docpropertydocother)r>rr(argsrrrdocumentss"       z Doc.documentcGs*d|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%rt)r>rr(rmessagerrrfailszDoc.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 getabsfilertr environrorrr rrr%rar!rlower)r>rZbasedirrdoclocrrr getdoclocs$     z Doc.getdocloc)N)N)r%r&r[r rror version_inforrrrrrrrrrr!base_exec_prefixrrrrrrms   rc@sHeZdZdZddZddZddZdd 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)rrzmaxlistmaxtuplemaxdict maxstringmaxother)r>rrrrzs  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)r/)r>r.rrrescapeszHTMLRepr.escapecCs tj||S)N)rr)r>rrrrrsz HTMLRepr.reprcCsZtt|dr@ddjt|jj}t||r@t||||S|jttt ||j S)Nr%repr_r_) rcrr!r%rr<rr3r5rr)r>rNlevel methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|krJdt|ddkrJd|d|j||dStjdd|j|S)Nrz\\rrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r3rrr/rrr)r>rNrtesttestreprrrr repr_strings zHTMLRepr.repr_stringc Cs8y|jttt||jS|jd|jjSdS)Nz <%s instance>)rr3r5rr __class__r%)r>rNrrrr repr_instanceszHTMLRepr.repr_instanceN) r%r&r[rUrzrrrrrepr_strrZ repr_unicoderrrrrs rc@seZdZdZeZejZejZddZd5ddZ d6d d Z d d Z ddZ d7ddZ ddZddZddZddZddZddZdiiifdd Zd8d!d"Zd9d#d$Zddiifd%d&Zd'd(Zddiiidfd)d*Zd+d,Zd:d-d.Zd;d/d0ZdHTMLDocz'Formatter class for HTML documentation.cCs d||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.headingN c Cs^|dkrdd|d}d|||f} |r@| 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 marginaliaZgaprrrrsectionszHTMLDoc.sectioncGsd|}|j|f|S)z$Format a section with a big heading.z%s)r)r>rrrrr bigsection szHTMLDoc.bigsectionc Cs&|j|j}t|dddddddd S)z!Format literal preformatted text.z z rz rz
)r expandtabsr/)r>r.rrr preformats zHTMLDoc.preformatrcCsd}t||d|}xht|D]\}|dd|}x>t|||||D]$}|t|krN||||d}qNW|d}q"Wd|S)z0Format a list of items into a multi-column list.rrzrz
zz7%s
)r range)r>listformatZcolsrrowscolrlrrr multicolumns  zHTMLDoc.multicolumncCsd|S)Nz%sr)r>r.rrrgrey sz HTMLDoc.greycGs*x$|D]}||krd|||fSqW|S)z:Make a link for an identifier, given name-to-URL mappings.z%sr)r>r(Zdictsdictrrrnamelink"s zHTMLDoc.namelinkcCsN|jtjj|j}}t||rDt|||krDd|j|t||fSt||S)zMake a link for a class.z%s)r%rrror&rcr<r))r>rr'r(rrrr classlink)s zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.z%s)r%)r>rrrr modulelink1szHTMLDoc.modulelinkcCsR|\}}}}|r|j|S|r,d||f}nd|}|rBd|}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(rr}shadowedurlr.rrr modpkglink5s   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%sr)r>rrrrrfilelinkDszHTMLDoc.filelinkcCs|p|j}g}d}tjd}xL|j||} | s2P| j\} } |j|||| | j\} } }}}}| r|| jdd}|jd||fn|rdt|}|jd||| fn|rdt|}|jd||| fn|r$|| | dd kr|jd |j ||n|jd |n@|| | dd krR|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(rrrrmarkupHs<      zHTMLDoc.markupc Csd}x|D]}t|tfkr|\}}|d}||j||}|r||fkrg}x|D]} |j|j| |qVW|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'parentrentrycbasesparentsrIrrrr(ss    zHTMLDoc.formattreec#s|j}y |j}Wntk r(d}YnX|jd}g}x@tt|dD],}|jddj|d|d||fqJWdj||d.d} d| } y&tj |} t j j | } j | | } Wntk rd} YnXg}t|dr:t|j}|ddd/kr&|d0dd kr&|dd1j}|jd j|t|d r\|jjt|j|rt| d dj|} j|}|dk rdt}nd}j| ddd| |}tj|tj}gi}}xltj|tjD]Z\}}|dk stj|p||krt|||r|j||fd|||<||<qWx|D]\}}xx|jD]n}|j|j}}tj j!|}||krL|rLt||rLt"|||krL||krL|d|||<||<qLWq%sz)%sz (built-in)r] $z Revision: z version %srTz (%s)z, z-
Module Referencerz#ffffffz#7799eezindex
r~z.html#z#-z %sz

%s

rZrzPackage Contentsz#aa55cccsj|dS)Nr)r)t)r>rrrrsz#HTMLDoc.docmodule..ModulescSsg|] \}}|qSrr)rkrGrHrrrrsz%HTMLDoc.docmodule..ZClassesz#ee77aarZ Functionsz#eeaa77ZDataz#55aa55z
rPZAuthorrSZCreditsrz $Revision: rr)6r%__all__rrrr r r!rrurllibparseZquoterrtrcstrr]rrrTrlocalsrr@r*r+ getmodulererAr&rrror<r,r8r6r-r&rrpkgutil iter_modulesrZrur rrr( getclasstreerrPrS)#r>rr(modignoredrdpartsZlinksrlZ linkednameheadrrrrversionrrrrZcdictrGrHrIr'rrZfdictdatar"modpkgsimporterispkgr classlistr)r>rrs   &     $         $        zHTMLDoc.docmodulecsj}|p |}j}g} | jGfddd} | ttj} t| dkrjdx"| D]} dj| j qfWdfdd} fd d }fd d }fd dt D}ixv|D]n\}}}}d|d||<}yt |}Wnt k r:YnXy ||<Wqt k r^YqXqWx|rT| r|| jn |ddt|fdd\}}tjkr|}qfn"krd}ndjj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|}qfWd!j| } ||krxd"||f}nd#|||f}|rg}x"|D]} |jj| j qW|d$d%j|}jtj}|od&|}j|d'd(| d)|S)*z.Produce HTML documentation for a class object.cs eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecSs d|_dS)Nr)needone)r>rrrrz sz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
r)rF)r>)pushrrmaybe sz.HTMLDoc.docclass..HorizontalRule.maybeN)r%r&r[rzrHr)rGrrHorizontalRule srIrz&
Method resolution order:
z
%s
z
cst||\}}|rj|xl|D]d\}}}}yt|}Wn&tk rhj||YnXj||dq(W|S)Nr)rOrHr< Exception_docdescriptorr)msgrvrKokr(rihomeclsrH)rrhrmdictr<rrGr>rrspills  zHTMLDoc.docclass..spillcsNt||\}}|rJj|x&|D]\}}}}j||q(W|S)N)rOrHrK)rLrvrKrMr(rirNrH)rOr<rGr>rrspilldescriptors/sz*HTMLDoc.docclass..spilldescriptorsc st||\}}|rj|x|D]\}}}}jt||}t|sZtj|rht|dd} nd} | dkrd|n0jt|j } d| } d|| fdq(W|S)NrUz
%s
z
%sz
%s%s
r) rOrHrr<callablerrgr&rr) rLrvrKrMr(rirNrHrIr")rrrOrPr<rrGr>rr spilldata8s"  z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS))r9)re)rkr(rirjrH)rrrrMs z$HTMLDoc.docclass..r~-rcs |dkS)Nrr)r1) thisclassrrrrfsz"HTMLDoc.docclass..z defined herezinherited from %sz:
z Methods %scSs |ddkS)Nrmethodr)r1rrrrrvszClass methods %scSs |ddkS)Nrz class methodr)r1rrrrrxszStatic methods %scSs |ddkS)Nrz static methodr)r1rrrrrzszData descriptors %scSs |ddkS)Nrzdata descriptorr)r1rrrrr|szData and other attributes %scSs |ddkS)NrrAr)r1rrrrr~srz*class %sz/%s = class %sz(%s)z, z%s
 
z#000000z#ffc8d8r0)r%rAr rrgetmror rHrr&rfr<rJrtpopleftrObuiltinsrrwr!r&rrr)r>rr(r<rrr=realnamer-rrImrorIrQrRrTrvrGrirNrHanchor inheritedtagrr.r"r) rrrOrPr<rrGr>rVrrs                              zHTMLDoc.docclasscCs|jd|j|S)z)Format an argument default value as text.=)rr)r>rrrr formatvalueszHTMLDoc.formatvaluecCs|j}|p |}|r|jpdd|} d} d} t|r|jj} |rZ| |k rd|j| |} n0|jdk rzd|j|jj|} nd|j| |} ||krd| |f} nD|rtj||g|krd |jd||f}d } n|}d | ||f} d}tj|rNytj|}Wnt t fk r d}YnX|rNt |}|d krNd |} |d d}|sXd}| |j || ov|j d| }| rd|S|jt||j|||}|od|}d||fSdS)z;Produce HTML documentation for a function or method object.rrUrz 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;rrrgetattr_staticr, signature ValueErrorrtr6rrr&rr)r>rr(r<rrrFrEr[r]noteskipdocsimclassrZreallinkargspecrcdeclr"rrrrsX       zHTMLDoc.docroutinecCsTg}|j}|r|d||jdk rB|jt||j}|d||ddj|S)Nz!
%s
z
%s
z
r)r rUr&rrr!)r>r(rHr<rhrGr"rrrrKs   zHTMLDoc._docdescriptorcCs|j|||S)z*Produce html documentation for a property.)rK)r>rr(r<rErrrrszHTMLDoc.docpropertycGs|r d|pd}||j|S)z-Produce HTML documentation for a data object.z%s = r)r)r>rr(r<r=ZlhsrrrrszHTMLDoc.docothercCs|j|||S)z1Produce html documentation for a data descriptor.)rK)r>rr(r<rErrrrszHTMLDoc.docdatacCsg}|dkri}xLtj|gD]<\}}}tdd|Drsz HTMLDoc.index..rrz#ffffffz#ee77aa)r9r:anyr rur rr)r>rrrBrCr(rDrrrrindexs z HTMLDoc.index)r)rrNr)r)N)NN)NNN)NN)NNN)N)r%r&r[rUr_repr_instancerrrrrrrr rrrrrrr&r(rrrarrKrrrrnrrrrrs<   +  y:   rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,tj|d|_|_d|_d|_|_dS)Nrrr)rrzrrrrr)r>rrrrzs  zTextRepr.__init__cCsTtt|dr@ddjt|jj}t||r@t||||Sttt||j S)Nr%rr_) rcrr!r%rr<r3r5rr)r>rNrrrrrrs  zTextRepr.repr1cCsHt||j}t|}d|krDdt|ddkrDd|d||dS|S)Nrz\\rrr)r3rrr/)r>rNrrrrrrr s  zTextRepr.repr_stringc Cs,yttt||jSd|jjSdS)Nz <%s instance>)r3r5rrrr%)r>rNrrrrrszTextRepr.repr_instanceN) r%r&r[rUrzrrrrrrrrrps  rpc@seZdZdZeZejZddZdddZddZ dd d Z dd dZ d ddZ ddZ d!ddZddZd"ddZd#ddZd$ddZd S)%TextDocz'Formatter class for text documentation.cCsdjdd|DS)z(Format a string in bold by overstriking.rcss|]}|d|VqdS)Nr)rkrkrrrrl(szTextDoc.bold..)r!)r>r.rrrbold&sz TextDoc.bold cs>|sdSfdd|jdD}|r4|dj|d<dj|S)z6Indent text by prepending a given prefix to each line.rcsg|] }|qSrr)rkr)prefixrrr-sz"TextDoc.indent..rrrr)rrr!)r>r.rur#r)rurindent*s zTextDoc.indentcCs$|j|j}|j|d|dS)z&Format a section with a given heading.rz )rvrrs)r>rrZclean_contentsrrrr1szTextDoc.sectionNrc sd}x|D]}t|tfkrt|\}}||t|}|rj||fkrjfdd|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))rkr,)r'rrrl@sz%TextDoc.formattree..z(%s)z, rz )rr)r!r() r>r)r'r*rurr+r,r-r.r)r'rr(8s  zTextDoc.formattreec CsD|j}tt|\}}|jd||o(d|}t|dd}|j|}|dk r`||jd|d}|rt||jd|}g} xNtj|tjD]<\} } |dk stj | p||krt | ||r| j | | fqWg} xXtj|tj D]F\} } |dk stj | stj | |krt | ||r| j | | fqWg} x6tj|tD]&\} } t | ||r8| j | | fq8Wg}t}t|drxFtj|jD]6\}}}|j||r|j |d n |j |qW|j||jd d j|}g}xBtj|tjD]0\} } | jj|d r| |kr|j | qW|rJ|j||jd d j|}| rdd| D}|jtj|d|g}x&| D]\} } |j |j| | |qzW||jdd j|}| rg}x&| D]\} } |j |j| | |qW||jdd j|}| rFg}x*| D]"\} } |j |j| | |ddq W||jdd j|}t|drt|j}|ddd#kr|d$ddkr|dd%j}||jd|}t|dr||jdt|j }t|dr||jdt|j!}t|dr||jd t|j"}ytj#|}Wnt$k r.d!}YnX||jd"|}|S)&z5Produce text documentation for a given module object.NAMEz - r3NzMODULE 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)rkrGrHrrrrsz%TextDoc.docmodule..rCLASSES FUNCTIONSF)r2ZDATAr]r/r0z Revision: VERSIONrTZDATErPZAUTHORrSZCREDITSz (built-in)FILEz $Revision: rr)%r%r$rrr<rrr@r+r8rer r,r8r-setrcr9r:rZaddrur!r*rar(r;rrr6r]rrTrPrSrrt)r>rr(r<ZsynopdescrrdrrrGrHrrArBZ modpkgs_namesrCr'rDZ submodulesrErr@rrrrrHs           $    zTextDoc.docmodulecsXj}|p |}j}jfdd}||kr:dj|}nj|d|}|rlt||} |ddj| }t} | r| dgpg} | jtt j } t | dkrԈd x| D]} d || qWd Gfd d d }|fdd}fdd}fdd}fddt D}x|r"| rT| j n |ddt|fdd\}}tjkr|}q>n krd}ndtj}t||d||dd}|d||dd}|d||d d}|d!||d"d}|d#||d$d}|}q>Wdj| } | 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)rF)r>rrrrzsz1TextDoc.docclass..HorizontalRule.__init__cs|jrddd|_dS)NrUrzr)rF)r>)rGrrrHs z.TextDoc.docclass..HorizontalRule.maybeN)r%r&r[rzrHr)rGrrrIsrIcst||\}}|rj|x^|D]V\}}}}yt|}Wn&tk rhj||Yq(Xj||q(W|S)N)rOrHr<rJrKr)rLrvrKrMr(rirNrH)rOr<rrGr>rrrQszTextDoc.docclass..spillcsNt||\}}|rJj|x&|D]\}}}}j||q(W|S)N)rOrHrK)rLrvrKrMr(rirNrH)rOr<rGr>rrrRsz*TextDoc.docclass..spilldescriptorsc st||\}}|rj|x~|D]v\}}}}t|sFtj|rPt|}nd}yt|} Wntk r|j|} YnXj | |d|ddq(W|S)Nrz)r2r"r) rOrHrSrrgrr<r__dict__r) rLrvrKrMr(rirNrHr"r9)rOr<rrGr>rrrTs  z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS))r9)re)rkr(rirjrH)rrrrs z$TextDoc.docclass..rcs |dkS)Nrr)r1)rVrrrr sz"TextDoc.docclass..z defined herezinherited from %sz Methods %s: cSs |ddkS)NrrWr)r1rrrrrszClass methods %s: cSs |ddkS)Nrz class methodr)r1rrrrrszStatic methods %s: cSs |ddkS)Nrz static methodr)r1rrrrrszData descriptors %s: cSs |ddkS)Nrzdata descriptorr)r1rrrrrszData and other attributes %s: cSs |ddkS)NrrAr)r1rrrrr sz | )r%rAr&rsmapr!rr rrrXr rfrYrOrZrr)rwrvr)r>rr(r<r=r[r-rrr.r"rr\rIrIrQrRrTrvr^r_r)rOr<rrGr>rVrrsl                        zTextDoc.docclasscCsd|j|S)z)Format an argument default value as text.r`)r)r>rrrrra*szTextDoc.formatvaluec Csr|j}|p |}d}d}t|rn|jj}|rB||k rndt||}n,|jdk r`dt|jj|}ndt||}||kr|j|} n,|rtj||g|krd}|j|d|} d} tj|rytj |} Wnt t fk rd} YnX| rt | } |d kr|j|d } | dd } | s&d } | | |} |r@| d St |pLd} | d | oj|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)rsrrbr,rcrdrtr6rrvr)r>rr(r<rEr[rerfrgrrhrcrir"rrrr.sH       zTextDoc.docroutinecCsTg}|j}|r$||j||dt|p.d}|rJ||j||ddj|S)Nrr)r rsrrvr!)r>r(rHr<rhrGr"rrrrK_s zTextDoc._docdescriptorcCs|j|||S)z*Produce text documentation for a property.)rK)r>rr(r<rErrrrlszTextDoc.docpropertycCs|j|||S)z1Produce text documentation for a data descriptor.)rK)r>rr(r<rErrrrpszTextDoc.docdatac Cs|j|}|rF|r|dpd|}|t|} | dkrF|d| d}|rX|j|dpZd|}|dk r~|d|jt|7}|S)z-Produce text documentation for a data object.z = rrNz...r)rr rsrvr6) r>rr(r<r*r2r"rrZchoprrrrts  zTextDoc.docother)rt)Nr)NN)NN)NNN)NNN)NNN)NNNNN)r%r&r[rUrprorrsrvrr(rrrarrKrrrrrrrrqs   e } 1  rqc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|S)Nr)r>r.rrrrssz_PlainTextDoc.boldN)r%r&r[rUrsrrrrrsrcCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpager)r.rrrrsrc s<ttjdstSttjds tStjj s8tjj r.ZTERMdumbemacscstt|S)N) pipepagerr)r.)rrrrrscs t|S)N)r)r.)rrrrrscSstt|dS)Nzmore <)rr)r.rrrrrssystemz(less) 2>/dev/nullrcSs t|dS)NZless)r)r.rrrrrsNz more "%s"cSs t|dS)NZmore)r)r.rrrrrs)rr)rr)rcrstdin plainpagerstdoutrr rroplatformrtempfileZmkstempclosettypagerunlink)rfdrr)rrrs6          rcCstjdd|S)z%Remove boldface formatting from text.z.r)rr)r.rrrrsrc Csddl}|j|d|jd}yDtj|jdd*}y|j|Wntk rPYnXWdQRXWntk rrYnXx(y|j PWqvtk rYqvXqvWdS)z3Page through text by feeding it to another program.rNT)shellrbackslashreplace)errors) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)r.cmdrprocpiperrrrs rcCs`ddl}|j}t|ddd}|j|WdQRXztj|d|dWdtj|XdS)z.cSstjjddddS)Nrr)rrrrrrrrrsZLINESrz -- more --qQz  bB)rr)rr)rrr)rrrttyrrfilenoZ tcgetattrZ setcbreakrrrUnsupportedOperationrr rrordrrr!flushZ tcsetattrZ TCSAFLUSH) r.r#rroldZgetcharhrZincr,rrrrsL              &rcCstjjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrr)r.rrrrsrcCstj|r>|jtjkr d|jSt|dr4d|jSd|jStj|rRd|jStj|rtd|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)thingrrrdescribe s.                    rc Csdd|jdD}d\}}xB|t|kr^tdj|d|d|}|rZ||d}}qPqW|rj|}nt}x8||dD](}yt||}Wq|tk rdSXq|W|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|] }|r|qSrr)rkrrrrr'szlocate..rNrr)Nr)rr rr!rZr<r)rrr>rnZ nextmodulerrrrrlocate%s  rcCsVt|tr0t||}|dkr(td|||fSt|dd}|t|trL|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%)rr6rrr<)rrrr(rrrresolve>s    r Python Library Documentation: %scCs|dkr t}t||\}}t|}tj|}|rTd|krT|d|d|jd7}n|rn||k rn|d|j7}tj|ptj|ptj |ptj |ptj |pt |t st|}|d7}||d|j||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module z objectz )r.rrrr8rfindr%r*r+r,rrrrrr)rrrZrendererrr(rrrrr render_docLs$         rcCsfy2|dkrtt|||n|jt|||tWn.ttfk r`}zt|WYdd}~XnXdS)zCDisplay text documentation, given an object or a path to an object.N)rrr plaintextrrprint)rrroutputrHrrrr"es r"cCsy`t||\}}tjt|tj||}t|dddd}|j|WdQRXtd|dWn.tt fk r}zt|WYdd}~XnXdS)zd?d@ddAdBd d!dd dCdDdEdFdʜIZ dGdd̈́Z eddτZeddτZdd҄ZeZefddԄZddքZdd؄ZddڄZdd܄ZdHddZddZddZddZdIddZdJddZddZdKddZ dS(LHelperrBOOLEANwithassertbreak while forclassCLASSES SPECIALMETHODScontinuefunctiondel BASICMETHODSifelsetryforbreak continue whileimportglobalnonlocal NAMESPACES TRUTHVALUEMODULESinSEQUENCEMETHODS COMPARISONlambdarynonlocalglobal NAMESPACESpassraise EXCEPTIONSreturnwhilebreak continue if TRUTHVALUE CONTEXTMANAGERS EXCEPTIONS yieldyield)!FalseNoneTrueandasrrrrdefrelifrexceptfinallyrfromrrrrisrrnotorrrrrrrrcCsg|]}dD] }||q qS)'r)rrr)rkprrrrrszHelper.rfrur'''r"""+rU***r//%<<>>r|^~rr<=>===!=<>+=-=*=/=%=&=|=^=<<=>>=**=//=jJ)STRINGS OPERATORSrUNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classr PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rz**,rz...:@rr_r^`rr'[]rtypesRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspectstrings4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPESstring-methodsSTRINGS FORMATTING formatstringsr:encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPESnumbersINTEGER FLOAT COMPLEX TYPESintegers int rangefloating float math imaginary complex cmathtypesseq$STRINGMETHODS FORMATTING range LISTS DICTIONARIEStypesfunctions def TYPES typesmethodsclass def CLASSES TYPESbltin-code-objectscompile FUNCTIONS TYPESbltin-type-objects types TYPESTYPESbltin-null-objectbltin-ellipsis-objectSLICINGS specialattrs!class SPECIALMETHODS PRIVATENAMES typesmodulesoperator-summarylambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIES EXPRESSIONSobjects specialnamesbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES customizationhash repr str SPECIALMETHODSattribute-accessATTRIBUTES SPECIALMETHODScallable-typesCALLS SPECIALMETHODSsequence-types(SEQUENCES SEQUENCEMETHODS SPECIALMETHODSMAPPINGS SPECIALMETHODS numeric-types*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS execmodel%NAMESPACES DYNAMICFEATURES EXCEPTIONSnaming3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURESdynamic-features NAMESPACESrtry except finally raise conversions identifierskeywords SPECIALIDENTIFIERS id-classesatom-identifiers atom-literals=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALS SEQUENCES exprlistsTUPLES LITERALStypesseq-mutable LISTLITERALSlistsLISTS LITERALS typesmappingDICTIONARYLITERALSrDICTIONARIES LITERALSattribute-references(getattr hasattr setattr ATTRIBUTEMETHODS subscriptionsslicingscallspowerunarybinaryshiftingbitwise comparisonsEXPRESSIONS BASICMETHODSbooleansEXPRESSIONS TRUTHVALUE assignmentr  augassign NUMBERMETHODScompoundfor while break continuetruth if while and or not BASICMETHODSdebuggerpdbcontext-managers)IrGrZ STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERZFLOATr"rmZMAPPINGSryZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSZNONEr$ZSPECIALATTRIBUTESrxrZPACKAGESrPrZ PRECEDENCEZOBJECTSZSPECIALMETHODSrZATTRIBUTEMETHODSZCALLABLEMETHODSrZMAPPINGMETHODSrZ EXECUTIONrdZDYNAMICFEATURESZSCOPINGZFRAMESrZ CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSr%ZLITERALSZTUPLESZ TUPLELITERALSZLISTSrqr>ruZ ATTRIBUTESZ SUBSCRIPTSrJZCALLSr#rZBINARYZSHIFTINGr!rrZ ASSERTIONZ ASSIGNMENTr ZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGrZ DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dS)N)_input_output)r>inputrrrrrz/szHelper.__init__cCs |jp tjS)N)rrr)r>rrrrr3szHelper.cCs |jp tjS)N)rrr)r>rrrrr4scCs2tjdddkr|dSd|jj|jjfS)Nrr0?rz<%s.%s instance>)rstackrr&r[)r>rrr__repr__6s zHelper.__repr__cCs6||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__>s   zHelper.__call__c Cs|jjdxy|jd}|s PWnttfk r<PYnX|j}t|dkr|d|d kold knr|d|dd kr|dd}|jdkrP|d kr|jq|j |qWdS)Nrzhelp> rrrrrrquitrr)rrrr)rr) rrgetlinerEOFErrorrr rrr)r>rrrrrKs"  ,   zHelper.interactcCs8|jtjkrt|S|jj||jj|jjSdS)z.Read one line, using input() when appropriate.N)rrrrrrr)r>promptrrrr`s    zHelper.getlinecCs<t|tdkr|j}|dkr,|jn|dkr>|jn|dkrP|jn|dkrb|jn|dddkr|j|jdn||jkr|j|nj|dkrt t |d nR||j kr|j |n<||j kr|j |n&|rt |d |jd nt td |jd n$t|tr|nt |d |jd |jjddS)Nrkeywordssymbolstopicsrzmodules rrrrz Help on %s:)rr)rrr)rr listkeywords listsymbols listtopics listmodulesrr showsymbolr"evalr showtopicrrr6rrrr)r>rrrrris6        z Helper.helpcCs$|jjdjdtjdddS)Na Welcome to Python {0}'s help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at https://docs.python.org/{0}/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". z%d.%dr)rrr rr)r>rrrr~sz Helper.introrPc Cstt|}||}t||d|}xt|D]z}xht|D]\}|||}|t|kr@|jj||||dkr@|jjdd|dt||q@W|jjdq2WdS)Nrrr)r sortedr rrr) r>itemscolumnsrZcolwr rowr rlrrrr s    (z Helper.listcCs |jjd|j|jjdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrr rrD)r>rrrrszHelper.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>rrrrszHelper.listsymbolscCs |jjd|j|jjdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrr rrD)r>rrrrszHelper.listtopicsc Cs,y ddl}Wn tk r,|jjddSX|jj||jj|}|s`|jjdt|dSt|tdkr||j ||S|\}}y|jj|}Wn(t k r|jjdt|dSX|j d}|r|pdd|}|r ddl }ddj |jd} |j| d } |d dj | 7}t|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.topicsrrrrrorrrrKeyErrorrtextwrapr!rZwrapr) r>topic more_xrefs pydoc_datatargetlabelxrefsr"rr.Z wrapped_textrrrrs6    zHelper.showtopicc Csy ddl}Wntk r dSX|jj||jj|}|sDtdt|trZ|j||S|\}}|jj|}|r|pxdd|}||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) rrrrorrdrr6 _gettopic)r>rrrrrrr"rrrrs     zHelper._gettopiccCs*|j|}|jd\}}}|j||dS)Nr)r partitionr)r>symbolrrr_rrrrrs zHelper.showsymbolcsv|r |jjdj|t|nR|jjdi}|fddfdd}tj|d|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... cSs>|r$|dddkr$|ddd}|jddkr:d||<dS) N z .__init__z (package)rrrii)find)rr'rrrrrcallbacksz$Helper.listmodules..callbackcsd|ddS)Nr)r')rrronerrorsz#Helper.listmodules..onerror)rz 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)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rry)rr)rr)rr)rry)rr)rr)rr)rr)rrrr)rrrr)rrUrrrrrrrrrrr rrr r r r r)rrr r r r r)rUr ) rrrrrrrrrrrr)rrrrrr )rr)r,r-)r.r/)r0r1)r2r)r.r3)r4r5)r6r7)r8r9)r:r;)r<r=)r?r@)rArB)rCrD)rErF)rHr)rIrJ)rKr)r,rL)rMr)rNrO)rQrG)rRrS)rTrU)rVrW)rXrY)rZr[)rZr\)r]r^)r_r`)rarb)rcr)rre)rfr)rgrh)rir)rjr)rkrl)rnro)rprq)rrrs)rtru)rrv)rwrx)ryr)rzr)r{rP)r|rP)r}rP)r~rP)rrP)rrP)rr)rr)rr )rr)rr)rr)rr)rr)NN)rr)r)r)r)!r%r&r[rZ _strprefixesZ_symbols_inverserrrZsymbols_rrorrzrrrrrrrrrrrr rrrrrrrrrrrrs6              rc@seZdZdZdddZdS)rz7An interruptible scanner that searches module synopses.NcCs |r |j}d|_i}xztjD]p}|dkrd||<|dkrH|d|dqt|jpTd}|jdd}|d|}|jj|dkr|d||qWxdtj |dD]R\} }} |jrP|dkr|d|dqytj | |} Wnt k rwYnX| j } t | d rny| j|} Wn&tk r:|r4||wYnXttj| pNd}t | d rh| j|}nd}n^ytjj| }Wn&tk r|r||wYnX|jr|jjdnd}t|d d}|d|}|jj|dkr||||qW|r|dS) NF__main__rrrrz - )r get_source get_filenamerV)rrrrrrUrrr9r _get_specrrrcrrJrrStringIOrrrrrrr<)r>rrGZ completerrseenr'r(rrCrDrrsourcerrrrrrs`       zModuleScanner.run)NNN)r%r&r[rUrrrrrrsrc CsDdd}dd}tj"tjdtj|||dWdQRXdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dS)Nrz .__init__z (package)z- ii)r)rr'rrrrrOszapropos..callbackcSsdS)Nr)r'rrrrSszapropos..onerrorignore)rN)warningscatch_warningsfilterwarningsrr)rGrrrrrrMs   rcsddlddlddlddlGdddjjGfdddjjGfdddj}|||}|jx|j r|j rt j d q~W|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@seZdZddZddZdS)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 DocHandlersrcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6d|_|j|f|_||_|jj||j|jd|_dS)NZ localhostF)hostZaddressrrIrzhandlerr)r>portrrrrrzs  z)_start_server..DocServer.__init__csBx4|js4j|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[rzrrr)rrr DocServers rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs,||_t||_jj|d|_d|_dS)NF)rrrThreadrzservingerror)r>rr) threadingrrrzs   z,_start_server..ServerThread.__init__cstyFjj__jj_t|j_|j |j }||_ |j Wn(t k rn}z ||_WYdd}~XnXdS)zStart the server.N)server HTTPServerrIrrZMessageZ MessageClass staticmethodrrready docserverrrJr)r>Zdocsvre)rremailhttprrrs    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr)r>rrrrrsz)_start_server..ServerThread.readycSs&d|j_|jd|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrr!rr)r>rrrstops z(_start_server..ServerThread.stopN)r%r&r[rzrrrr)rrrrrrr ServerThreads  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrr#rrtimeZsleep)rrrZthreadr)rrrrrrr _start_server[s8& r text/htmlc s*Gfdddt}|fddfddfddfd d fd d  fd dfddfddfdd f dd}|jdr|dd}|dkrtjjtjjt}tjj||}t|}dj|j SQRXn|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.._HTMLDoccsd}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.pagecSs d||fS)Nz%sr)r>rrrrrr sz'_url_handler.._HTMLDoc.filelinkN)r%r&r[rrr)rrr_HTMLDocs rcs>jdtjtjdtjf}d|jtjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)Zterse)rrZpython_versionZ python_buildZpython_compiler)r@)rrrr s  z!_url_handler..html_navbarcsdd}jddd}ddtjD}j||}|djd dd |g}i}x tjD]}|jj||qVW|jd d d j|fS)zModule Index page.cSs d||fS)Nz%sr)r(rrr bltinlink. sz3_url_handler..html_index..bltinlinkz7Index of Modulesz#ffffffz#7799eecSsg|]}|dkr|qS)rr)rkr(rrrr4 sz4_url_handler..html_index..z

zBuilt-in Modulesz#ee77aaz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr) rrrr rrr rnr!)rrnamesrrr)rrr html_index+ s  z _url_handler..html_indexc sgfdd}tj*tjddd}tj|||dWdQRXdd }g}jd d d }x"D]\}}|j|||qhW|jd |d ddj|}d|fS)zSearch results page.cs:|dddkr |ddd}j||o0d|fdS)Nrz .__init__z (package)z- ii)r )rr'r) search_resultrrrI sz3_url_handler..html_search..callbackrcSsdS)Nr)r'rrrrP sz2_url_handler..html_search..onerror)rNcSs d||fS)Nz%sr)r(rrrrU sz4_url_handler..html_search..bltinlinkz5Search Resultsz#ffffffz#7799eezkey = %sz#ee77aaz
zSearch Results) rrrrrrr rr!) rGrrrrhrr(rr)r)rr html_searchD s    z!_url_handler..html_searchc sjtjj|}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) r4r5Zunquoterrrrrr)rfpr#Zbodyrr)rrr html_getfileb s  z"_url_handler..html_getfilecsLdd}jddd}ttjj}j||}|jddd|}d|fS)zIndex of topic texts available.cSs d||fS)Nz%sr)r(rrrrr sz4_url_handler..html_topics..bltinlinkz,INDEXz#ffffffz#7799eeZTopicsz#ee77aa)rrrrrDr r)rrrr)rrr html_topicso s z!_url_handler..html_topicscsLjddd}ttjj}dd}j||}|jddd|}d|fS)zIndex of keywords.z,INDEXz#ffffffz#7799eecSs d||fS)Nz%sr)r(rrrr sz6_url_handler..html_keywords..bltinlinkZKeywordsz#ee77aa)rrrrrDr r)rrrr)rrr html_keywords s z#_url_handler..html_keywordscstj}t||}|j|\}}||jkr0d}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#ee77aacSs d||fS)Nz%sr)r(rrrr sz7_url_handler..html_topicpage..bltinlinkzRelated help topics: z%s %sr) rrrrrrr&rrrr rr!)rZbufZhtmlhelprrrrr)rrrhtml_topicpage s&      z$_url_handler..html_topicpagecs@t|dd}|dkr$|dkr$tdt|}j||}||fS)Nr)rrzcould not find object)rrdrr)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)rkr)rrrrl sz3_url_handler..html_error..z#bb0000z Error - %s)rr!rrr)rrrr)rrr html_error s z _url_handler..html_errorcs|}|jdr|dd}y2|dkr4\}}n|dkrJ\}}n|dkr^\}}nd|kr@|jd\}}}|d kr|\}}n|d kr|\}}n|d kry|\}}Wn tk r|\}}YnXn^|d kr6|dkr\}}n4y|\}}Wn"tk r2|\}}YnXntd n |\}}Wn2tk r}z||\}}WYdd}~XnXj||S)zGenerate an HTML page for url.z.htmlNrrnrrr`z search?keyz getfile?keyz topic?keyzget?keyz bad pydoc url)rrn)rrn)rbrrdrJr)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) rrar rdirnamerealpathrVr!r readlinesrt)rrrrZ path_hererrr) rrrrrrrrrrr _url_handlers,         *     rT) open_browsercCsddl}tt|}|jr&t|jdS|jrd}|r@|j|jzy^td|jt|xD|jrtd}|j }|dkr|PqZ|dkr|j|jqZt|qZWWnt 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) webbrowserrrrrrrrrrrrr)rrrZ serverthreadZserver_help_msgrrrrbrowse s2    rcCst|to|jtjdkS)Nr)rr6rr sep)rNrrrispath sr cCsddl}Gdddt}dtjkrXtjjtjd}|tjkrJtjj|tjjddyp|jtjddd\}}d }d }d }d}xP|D]H\} } | d krd }d }| d krt | dS| d krd }| }| dkrd }qW|r|dkrd}t ||ddS|s|x|D]} t | r4tjj |  r4t d| Py`t | rVtjj| rVt| } |rt | r~tjj| r~t| nt| n tj| Wn,tk r} zt | WYdd} ~ XnXqWWnN|j|fk rtjjtjjtjdd} t dj| tjdYnXdS)z@Command-line interface (looks at sys.argv to decide what to do).rNc@s eZdZdS)zcli..BadUsageN)r%r&r[rrrrBadUsage sr rrrzbk:p:wFz-bTz-kz-pz-w)rzfile %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 )getoptrJrrr rargvremoveinsertrrr existsrr{rr rrrrrrrr r )r r Z scriptdirZoptsrZwritingZ start_serverrroptvalargrHrrrrcli sd        $rr)NN)r)r)rrN)rrN)r)rN)r)r)XrUr3rPrTrSrZZimportlib._bootstraprZimportlib._bootstrap_externalZimportlib.machineryimportlib.utilrrr r9rrrrrZ urllib.parser4r collectionsrreprlibr tracebackrrrr$r)r-r/r3r IGNORECASEr4r5r:r?rCrOrerfrwr}rrrJrrrrrrrprqrrrrrrrrrrrr.rrrrr"rrrrrrrrrr rr%rrrr#s           ' 0>*- d" ,    = %V