a ;`Y@sdZdgZdZdZdZddlZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZd d Zd d ZddZ ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(e)d ej*Z+d!d"Z,d#d$Z-d%d&Z.d'd(Z/dd)d*Z0d+d,Z1d-d.Z2d/d0Z3d1d2Z4ifd3d4Z5Gd5d6d6e6Z7d7d8Z8difd9d:Z9Gd;d<d<Z:Gd=d>d>eZ;Gd?d@d@e:ZGdEdFdFe>Z?dGdHa@dIdJZAdKdLZBdMdNZCdOdPZDdQdRZEdSdTZFdUdVZGdWdXZHddYdZZIe>ZJe?ZKe<ZLdd[d\ZMdd^d_ZNdd`daZOddbdcZPddedfZQGdgdhdhZReRZSGdidjdjZTdkdlZUdmdnZVddpdqZWddrdsdtdudvZXdwdxZYdydzZZd{d|Z[d}d~Z\e]dkre\dS)a^Generate 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 -n " to start an HTTP server with the given hostname (default: localhost) on the local machine. 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. Combine with the -n and -p options to control the hostname and port used. 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 /usr/share/doc/pythonX.Y/html/library if the pythonX.Y-doc package is installed or 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}tjD]H}tj|pd}tj|}||vrtj|r||||q|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr/usr/lib/python3.9/pydoc.pypathdirsUs    rcCsPtj|j}|durdS|jdddD]}t||}q.t|sLdS|S)Nr) rmodulesget __module__ __qualname__splitgetattrinspectisclass)funcclsnamerrr _findclassas  rc Cst|rJ|jj}|j}t|r@tt||dd|jur@|}n|j}n$t|r~|j}t |}|dusxt|||ur|dSnt |r|j}|j}t|r|j d||j kr|}n|j}nt |t r|j}|j}t |}|dust|||urdSntt|st|rj|j}|j}t|||ur2dSt|rnt|dd}t |trn||vrn||SndS|jD]F}ztt||}WntyYqtYn0|durt|SqtdS)N__func__r __slots__)rismethodr __name____self__rr __class__ isfunctionr isbuiltinr isinstancepropertyfgetZismethoddescriptorisdatadescriptor __objclass__ismemberdescriptordict__mro__ _getowndocAttributeError)objrselfrrslotsbasedocrrr_finddocksZ              r7cCsdzJt|d}|durWdS|turFt|j}t|trF||krFWdS|WSty^YdS0dS)zUGet the documentation string for an object if it is not inherited from its class.__doc__N)object__getattribute__typer8r(strr1)r2r6Ztypedocrrrr0s   r0c CsNt|}|dur6z t|}Wnttfy4YdS0t|tsDdSt|S)zGet the documentation string for an object. All tabs are expanded to spaces. To clean up docstrings that are indented to line up with blocks of code, any whitespace than can be uniformly removed from the second line onwards is removed.N)r0r7r1 TypeErrorr(r<rZcleandoc)r9r6rrr_getdocs  r>cCs,t|pt|}|r(tdd|p*dS)z-Get the doc string or comments for an object.z^ * )r>rZ getcommentsresubrstrip)r9resultrrrgetdocsrDcCsf|d}t|dkr&|ddfSt|dkrX|dsX|dd|ddfSdd|fS)z>Split a doc string into a synopsis line (if any) and the rest. rr?N)striprlenrBjoin)r6linesrrrsplitdocs   rLcCs"|j}|j|kr|jd|}|S)z@Get a class name and qualify it with a module name if necessary.r)r#r)r9modnamerrrr classnames rNcCs>t|p:t|p:t|p:t|p:t|p:t| S)z>Check if an object is of a type that probably means it's data.)rismoduler isroutineZisframeZ istracebackZiscoder9rrrisdatasrRcGs.|r*|d||d}|dd}q|S)z/Do a series of global replacements on a string.rFrrGN)rJr)textZpairsrrrreplacesrTcCsXt||krTtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrGN...)rImax)rSmaxlenZpreZpostrrrcrams  $rYz at 0x[0-9a-f]{6,16}(>+)$cCs td|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidrArSrrrstripidsr\cCs<t|rdSt|r8t|dd}t|p4|du SdS)zo Returns True if fn is a bound method, regardless of whether fn was implemented in Python or in C. Tr$NF)rr"r'rrO)fnr3rrr_is_bound_methods    r^cCs^i}t|tjD]\}}d||<q|jD]}|t|q*|D]}t||||<qF|SNrF)r getmembersrP __bases__update allmethodskeysr)clmethodskeyvaluer5rrrrcs   rccCs8g}g}|D]"}||r$||q ||q ||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 predicateZyesZnoxrrr _split_lists  rmcCs\|dvr dS|dr$|dr$dS|drr __loader__ __builtins__ __cached____date__rr!__path__ __version____file____spec__r8r# __credits__ __author__ __package__r__rF__fieldsTN) startswithendswithhasattr)rallr2rrr visiblenamesrcCsXg}t|D]D\}}}}t|r@d}t|tr@|jdur@d}|||||fq|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.data descriptorNreadonly property)rclassify_class_attrsr+r(r)fsetr )r9resultsrkindrrhrrrr)s rcsZt|dgzfddtDWnty<iYn0fdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namer{csi|]\}}||tqSr)rI).0ir)fieldsrr :z#sort_attributes..cs|dd|dfSNr)r)attr) field_orderrr=rz!sort_attributes..rgN)r enumerater=sort)attrsr9Zkeyfuncr)rrrsort_attributes4s    rcCs:tj|r6dD]$}tjtj|d|rdSqdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfilerJ)rextrrr ispackageBs  rcCs|}|dddks |s0|}|sq0q|}|dddkrT|dd}|dddkr|dd}|dddkr|dd}|s|}|sqq|dd }nd}|S) NrF#zr"""rU"""r\r)readlinerHr)filelinerCrrrsource_synopsisJs rc Cs2t|j}||d\}}|dus.||kr.|ttjjrJtjj }n |ttjj rftjj }nd}|durzt |}WntyYdS0|t|}Wdn1s0Yn^|d|}tjjd||d}ztj|} WnYdS0tjd=| jr| jdnd}||f||<|S)z.Get the one-line summary out of a module file.)NNNZ__temp__loaderr)r statst_mtimerr}tuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrrr8 splitlines) filenamecachemtimeZ lastupdaterCZ loader_clsrrspecmodulerrrsynopsis[s6    (   rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dSN)rexcrhtb)r3rexc_inforrrrszErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr#rrh)r3rrrr__str__szErrorDuringImport.__str__N)r#rrr8rrrrrrrsrc Cstjj}t|d"}||t|k}Wdn1s:0Ytj|}tj |\}}|rttj ||}ntj ||}tjj |||d}ztj|WSt|tYn0dS)z|turt|j| n(t |t r|j krYdSttYn0 dddD],} zt || }WqtyYdS0q|S)aImport a module; handle errors; return None if the module isn't found. If the module *is* found but an exception occurs, it's wrapped in an ErrorDuringImport exception and reraised. Unlike __import__, if a package path is specified, the module at the end of the path is returned, not the package at the beginning. If the optional 'forceload' argument is 1, we reload the module from disk (unless it's a dynamic extension).csg|]}|dr|qS)r)r|)rmrrr rzsafeimport..NrrF)rrbuiltin_module_names __import__rrrt SyntaxErrorr issubclass ImportErrorrrrr1) r forceloadrZsubsrgrrrhrinfopartrrr safeimports*    rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrGcGs||f|}zFt|r$|j|WSt|r:|j|WSt|rP|j|WSWntydYn0t|rz|j |S|j |S)z%Generate documentation for an object.) rrO docmodulerdocclassrP docroutiner1r+docdatadocother)r3r9rargsrrrdocuments  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)reprr;r#r=)r3r9rrmessagerrrfailszDoc.failZstdlibcCszt|}Wnty$d}Yn0tjd|j}tj|}t |t tr|j dvs| |r| tj |ds| tj |ds|j dvr| drd|d |j f}qtj ||j d }nd }|S) z*Return the location of module docs or None (built-in)r) errno exceptionsZgcZimpmarshalposixsignalr_threadZ zipimportz dist-packagesz site-packages)z xml.etreeztest.pydoc_mod)zhttp://zhttps://z%s/%s/.htmlN)r getabsfiler=r environrrrr r(r;r#r|rJrBlower)r3r9Zbasedirrdoclocrrr getdoclocs,    z Doc.getdocloc)N)N)r#rrr rrr version_inforrrrrrr docpropertyr sysconfigZget_pathrrrrrrs   rc@sHeZdZdZddZddZddZdd Zd d ZeZ d d Z eZ dS)HTMLReprzBClass for safely making an HTML representation of a Python object.cCs,t|d|_|_d|_d|_|_dSN drrmaxlistmaxtuplemaxdict maxstringmaxotherr3rrrr s  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)rTr3rSrrrescapeszHTMLRepr.escapecCs t||Sr)rrr3r9rrrrsz HTMLRepr.reprcCsZtt|dr@ddt|j}t||r@t||||S|ttt ||j SNr#repr_rz) r~r;rJr#rrrrYr\rrr3rllevelZ methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|vrJdt|ddvrJd|d|||dStdd||S)Nr\\r?rrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)rYrrrTrr@rAr3rlrtestZtestreprrrr repr_strings zHTMLRepr.repr_stringcCs@z|ttt||jWS|d|jjYS0dSNz <%s instance>)rrYr\rrr%r#r3rlrrrr repr_instance+szHTMLRepr.repr_instanceN) r#rrr8rrrr rrepr_strrZ repr_unicoderrrrr s rc@seZdZdZeZejZejZddZd1ddZ d2d d Z d d Z ddZ d3ddZ ddZddZddZddZddZddZdiiifdd Zd4d!d"Zd5d#d$Zddiifd%d&Zd'd(Zddiiidfd)d*Zd6d+d,ZeZd7d-d.Zd8d/d0ZdS)9HTMLDocz'Formatter class for HTML documentation.cCs d||fS)Format an HTML page.z Python: %s %s r)r3titlecontentsrrrpage<sz HTMLDoc.pager?cCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
 r)r3rfgcolbgcolZextrasrrrheadingFszHTMLDoc.headingNrc Cs^|durdd|d}d|||f} |r@| d||||f} n| d|||f} | d|S) z Format a section with a heading.Nzrzz

zR z( z'
 
%s
%s %s
%s
%s%s%s
r) r3rrrrwidthZpreludeZ marginaliaZgaprCrrrsectionQs zHTMLDoc.sectioncGsd|}|j|g|RS)z$Format a section with a big heading.z%s)r)r3rrrrr bigsectiongszHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text. z rrrE
)r expandtabsrTrrrr preformatls zHTMLDoc.preformatrcCsd}t||d|}t|D]X}|dd|}t|||||D]$}|t|krJ||||d}qJ|d}q d|S)z0Format a list of items into a multi-column list.r?rFzrr!zz7%s
)rIrange)r3listformatZcolsrCrowscolrrrr multicolumnrs   zHTMLDoc.multicolumncCsd|S)Nz%srrrrrgrey~rz HTMLDoc.greycGs*|D] }||vrd|||fSq|S)z:Make a link for an identifier, given name-to-URL mappings.%sr)r3rZdictsr.rrrnamelinkszHTMLDoc.namelinkcCsN|jtj|j}}t||rDt|||urDd|j|t||fSt||S)zMake a link for a class.z%s)r#rrrrr~rrN)r3r9rMrrrrr classlinks zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.%s)r#rrrr modulelinkszHTMLDoc.modulelinkcCsR|\}}}}|r||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)r+)r*)r3Z modpkginforrrshadowedurlrSrrr modpkglinks   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%srr3r1rrrrfilelinkszHTMLDoc.filelinkcCs|p|j}g}d}td}|||} | s0qh| \} } ||||| | \} } }}}}| r|| dd}|d||fn|rdt|}|d||| fn|rdt|}|d||| fn|r"|| | dd kr|d | ||n|d |n@|| | dd krP|| ||||n|| ||| }q||||d d |S)zMark up some plain text, given a context of symbols to look for. Each context dictionary maps object names to anchor names.rzJ\b((http|https|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?(\w+))"z"r+z'http://www.rfc-editor.org/rfc/rfc%d.txtz(http://www.python.org/dev/peps/pep-%04d/rF(zself.zself.%sNr?) rr@compilesearchspanr groupsrTintr,rJ)r3rSrfuncsclassesrfrherepatternmatchstartendrZschemeZrfcZpepZselfdotrr1rrrmarkups8      zHTMLDoc.markupc Csd}|D]}t|tdur|\}}|d}||||}|r||fkrg}|D]} ||| |qR|dd|d}|d}qt|tgur|d||||}qd |S) zAProduce HTML for a class tree as given by inspect.getclasstree().r?rz"

r6, )z
z
%s
z
%s
)r;r-r rJ formattree) r3treerMparentrCentrycbasesparentsr5rrrrFs"  zHTMLDoc.formattreec# s|j}z |j}Wnty&d}Yn0|d}g}tt|dD],}|dd|d|d||fqFd||dd} d| } z&t |} t j | } | | } Wntyd} Yn0g}t|dr2t|j}|dd d kr|ddd kr|d d}|d |t|d rT|t|j|rl| dd|} |}|durdt}nd}| ddd| |}t|tj}gi}}t|tjD]Z\}}|dust|p||urt|||r|||fd|||<||<q|D]\}}|jD]n}|j|j}}tj !|}||kr<|r%sr)%srrs $Revision: $z version %srqz (%s)rDz-
Module Referencer?#ffffff#7799eezindex
rz.html#z#-z %sz

%s

rrrzPackage Contentsz#aa55cccs|dSr_)r/trrrr:rz#HTMLDoc.docmodule..ZModulescSsg|] \}}|qSrrrrgrhrrrr?rz%HTMLDoc.docmodule..ZClasses#ee77aarZ Functionsz#eeaa77ZDataz#55aa55r!rwZAuthorrvZCredits)6r#__all__r1rr$rIr rJrrurllibparseZquoter4r=r~r<rsrHrrqrlocalsrr`rOr getmodulerrarrrrrrPr'r&rRrCrDr#pkgutil iter_modulesrrrr)r2rrF getclasstreerrwrv)#r3r9rmodignoredrpartsZlinksrZ linkednameheadrr1r4rversionrrCrr=Zcdictrgrhr5rMrr<Zfdictdatar6modpkgsimporterispkgr classlistrrrrs          $                        zHTMLDoc.docmodulec sj}|p |}j}g} | jGfddd} | tt} t| dkrd| D]} d| j qddfdd} fd d }fd d }fd dt D}i|D]j\}}}}d|d||<}zt |}Wnt y2Yn0z ||<Wqt yTYq0q|rt| rn| n |ddt|fdd\}}tjurtjur|}qXn"urd}ndj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|d!||d"d}|gkslJ|}qXd#| } ||krd$||f}nd%|||f}|rg}|D]} || j q|d&d'|}d#}zt}Wntt fyd(}Yn0|r@t|}|r@|d)kr@||d*}t}|r\||pXd#}|j}|o|d+|}|d,d-| d.|S)/z.Produce HTML documentation for a class object.cs eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecSs d|_dSrZneedonerrrrrisz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
rFrirpushrrmaybeksz.HTMLDoc.docclass..HorizontalRule.maybeNr#rrrrlrrjrrHorizontalRulehsrnrGz&
Method resolution order:
z
%s

c st||\}}|r||D]b\}}}}zt|}Wn$tyd||Yn0||dq&|S)NrErmrlr Exceptionrrmsgrrkokrrhomeclsrhr=r<hrmdictr_r9rkr3rrspill{s   zHTMLDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrmrlrrrrwr_rkr3rrspilldescriptorssz*HTMLDoc.docclass..spilldescriptorsc st||\}}|r||D]r\}}}}t||}t|} | s`d|n0t|j} d| } d|| fdq&|S)Nz
%s
z
%sz
%s%s
rE)rmrlrrrDrCr#) rsrrkrtrrrurhr5r6rvrr spilldatas  z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS)r2rrrrrrhrQrrrs  z$HTMLDoc.docclass..r-rcs |duSNrGrrS thisclassrrrrz"HTMLDoc.docclass.. defined hereinherited from %sz:
z Methods %scSs |ddkSNrFmethodrrSrrrrrzClass methods %scSs |ddkSNrFz class methodrrSrrrrrzStatic methods %scSs |ddkSNrFz static methodrrSrrrrrzReadonly properties %scSs |ddkSNrFrrrSrrrrrzData descriptors %scSs |ddkSNrFrrrSrrrrrzData and other attributes %scSs |ddkSNrFrdrrSrrrrrr?z*class %sz/%s = class %s(%s)rDN()r z%s
 
z#000000z#ffc8d8rU)r#rar rrgetmrorIrlr-rrrrqr=popleftrmbuiltinsr9rrJ signature ValueErrorr<rrDrCr#r)r3r9rr_r<r=r`realnamerKrrnmror5ryr|r}rrgrrurhanchor inheritedtagrrLdeclrargspecr6r) r=r<rwrxr_r9rkr3rrr]s                   zHTMLDoc.docclasscCs|d||Sz)Format an argument default value as text.=)r*rrrrr formatvalueszHTMLDoc.formatvaluec Cs|j}|p |}|r|jpdd|} d} d} t|r|jj} |rZ| |urd|| |} n0|jdurzd||jj|} nd|| |} t|st|rd} nd} ||krd | |f}nD|rt||g|urd |jd||f}d } n|}d | ||f}d}t |rjzt |}Wnt t fy<d}Yn0|rjt |}|d krjd|}|d d}|std}| |||| o|d| }| rd|S|t||j|||}|od|}d||fSdS)z;Produce HTML documentation for a function or method object.r?rr from N method of %s instance unbound %s methodasync z$%sz%srFz)%s = %sz$%s lambda r(...)z'%sz
%s
z
%s
z
%s
%s
)r#r^r$r%r-riscoroutinefunctionisasyncgenfunctiongetattr_staticrPrrr=r<rr*rCrDr#)r3r9rr_r<r=rfrerrnoteskipdocsimclassasyncqualifierrZreallinkrrrr6rrrrsl       zHTMLDoc.docroutinecCsNg}|j}|r|d||t||j}|r<|d||dd|S)z1Produce html documentation for a data descriptor.z!
%s
z
%s
ror?)r rCrDr#rJr3r9rr_rerrkr6rrrrDs  zHTMLDoc.docdatacGs|r d|pd}|||S)z-Produce HTML documentation for a data object.z%s = r?r)r3r9rr_r`ZlhsrrrrTszHTMLDoc.docothercCsg}|duri}t|gD]<\}}}tdd|Dr:q||d|||vfd||<q||||j}||dd|S)z2Generate an HTML index for a directory of modules.Ncss*|]"}dt|kodknVqdS)iiN)ordrZchrrr ^rz HTMLDoc.index..r?rFrQrV)r\r]anyr rr)r2r)r3rr0rerfrrgrrrrindexYs  z HTMLDoc.index)r?)rr?Nr)r)N)NN)NNN)NN)N)r#rrr8r_repr_instancerrrrrrr#r)r*r,r-r/r2r4rCrFrrrrrrrrrrrrr3s>   +  y# A  rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,t|d|_|_d|_d|_|_dSrrrrrrrls  zTextRepr.__init__cCsTtt|dr@ddt|j}t||r@t||||Sttt||j Sr) r~r;rJr#rrrYr\rrrrrrr rs  zTextRepr.repr1cCsHt||j}t|}d|vrDdt|ddvrDd|d||dS|S)Nrr r?r r)rYrrrTr rrrrys  zTextRepr.repr_stringcCs4zttt||jWSd|jjYS0dSr)rYr\rrr%r#rrrrrszTextRepr.repr_instanceN) r#rrr8rr rrrrrrrrjs  rc@s~eZdZdZeZejZddZdddZddZ dd d Z dd dZ dddZ ddZ dddZdddZeZdddZd S) TextDocz'Formatter class for text documentation.cCsddd|DS)z(Format a string in bold by overstriking.r?css|]}|d|VqdS)NrrrrrrrzTextDoc.bold..)rJrrrrboldsz TextDoc.bold cs>|sdSfdd|dD}|r4|d|d<d|S)z6Indent text by prepending a given prefix to each line.r?csg|] }|qSrrrrprefixrrrrz"TextDoc.indent..rEr)rrBrJ)r3rSrrKrrrindentszTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rEr )rrBr)r3rrZclean_contentsrrrrszTextDoc.sectionNr?c sd}|D]}t|tdurr|\}}||t|}|rh||fkrhfdd|D} |dd| }|d}qt|tgur|||||d}q|S) zBRender in text a class tree as returned by inspect.getclasstree().r?rc3s|]}t|VqdSrrN)rrJrMrrrrz%TextDoc.formattree..rrDrEr)r;rNrJrF) r3rGrMrHrrCrIrJrKrLrrrrFs  zTextDoc.formattreec Cs"|j}tt|\}}|d||o(d|}t|dd}||}|dur`||d|d}|rt||d|}g} t|tjD]<\} } |dust | p||urt | ||r| | | fqg} t|tj D]F\} } |dust | st | |urt | ||r| | | fqg} t|tD]&\} } t | ||r.| | | fq.g}t}t|drt|jD]6\}}}|||r| |d n | |qx|||d d |}g}t|tjD]0\} } | j|d r| |vr| | q|r6|||d d |}| rdd| D}|t|d|g}| D]\} } | || | |qd||dd |}| rg}| D]\} } | || | |q||dd |}| r&g}| D]"\} } | |j| | |ddq||dd |}t|drt|j}|dddkrp|dddkrp|dd}||d|}t|dr||dt|j }t|dr||dt|j!}t|d r||d!t|j"}zt#|}Wnt$y d"}Yn0||d#|}|S)$z5Produce text documentation for a given module object.NAME - rWNzMODULE 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 DESCRIPTIONrr (package)zPACKAGE CONTENTSrErZ SUBMODULEScSsg|] \}}|qSrrrUrrrrrz%TextDoc.docmodule..rFCLASSES FUNCTIONSF)rXZDATArsrNrOrrPZVERSIONrqZDATErwZAUTHORrvZCREDITSrZFILE)%r#rLrDrrrrr`rr[rr rPr'rRsetr~r\r]rraddrrJrOr|rFr^rrr<rsrHrqrwrvrr=)r3r9rr_ZsynopdescrCrrr=rgrhr<rdreZ modpkgs_namesrfrMrgZ submodulesrhrrcrrrrrs                 $    zTextDoc.docmodulec sXj}|p |}j}jfdd}||kr:d|}n|d|}|rlt||} |dd| }g} | jzt} Wnt t fyd} Yn0| rt | } | r| dkrȈ|| d t } | r| d t t}t|d kr(d |D]}d ||qd tddtDt jd}t|}d}|rd|d|D]}d |ql||krdt ||dd Gfddd}|fdd}fdd}fdd}fddtD}|r$|r(|n |dd t|fd d!\}}tjurltjurl|}qn ur|d"}nd#tj}t||d$||d%d!}|d&||d'd!}|d(||d)d!}|d*||d+d!}|d,||d-d!}|d.||d/d!}|gksJ|}qd | } | s<|d S|d | d0d S)1z4Produce text documentation for a given class object.cSs t||Srr)rJrrrrmakenamesz"TextDoc.docclass..makenameclass z = class rrDNrrErGzMethod resolution order:rr?css.|]&}|jds|jdkrt|jVqdS)rzrN)r#r|rr<)rrrrrrDsz#TextDoc.docclass..rrzBuilt-in subclasses:z ... and z other subclassescs eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dSrrirrrrrVsz1TextDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)NzF----------------------------------------------------------------------rFrirrjrrrlXsz.TextDoc.docclass..HorizontalRule.maybeNrmrrjrrrnUsrnc st||\}}|r|||D]T\}}}}zt|}Wn$tyd||Yq&0||q&|Srrprrrwr_r9rkr3rrry^s zTextDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrzrrr{rrr|osz*TextDoc.docclass..spilldescriptorsc st||\}}|r||D]\\}}}}t|}zt|} Wntyd|j|} Yn0j| |d|ddq&|S)Nr)rXr6rE)rmrlrDrr1__dict__r) rsrrkrtrrrurhr6r2rrrr}xs z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqSr~rrrQrrrs  z$TextDoc.docclass..rcs |duSrrrSrrrrrz"TextDoc.docclass..rrz Methods %s: cSs |ddkSrrrSrrrrrzClass methods %s: cSs |ddkSrrrSrrrrrzStatic methods %s: cSs |ddkSrrrSrrrrrzReadonly properties %s: cSs |ddkSrrrSrrrrrzData descriptors %s: cSs |ddkSrrrSrrrrrzData and other attributes %s: cSs |ddkSrrrSrrrrrz | )r#rarrmaprJr rrrr=r<rDrrrIsortedr;__subclasses__rrrrmrr9rNrrrB)r3r9rr_r`rrKrrrLrrrr6rr5Z subclassesZno_of_subclassesZMAX_SUBCLASSES_TO_DISPLAYZ subclassnamernryr|r}rrrr)rwr_r9rkr3rrrs                   zTextDoc.docclasscCsd||SrrrrrrrszTextDoc.formatvaluec Cs|j}|p |}d}d}t|rn|jj}|rB||urndt||}n,|jdur`dt|jj|}ndt||}t|st|rd} nd} ||kr||} n,|rt ||g|urd}||d |} d} t |r:zt |} Wnt t fyd} Yn0| r:t| } |d kr:||d } | dd } | sDd } | | | |} |rb| dSt|pnd}| d|o||dSdS)z;Produce text documentation for a function or method object.r?rrNrrrrF = rz lambda rrrE)r#r^r$r%rNrrrrrrPrrr=r<rDrrB)r3r9rr_rerrrrrrrrrr6rrrrsT       zTextDoc.docroutinecCsTg}|j}|r$||||dt|p.d}|rJ||||dd|S)z1Produce text documentation for a data descriptor.rEr?)r rrDrrJrrrrrs zTextDoc.docdatac Cs||}|rF|r|dpd|}|t|} | dkrF|d| d}|rX||dpZd|}|slt|}|r|d|t|d7}|S)z-Produce text documentation for a data object.rr?rNrVrE)rrIrrDrr<) r3r9rr_rHrXr6rrZchoprrrrs  zTextDoc.docother)r)Nr?)NN)NN)NNN)NNN)NNNNN)r#rrr8rrrrrrrFrrrrrrrrrrrrs   e  7 rc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|Srrrrrrrsz_PlainTextDoc.boldN)r#rrr8rrrrrr srcCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpagerr[rrrrsrc szttjdstSttjds tStjr4tjs8tStjdpNtjdrtj dkrjfddStjddvrfd dSfd dStjddvrtStj dkrd dSttd rt d dkrddSttd rt ddkrddSddl }| \}}t |zRttd rLt d|dkrLddWt|StWt|SWt|n t|0dS)z2Decide what method to use for paging through text.isattyZMANPAGERZPAGERZwin32cstt|Sr tempfilepagerplainr[Z use_pagerrrr$rzgetpager..ZTERM)ZdumbZemacscstt|Sr) pipepagerrr[rrrr&rcs t|Srrr[rrrr(rcSstt|dS)Nzmore /dev/nullrcSs t|dS)Nrrr[rrrr.rz(less) 2>/dev/nullcSs t|dS)NZlessrr[rrrr0rNz more "%s"cSs t|dS)NZmorerr[rrrr7r)r~rstdin plainpagerstdoutrr rrplatformrtempfileZmkstempcloseunlinkttypager)rfdrrrrrsB            rcCstdd|S)z%Remove boldface formatting from text.z.r?)r@rAr[rrrr=src Csddl}|j|d|jd}zVtj|jdd2}z||WntyNYn0Wdn1sd0YWntyYn0z| WqWqtyYq0qdS)z3Page through text by feeding it to another program.rNT)shellrbackslashreplaceerrors) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)rScmdrprocpiperrrrAs (  rc Cs~ddl}|}t|ddd}||Wdn1s>0Yz$t|d|dWt|n t|0dS)z.cSstjddddS)NrrF)rrrrrrrrsrZLINESrFz -- more --)qQz ) rE)bB)rrrttyrrfilenoZ tcgetattrZ setcbreakrr1rUnsupportedOperationr;r rrrrrrJflushZ tcsetattrZ TCSAFLUSH) rSrKrroldZgetcharhr ZincrJrrrrhsN              & rcCstjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrrr[rrrrsrcCst|r>|jtjvr d|jSt|dr4d|jSd|jSt|rRd|jSt|rtd|jj |jj|jfSt |rd|jj |jj|jfSt |rd|jSt |rd |jSt |rd |jSt|jS) z/Produce a short description of the given thing.zbuilt-in module rrzpackage zmodule zbuilt-in function zgetset descriptor %s.%s.%szmember descriptor %s.%s.%srz function zmethod )rrOr#rrr~r'Zisgetsetdescriptorr,rr-rr&r"r;)thingrrrdescribes2                  rc Csdd|dD}d\}}|t|kr\td|d|d|}|r\||d}}qq\q|rf|}nt}||dD]*}zt||}WqvtyYdS0qv|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|] }|r|qSrr)rrrrrrrzlocate..rrNrF)rrIrrJrrr1)rrrarnZ nextmoduler9rrrrlocates   r cCsVt|tr0t||}|dur(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#)r(r<r rr)rrr9rrrrresolves   r  Python Library Documentation: %scCs|dur t}t||\}}t|}t|}|rTd|vrT|d|d|d7}n|rn||urn|d|j7}t|st|st |st |st |st |dr|j }nt|}|d7}||d|||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module __origin__z objectr )rSr rrr[rfindr#rOrrPr+r>r~r r;r)rrrZrendererr9rrrrrr render_docs.     rc Cshz2|durtt|||n|t|||tWn0ttfyb}zt|WYd}~n d}~00dS)zCDisplay text documentation, given an object or a path to an object.N)rrr plaintextrrprint)rrroutputrhrrrr6s r6c Csztt||\}}tt|t||}t|dddd}||Wdn1sZ0Ytd|dWn0tt fy}zt|WYd}~n d}~00dS)zd?d@dAdBdCdDdEdFdGdHdIdJdKdLdLdMdNdOdPdQddRdSdSdTdUdVdWdXdYdZd[d\d]d^d_d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{dd d|d}d~ddIZ dddZ eddZeddZddZeZefddZddZddZddZddZdddZddZddZddZdddZdddZddZdddZ dS)Helperr?BOOLEANwith)assertr?)asyncr?)awaitr?)break while for)classzCLASSES SPECIALMETHODS)continuer)Zfunctionr?)del BASICMETHODSif)elsertry)forzbreak continue whileimport)globalznonlocal NAMESPACES)r# TRUTHVALUE)r'MODULES)inSEQUENCEMETHODS COMPARISON)lambdar)nonlocalzglobal NAMESPACES)passr?)raise EXCEPTIONS)returnr)r%r2)whilezbreak continue if TRUTHVALUE)rz CONTEXTMANAGERS EXCEPTIONS yield)yieldr?)$FalseNoneTrue__peg_parser__andasrrrrrr defr!elifr$exceptfinallyr&fromr(r#r'r+isr.r/notorr0r1r3r%r4rr5cCsg|]}dD] }||q qS)'r5r)rprrrrrGrzHelper.)rfr urEz'''r5r)+r***rz//%<<>>r|^~rr<=>===!=<>)rrrRrSrTrUrV)rrQ) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)rMrNrrOrPrQ)jJ)STRINGS OPERATORSr-UNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classrY PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rLrK,rrV:@rrzry`r6rE[]r)typeszRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES)zstring-methodszSTRINGS FORMATTING)Z formatstringsrZ)riz:encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPES)ZnumberszINTEGER FLOAT COMPLEX TYPES)Zintegersz int range)Zfloatingz float math)Z imaginaryz complex cmath)Ztypesseqz$STRINGMETHODS FORMATTING range LISTS DICTIONARIES)Ztypesfunctionsz def TYPES)Z typesmethodszclass def CLASSES TYPES)zbltin-code-objectszcompile FUNCTIONS TYPES)zbltin-type-objectsz types TYPESTYPES)zbltin-null-objectr?)zbltin-ellipsis-objectSLICINGS)Z specialattrsr?)rhz!class SPECIALMETHODS PRIVATENAMES)Z typesmodulesr')zoperator-summaryzlambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIES EXPRESSIONS)Zobjectsrk)Z specialnameszbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES)Z customizationzhash repr str SPECIALMETHODS)zattribute-accesszATTRIBUTES SPECIALMETHODS)zcallable-typeszCALLS SPECIALMETHODS)sequence-typesz(SEQUENCES SEQUENCEMETHODS SPECIALMETHODS)rnzMAPPINGS SPECIALMETHODS)z numeric-typesz*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS)Z execmodelz%NAMESPACES DYNAMICFEATURES EXCEPTIONS)Znamingz3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURES)zdynamic-featuresr? NAMESPACES)rztry except finally raise)Z conversionsr?)Z identifierszkeywords SPECIALIDENTIFIERS)z id-classesr?)zatom-identifiersr?)z atom-literalsz=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALS SEQUENCES)Z exprlistszTUPLES LITERALS)ztypesseq-mutable LISTLITERALS)ZlistszLISTS LITERALS)Z typesmappingDICTIONARYLITERALS)r.zDICTIONARIES LITERALS)zattribute-referencesz(getattr hasattr setattr ATTRIBUTEMETHODS)Z subscriptionsr,)Zslicingsr,)Zcallsrm)Zpowerrm)Zunaryrm)Zbinaryrm)Zshiftingrm)Zbitwiserm)Z comparisonszEXPRESSIONS BASICMETHODS)ZbooleanszEXPRESSIONS TRUTHVALUEr)Z assignmentr\)Z augassign NUMBERMETHODSr!r3)Zcompoundzfor while break continue)truthz if while and or not BASICMETHODS)ZdebuggerZpdb)zcontext-managersr)IrkrYZ STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERZFLOATr^rpZMAPPINGSrZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSZNONEr`ZSPECIALATTRIBUTESrr*ZPACKAGESrmrZZ PRECEDENCEZOBJECTSZSPECIALMETHODSr"ZATTRIBUTEMETHODSZCALLABLEMETHODSr,ZMAPPINGMETHODSrsZ EXECUTIONroZDYNAMICFEATURESZSCOPINGZFRAMESr2Z CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSraZLITERALSZTUPLESZ TUPLELITERALSZLISTSrqrjrrZ ATTRIBUTESZ SUBSCRIPTSrlZCALLSr_r[ZBINARYZSHIFTINGr]r-rZ ASSERTIONZ ASSIGNMENTr\ZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGr)Z DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dSr)_input_output)r3inputrrrrrszHelper.__init__cCs |jp tjSr)rvrrrrrrrxsz Helper.inputcCs |jp tjSr)rwrrrrrrrsz Helper.outputcCs2tdddkr|dSd|jj|jjfS)NrFrU?r?z<%s.%s instance>)rstackr%rrrrrr__repr__s zHelper.__repr__cCs6||jur||n|||jddS)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. )_GoInteractiverintrointeractrrr3Zrequestrrr__call__s   zHelper.__call__c Cs|jdz|d}|s WqWnttfy<YqYn0|}t|dkr|d|dkrndvrnn |d|ddvr|dd}|dvrq|d kr|q | |q dS) NrEzhelp> rGrrrDrF)rquitr) rrgetlinerEOFErrorrHrIrr}rrrrrr~s    ,  zHelper.interactcCs8|jtjurt|S|j||j|jSdS)z.Read one line, using input() when appropriate.N)rxrrrrrr)r3Zpromptrrrrs    zHelper.getlinecCs<t|tdur|}|dkr,|n|dkr>|n|dkrP|n|dkrb|n|dddkr||dn||jvr||nj|d vrt t |d nR||j vr| |n<||j vr| |n&|rt |d |jd nt td |jd n$t|tr|nt |d |jd |jd dS) Nr?keywordssymbolstopicsrzmodules rF)r8r6r7z Help on %s:)rrE)r;rH listkeywords listsymbols listtopics listmodulesrr showsymbolr6evalr showtopicrrwr<r(rrrrrrrrs$z Helper.helpcCs$|jddtjdddS)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.%drG)rrr&rrrrrrr}s z Helper.introrPc Cstt|}||}t||d|}t|D]v}t|D]\}|||}|t|kr<|j||||dkr<|jdd|dt||q<|jdq0dS)NrFrrE)r%rrIr$rr) r3itemscolumnsrZcolwr'rowr(rrrrr%'s      &z Helper.listcCs |jd||jdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrr%rrdrrrrr4s zHelper.listkeywordscCs |jd||jdS)Nzx Here is a list of the punctuation symbols which Python assigns special meaning to. Enter any symbol to get more help. )rrr%rrdrrrrr;s zHelper.listsymbolscCs |jd||jdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrr%rrdrrrrrCs zHelper.listtopicsc Cs,z ddl}Wn ty,|jdYdS0|j||j|}|s`|jdt|dSt|tdur|| ||S|\}}z|jj|}Wn(t y|jdt|YdS0| d}|r|pdd|}|r ddl }dd |d} || d } |d d | 7}t|dS) Nrt Sorry, topic and keyword documentation is not available because the module "pydoc_data.topics" could not be found. zno documentation found for %s r?rErRelated help topics: rDHz %s )pydoc_data.topicsrrrrrrrr;rKeyErrorrHtextwraprJrZwrapr) r3topic more_xrefs pydoc_datatargetlabelxrefsr6rrSZ wrapped_textrrrrJs4       zHelper.showtopiccCsz ddl}Wnty YdS0|j||j|}|sDtdt|trZ|||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. rN)rr?zcould not find topicr?r) rrrrrrr(r< _gettopic)r3rrrrrrr6rrrrjs      zHelper._gettopiccCs*|j|}|d\}}}|||dS)Nr)r partitionr)r3symbolrrrzrrrrrs zHelper.showsymbolcsv|r |jd|t|nR|jdi}|fddfdd}tj|d|||jddS) 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}|ddkr:d||<dS)N .__init__rrrrF)find)rrMrrrrrcallbacksz$Helper.listmodules..callbackcsd|ddSrrrrrronerrorsz#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)r3rgrrrrrrs     zHelper.listmodules)NN)rr)r?)r?)r?)!r#rrrZ _strprefixesZ_symbols_inverserrrZsymbols_rrrrr)rxrr{r9r|rr~rrr}r%rrrrrrrrrrrrsD(    W       rc@seZdZdZdddZdS)rz7An interruptible scanner that searches module synopses.Nc Cs|r |}d|_i}tjD]p}|dkrd||<|durF|d|dqt|jpRd}|dd}|d|}||dkr|d||qtj |dD]V\} }} |jrq|dur|d|dqzt | |} Wnt yYqYn0| j } t | d rjz| |} Wn&ty6|r.||YqYn0tt| pJd}t | d rd| |}nd}n^ztj| }Wn&ty|r||YqYn0|jr|jdnd}t|d d}|d|}||dkr||||q|r|dS) NF__main__rFr?rErrr get_source get_filenamert)rrrrrr8rrr\r _get_specrrr~rrqrrStringIOrrrrrrr)r3rrgZ completerrseenrMrrrfrgrrsourcerrrrrrs^            zModuleScanner.run)NNN)r#rrr8rrrrrrsrcCsXdd}dd}t,tdtj|||dWdn1sJ0YdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dSNrrrz- )rrrMrrrrrszapropos..callbackcSsdSrrrrrrrszapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rgrrrrrrs   rcsddlddlddlddlGdddjjGfdddjjGfdddj}||||}||j s|j st d q~|S) aAStart 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.monotonic() >>> timeout = 1 #seconds This is a short timeout for testing purposes. >>> while serverthread.serving: ... time.sleep(.01) ... if serverthread.serving and time.monotonic() - starttime > timeout: ... serverthread.stop() ... break Print any errors that may have occurred. >>> print(serverthread.error) None rNc@seZdZddZddZdS)z!_start_server..DocHandlercSsX|jdrd}nd}|d|dd|||j||j|ddS) 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.csstext/css text/htmlz Content-Typez%s; charset=UTF-8rN) rr}Z send_responseZ send_headerZ end_headersZwfiler urlhandlerr)r3 content_typerrrdo_GET2 s   z(_start_server..DocHandler.do_GETcWsdSrr)r3rrrr log_messageB sz-_start_server..DocHandler.log_messageN)r#rrrrrrrr DocHandler0 srcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dSNF)hostZaddressrr5rhandlerr)r3rportrrrrrH s  z)_start_server..DocServer.__init__cs>|js2|jgggd\}}}|r|q|dSr_)rselectZsocketrZhandle_requestZ server_close)r3ZrdZwrZexrrrserve_until_quitO s  z1_start_server..DocServer.serve_until_quitcSs |j||jr||dSr)r5server_activaterrrrrrV s z0_start_server..DocServer.server_activateN)r#rrrrrrrrr DocServerF s rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dSr)rrr;rThreadrservingerror)r3rrr) threadingrrr] s   z,_start_server..ServerThread.__init__c szzJjj__jj_t|j_|j |j |j }||_ | Wn*tyt}z||_WYd}~n d}~00dS)zStart the server.N)server HTTPServerr5rrZMessageZ MessageClass staticmethodrrrready docserverrrqr)r3Zdocsvre)rremailhttprrre s    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr1)r3rrrrrr sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrrJrr1rrrrstopx s z(_start_server..ServerThread.stopN)r#rrrrrrr)rrrrrrr ServerThread[ s  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrrArrtimesleep)rhostnamerrthreadr)rrrrrrr _start_servers8'   rrc sDGfdddt}|fddfddfddfd d fd d  fd dfddfddfdd f dd}|dr|dd}|dkrtjtjt}tj||}t|}d| WdS1s0Yn|dkr0||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)rzpydoc_data/_pydoc.cssz1a  Pydoc: %s %s%s
%s
r)r3rrcss_pathZcss_link html_navbarrrr s z#_url_handler.._HTMLDoc.pagecSs d||fS)Nz%srr3rrrr4 sz'_url_handler.._HTMLDoc.filelinkN)r#rrrr4rrrr_HTMLDoc s rcs>dttdtf}d|tjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)Zterse)rrZpython_versionZ python_buildZpython_compiler)rcrrrr s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}tjD]}|||qT|d d d |fS)zModule Index page.cSs d||fSNr.rrrrr bltinlink sz3_url_handler..html_index..bltinlinkz7Index of ModulesrQrRcSsg|]}|dkr|qS)rr)rrrrrr sz4_url_handler..html_index..z

zBuilt-in ModulesrVz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr?) rrrr)rrr rrJ)rrnamesrrrrrr html_index s"  z _url_handler..html_indexc sgfdd}t4tddd}tj|||dWdn1sR0Ydd }g}d d d }D]\}}||||qz|d |d dd|}d|fS)zSearch results page.cs:|dddkr |ddd}||o0d|fdSrrirZ search_resultrrr sz3_url_handler..html_search..callbackrcSsdSrrrrrrr sz2_url_handler..html_search..onerrorrNcSs d||fSrrrrrrr sz4_url_handler..html_search..bltinlinkz5Search ResultsrQrRzkey = %srV
zSearch Results) rrrrrrr rrJ) rgrrrrrrrrrrr html_search s$   0 z!_url_handler..html_searchcs~tj|}t|}|}Wdn1s:0Yd|}ddd}|d|dd|}d||fS) z-Get and display a source file listing safely.N

%s
z3File ListingrQrRzFile: %srVz getfile %s) rXrYZunquoterrrrrr)rfprKbodyrrrrr html_getfile s  , z"_url_handler..html_getfilecsLdd}ddd}ttj}||}|ddd|}d|fS)zIndex of topic texts available.cSs d||fSNz%srrrrrr sz4_url_handler..html_topics..bltinlink,INDEXrQrRZTopicsrV)rrrrrdr)r)rrrrrrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.rrQrRcSs d||fSrrrrrrr sz6_url_handler..html_keywords..bltinlinkZKeywordsrV)rrrrrdr)r)rrrrrrr html_keywords s z#_url_handler..html_keywordscst}t||}||\}}||jvr0d}nd}d|dd}d|}|dd|}|rt| }dd } ||} d dd|}d ||fd |||ffS) zTopic or keyword help page.ZKEYWORDZTOPICrMrQrRrrVcSs d||fSrrrrrrr8 sz7_url_handler..html_topicpage..bltinlinkrz%s %sr?) rrrrrrrCrrrr)rrJ)rZbufZhtmlhelprrrrrrrrhtml_topicpage' s,     z$_url_handler..html_topicpagecs@t|dd}|dur$|dkr$tdt|}||}||fS)NrF)rr7zcould not find object)r rrr)r1r2rcontentrrr html_getobjA s   z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,ErrorrQrRrc3s|]}|VqdSr)rrrrrrM rz3_url_handler..html_error..z#bb0000z Error - %s)rrJrr;r)r1rrrrrr html_errorI s  z _url_handler..html_errorc s|}|dr|dd}z*|dvr4\}}n|dkrH\}}n|dkr\\}}nd|vr8|d\}}}|dkr|\}}n|d kr|\}}n|d krz|\}}Wnty|\}}Yn0nZ|d kr.|dvr\}}n2z|\}}Wn ty*|\}}Yn0ntd n |\}}Wn4tyz}z||\}}WYd}~n d}~00||S) zGenerate an HTML page for url.rN)r?rrrrz search?keyz getfile?keyz topic?keyzget?keyz bad pydoc url)r}rrrqr)r1Z complete_urlrroprzr) rrrrrrrrrrr get_html_pageS sB         $z#_url_handler..get_html_pagerrFNrr?rz"unknown content type %r for url %s) rr|r rdirnamerealpathrtrJr readlinesr=)r1rrrZ path_hererrr) rrrrrrrrrrr _url_handler s,         *    0 rT localhost) open_browserrc Csddl}tt||}|jr(t|jdS|jrd}|rB||jzzZtd|jt||jrtd}| }|dkr|qqZ|dkr||jqZt|qZWnt t fytYn0W|jr| tdn|jr| td0dS) 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) webbrowserrrrrrrr1rxrrrr)rrrrZ serverthreadZserver_help_msgrrrrbrowse s8     rcCst|to|tjdkSr)r(r<rr sep)rlrrrispath srcCsvd|vstj|vst|vr"dStjt}tj|}|}||vrbtj||sb||| dt|S)zEnsures current directory is on returned path, and argv0 directory is not Exception: argv0 dir is left alone if it's also pydoc's directory. Returns a new path entry list, or None if no adjustment is needed. r?Nr) r curdirgetcwdrrrtcopysamefileremoveinsert)Z given_pathZargv0Z stdlib_dirZ script_dir revised_pathrrr_get_revised_path s    r cCs,ttjtjd}|dur(|tjdd<dS)zEnsures current directory is on sys.path, and __main__ directory is not. Exception: __main__ dir is left alone if it's also pydoc's directory. rN)r rrargv)r rrr_adjust_cli_sys_path sr c Csddl}Gdddt}tzx|tjddd\}}d}d}d}d}d}|D]\\} } | d krld }d }| d krt| WdS| d krd }| }| d krd }| dkrTd }| }qT|rt|||dWdS|s||D]} t| rtj | st d| qz`t| r&tj | r&t | } |rXt| rNtj | rNt| nt| n t| Wqty} zt | WYd} ~ qd} ~ 00qWnL|j|fytj tj tjdd} t dj| tjdYn0dS)z@Command-line interface (looks at sys.argv to decide what to do).rNc@s eZdZdS)zcli..BadUsageN)r#rrrrrrBadUsage rr rFzbk:n:p:wFrz-bTz-kz-pz-wz-n)rrzfile %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} -n Start an HTTP server with the given hostname (default: localhost). {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. This option can be used in combination with -n and/or -p. {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)getoptrqr rr rrrr rexistsrrrr rrrrrrrr&r)rr ZoptsrZwritingZ start_serverrrrZoptvalargrhrrrrcli s`    $rr)NN)r)r)r rN)r rN)r)r?N)r)r)^r8rWrwrqrvrZimportlib._bootstraprimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrr r\rr@rrrrZ urllib.parserXr collectionsrreprlibr tracebackrrrr7r0r>rDrLrNrRrTrYr7 IGNORECASErZr\r^rcrmrrrrrrrqrrrrrrrrrrrrrrrrrrr rSrrr rr6rrrrrrrrrrr r rr#rrrrs*      3      ' 0;*; $ ,    = % U