a _h@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)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 -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 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)dirsZnormdirsdirnormdirr&/opt/imh-python/lib/python3.9/pydoc.pypathdirsQs    rcCsPtj|j}|durdS|jdddD]}t||}q.t|sLdS|S)Nr) rmodulesget __module__ __qualname__splitgetattrinspectisclass)funcclsnamerrr _findclass]s  r c 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_finddocgsZ              r8cCsdzJt|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__typer9r)strr2)r3r7Ztypedocrrrr1s   r1c 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)r1r8r2 TypeErrorr)r=rZcleandoc)r:r7rrr_getdocs  r?cCs,t|pt|}|r(tdd|p*dS)z-Get the doc string or comments for an object.z^ * )r?rZ getcommentsresubrstrip)r:resultrrrgetdocsrEcCsf|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)striprlenrCjoin)r7linesrrrsplitdocs   rMcCs"|j}|j|kr|jd|}|S)z@Get a class name and qualify it with a module name if necessary.r)r$r)r:modnamerrrr classnames rOcCs>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 istracebackZiscoder:rrrisdatasrScGs.|r*|d||d}|dd}q|S)z/Do a series of global replacements on a string.rGrrHN)rKr)textpairsrrrreplacesrVcCsXt||krTtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrHN...)rJmax)rTmaxlenpreZpostrrrcrams  $r\z at 0x[0-9a-f]{6,16}(>+)$cCs td|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidrBrTrrrstripidsr_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(rrP)fnr4rrr_is_bound_methods    racCs^i}t|tjD]\}}d||<q|jD]}|t|q*|D]}t||||<qF|SNrG)r getmembersrQ __bases__update allmethodskeysr)clmethodskeyvaluer6rrrrfs   rfcCs8g}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 predicateZyesnoxrrr _split_lists  rqcCs\|dvr dS|dr$|dr$dS|drr"__date__ __version__r9__file__ __package__ __loader__ __credits____path__ __author____spec__r __cached__ __builtins__r$rr__rG__fieldsTN) startswithendswithhasattr)rallr3rrr 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 )r:resultsrkindrrkrrrr%s rcsZt|dgzfddtDWnty<iYn0fdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namercsi|]\}}||tqSr)rJ).0ir)fieldsrr 6z#sort_attributes..cs|dd|dfSNr)r)attr) field_orderrr9rz!sort_attributes..rjN)r enumerater>sort)attrsr:Zkeyfuncr)rrrsort_attributes0s    rcCs:tj|r6dD]$}tjtj|d|rdSqdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfilerK)rextrrr ispackage>s  rcCs|}|dddks |s0|}|sq0q|}|dddkrT|dd}|dddkr|dd}|dddkr|dd}|s|}|sqq|dd }nd}|S) NrG#zr"""rW"""r\r)readlinerIr)filelinerDrrrsource_synopsisFs 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_mtimerrtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrrr9 splitlines) filenamecachemtimeZ lastupdaterDZ loader_clsrrspecmodulerrrsynopsisWs6    (   rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dSN)rexcrktb)r4rexc_inforrrrszErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr$rrk)r4rrrr__str__szErrorDuringImport.__str__N)r$rrr9rrrrrrr~src 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..NrrG)rrbuiltin_module_names __import__rrrt SyntaxErrorr issubclass ImportErrorrrrr2) r forceloadrZsubsrjrrrkrinfopartrrr safeimports*    rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrHcGs||f|}zFt|r$|j|WSt|r:|j|WSt|rP|j|WSWntydYn0t|rz|j |S|j |S)z%Generate documentation for an object.) rrP docmodulerdocclassrQ docroutiner2r,docdatadocother)r4r:rargsrrrdocuments  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>)r4r:rrmessagerrrfailszDoc.failZstdlibcCszt|}Wnty$d}Yn0tjd|j}tj|}t |t tr|j dvsx| |r| 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 exceptionsgcZimpmarshalposixsignalr_threadZ zipimportz site-packages)z xml.etreeztest.pydoc_mod)zhttp://zhttps://z%s/%s/.htmlN)r getabsfiler>r environrrrr r)r<r$rrKrClower)r4r:Zbasedirrdoclocrrr 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 maxstringmaxotherr4rrrrs  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)rVr4rTrrrescape szHTMLRepr.escapecCs t||Sr)rrr4r:rrrrsz HTMLRepr.reprcCsZtt|dr@ddt|j}t||r@t||||S|ttt ||j SNr$repr_r~) rr<rKr$rrrr\r_rrr4rplevelZ methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|vrJdt|ddvrJd|d|||dStdd||S)Nr\\r@rrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r\rrrVrrArBr4rpr testZtestreprrrr repr_strings zHTMLRepr.repr_stringcCs@z|ttt||jWS|d|jjYS0dSNz <%s instance>)rr\r_rrr&r$r4rpr rrr repr_instance&szHTMLRepr.repr_instanceN) r$rrr9rrrrrrepr_strrZ repr_unicoderrrrrs 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)r4titlecontentsrrrpage7sz HTMLDoc.pager@cCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
 r)r4rfgcolbgcolextrasrrrheadingAszHTMLDoc.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) r4rrrrwidthZpreludeZ marginaliaZgaprDrrrsectionLs zHTMLDoc.sectioncGsd|}|j|g|RS)z$Format a section with a big heading.z%s)r$)r4rrrrr bigsectionbszHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text. z rrrF
)r expandtabsrVrrrr preformatgs 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@rGzrr'zz7%s
)rJrange)r4listformatZcolsrDrowscolrrrr multicolumnms   zHTMLDoc.multicolumncCsd|S)Nz%srrrrrgreyyrz HTMLDoc.greycGs*|D] }||vrd|||fSq|S)z:Make a link for an identifier, given name-to-URL mappings.%sr)r4rZdictsr/rrrnamelink{szHTMLDoc.namelinkcCsN|jtj|j}}t||rDt|||urDd|j|t||fSt||S)zMake a link for a class.z%s)r$rrrrrrrO)r4r:rNrrrrr classlinks zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.%s)r$r rrr 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)r1)r0)r4Z modpkginforrrshadowedurlrTrrr modpkglinks   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%sr)r4r7rrrrfilelinkszHTMLDoc.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"r1z'http://www.rfc-editor.org/rfc/rfc%d.txtz)https://www.python.org/dev/peps/pep-%04d/rG(zself.zself.%sNr@) rrAcompilesearchspanr groupsrVintr2rK)r4rTrfuncsclassesrirherepatternmatchstartendrschemeZrfcZpepZselfdotrr7rrrmarkups8      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"

r;, )z
z
%s
z
%s
)r<r3r rK formattree) r4treerNparentrDentrycbasesparentsr6rrrrLs"  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 %srrz (%s)rJz-
Module Referencer@#ffffff#7799eezindex
rz.html#z#-z %sz

%s

rxrzPackage Contentsz#aa55cccs|dSrb)r5trrrr5rz#HTMLDoc.docmodule..ZModulescSsg|] \}}|qSrrrrjrkrrrr:rz%HTMLDoc.docmodule..ZClasses#ee77aarZ Functionsz#eeaa77ZDataz#55aa55r'ryZAuthorrwZCredits)6r$__all__r2rr*rJr rKrrurllibparsequoter9r>rr=rsrIrrrrlocalsr!rcrPr getmodulerrdrrrrrrQr(r'rSrIrEr)pkgutil iter_modulesrxrr/r8r%rL getclasstreerryrw)#r4r:rmodignoredrpartsZlinksrZ linkednameheadrr7r9rversionrrDrrBZcdictrjrkr6rNrrAZfdictdatar7modpkgsimporterispkgr 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|_dSrZneedonerrrrrdsz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
rGrprpushrrmaybefsz.HTMLDoc.docclass..HorizontalRule.maybeNr$rrrrsrrqrrHorizontalRulecsrurHz&
Method resolution order:
z
%s

c st||\}}|r||D]b\}}}}zt|}Wn$tyd||Yn0||dq&|S)NrFrqrsr ExceptionrrmsgrrnokrrhomeclsrkrBrAhrmdictrfr:rrr4rrspillvs   zHTMLDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrqrsrryr~rfrrr4rrspilldescriptorssz*HTMLDoc.docclass..spilldescriptorsc st||\}}|r||D]r\}}}}t||}t|} | s`d|n0t|j} d| } d|| fdq&|S)Nz
%s
z
%sz
%s%s
rF)rqrsrrrErIr)) rzrrnr{rrr|rkr6r7r}rr spilldatas  z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS)r3rrrrrrkrRrrrs  z$HTMLDoc.docclass..r-rcs |duSNrHrrY thisclassrrrrz"HTMLDoc.docclass.. defined hereinherited from %sz:
z Methods %scSs |ddkSNrGmethodrrYrrrrrzClass methods %scSs |ddkSNrGz class methodrrYrrrrrzStatic methods %scSs |ddkSNrGz static methodrrYrrrrrzReadonly properties %scSs |ddkSNrGrrrYrrrrrzData descriptors %scSs |ddkSNrGrrrYrrrrrzData and other attributes %scSs |ddkSNrGrkrrYrrrrrr@z*class %sz/%s = class %s(%s)rJN()r&z%s
 
z#000000z#ffc8d8rW)r$rdr rrgetmrorJrsr3rrrrxr>popleftrqbuiltinsr:rrK signature ValueErrorr=rrErIr)r$)r4r:rrfrArBrgrealnamerQrrumror6rrrrrjrr|rkanchor inheritedtagrrRdeclrargspecr7r) rBrAr~rrfr:rrr4rrrXs                   zHTMLDoc.docclasscCs|d||Sz)Format an argument default value as text.=)r0rr rrr 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%srGz)%s = %sz$%s lambda r(...)z'%sz
%s
z
%s
z
%s
%s
)r$rar%r&r3riscoroutinefunctionisasyncgenfunctiongetattr_staticrQrrr>r=rr0rIrEr))r4r:rrfrArBrirhrrnoteskipdocsimclassasyncqualifierrZreallinkrrrr7rrrrsl       zHTMLDoc.docroutinecCsNg}|j}|r|d||t||j}|r<|d||dd|S)z1Produce html documentation for a data descriptor.z!
%s
z
%s
rvr@)r rIrEr)rKr4r:rrfrhrrrr7rrrr?s  zHTMLDoc.docdatacGs|r d|pd}|||S)z-Produce HTML documentation for a data object.z%s = r@r)r4r:rrfrgZlhsrrrrOszHTMLDoc.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 Yrz HTMLDoc.index..r@rGrWr\)rcrdanyr rr/r8r%)r4rr6rlrmrrnrrrrindexTs  z HTMLDoc.index)r@)r"r@Nr)r)N)NN)NNN)NN)N)r$rrr9r_repr_instancerrrr!r$r%r)r/r0r2r3r5r8r9rIrLrrrrrrrrrrrrr.s>   +  y# A  rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,t|d|_|_d|_d|_|_dSrrrrrrrgs  zTextRepr.__init__cCsTtt|dr@ddt|j}t||r@t||||Sttt||j Sr ) rr<rKr$rrr\r_rrr rrrrms  zTextRepr.repr1cCsHt||j}t|}d|vrDdt|ddvrDd|d||dS|S)Nrrr@rr)r\rrrVrrrrrts  zTextRepr.repr_stringcCs4zttt||jWSd|jjYS0dSr)r\r_rrr&r$rrrrrszTextRepr.repr_instanceN) r$rrr9rrrrrrrrrres  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..)rKrrrrboldsz 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..rFr)rrCrK)r4rTrrLrrrindentszTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rFr&)rrCr)r4rrZclean_contentsrrrr$szTextDoc.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|VqdSrrO)rrPrNrrrrz%TextDoc.formattree..rrJrFr)r<rOrKrL) r4rMrNrNrrDrOrPrQrRrrrrLs  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 - 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 DESCRIPTIONrx (package)zPACKAGE CONTENTSrFrZ SUBMODULEScSsg|] \}}|qSrrr[rrrrrz%TextDoc.docmodule..rGCLASSES FUNCTIONSF)rZZDATArsrTrUrrVVERSIONrrZDATEryZAUTHORrwZCREDITSrFILE)%r$rMrEr$rrrrcrrbrr rQr(rSsetrrcrdrxaddrrKrPrrLrerrr=rsrIrrryrwrr>)r4r:rrfZsynopdescrDrrrBrjrkrArkrlZ modpkgs_namesrmrNrnZ submodulesrorrjrrrrrs                 $    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)rPrrrrmakenamesz"TextDoc.docclass..makenameclass z = class rrJNrrFrHzMethod resolution order:rr@css.|]&}|jds|jdkrt|jVqdS)r~rN)r$rrr=)rrrrrr?sz#TextDoc.docclass..rrzBuilt-in subclasses:z ... and z other subclassescs eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dSrrprrrrrQsz1TextDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)NzF----------------------------------------------------------------------rGrprrqrrrsSsz.TextDoc.docclass..HorizontalRule.maybeNrtrrqrrruPsruc st||\}}|r|||D]T\}}}}zt|}Wn$tyd||Yq&0||q&|Srrwryr~rfr:rrr4rrrYs zTextDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrryrrrrjsz*TextDoc.docclass..spilldescriptorsc st||\}}|r||D]\\}}}}t|}zt|} Wntyd|j|} Yn0j| |d|ddq&|S)Nr)rZr7rF)rqrsrErr2__dict__r) rzrrnr{rrr|rkr7r3rrrrss z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqSrrrrRrrrs  z$TextDoc.docclass..rcs |duSrrrYrrrrrz"TextDoc.docclass..rrz Methods %s: cSs |ddkSrrrYrrrrrzClass methods %s: cSs |ddkSrrrYrrrrrzStatic methods %s: cSs |ddkSrrrYrrrrrzReadonly properties %s: cSs |ddkSrrrYrrrrrzData descriptors %s: cSs |ddkSrrrYrrrrrzData and other attributes %s: cSs |ddkSrrrYrrrrrz | )r$rdrrmaprKr rrrr>r=rErrrJsortedr<__subclasses__rrrrqrr:rOrrrC)r4r:rrfrgrrQrrrRrrrr7rr6Z subclassesZno_of_subclassesZMAX_SUBCLASSES_TO_DISPLAYZ subclassnamerurrrrrrr)r~rfr:rrr4rrrs                   zTextDoc.docclasscCsd||Srrr rrrrszTextDoc.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@rrNrrrrG = rz lambda rrrF)r$rar%r&rOrrrrrrQrrr>r=rErrC)r4r:rrfrhrrrrrrrrrr7rrrrsT       zTextDoc.docroutinecCsTg}|j}|r$||||dt|p.d}|rJ||||dd|S)z1Produce text documentation for a data descriptor.rFr@)r rrErrKrrrrrs 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@rNrXrF)rrJrrErr=) r4r:rrfrNrZr7rrZchoprrrrs  zTextDoc.docother)r)Nr@)NN)NN)NNN)NNN)NNNNN)r$rrr9rrrrrr$rLrrrrrrrrrrrrs   e  7 rc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|Srrrrrrr sz_PlainTextDoc.boldN)r$rrr9rrrrrrsrcCstat|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 dkrddSddl }| \}}t |zRttd r,t d|dkr,ddWt|StWt|SWt|n t|0dS)z2Decide what method to use for paging through text.isattyZMANPAGERZPAGERwin32cstt|Sr tempfilepagerplainr^Z use_pagerrrrrzgetpager..ZTERM)ZdumbZemacscstt|Sr) pipepagerrr^rrrr!rcs t|Srrr^rrrr#rcSstt|dS)Nzmore /dev/nullrcSs t|dS)NZlessrr^rrrr)rNz more "%s"cSs t|dS)NZmorerr^rrrr0r)rrstdin plainpagerstdoutrr rrplatformrtempfilemkstempcloseunlinkttypager)rfdrrrrrs>            rcCstdd|S)z%Remove boldface formatting from text.z.r@)rArBr^rrrr6src Csddl}|j|d|jd}zVtj|jdd2}z||WntyNYn0Wdn1sd0YWntyYn0z| WqWqtyYq0qdS)z3Page through text by feeding it to another program.rNT)shellrbackslashreplace)errors) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)rTcmdrprocpiperrrr:s (  rc Csddl}|}tj|d}t|ddtjdkr.cSstjddddS)NrrG)rrrrrrrrmrLINESrGz -- more --)qQz ) rF)bB)rrrttyrrfilenoZ tcgetattrZ setcbreakrr2rUnsupportedOperationr@r rrrrrrKflushZ tcsetattrZ TCSAFLUSH) rTrLrroldZgetcharhrZincrPrrrrbsN              & 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 rxzpackage zmodule zbuilt-in function zgetset descriptor %s.%s.%szmember descriptor %s.%s.%srz function zmethod )rrPr$rrrr(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..rrNrG)rrJrrKrrr2)rrrhrnZ nextmoduler:rrrrlocates   rcCsVt|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=rrr)rrr:rrrrresolves   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&)rTrrrrbrfindr$rPrrQr,r?rrr<r)rrrZrendererr:rrrrrr 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)rrroutputrkrrrr7s r7c 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-)functionr@)del BASICMETHODSif)elser-try)forzbreak continue whileimport)globalznonlocal NAMESPACES)r3 TRUTHVALUE)r7MODULES)inSEQUENCEMETHODS COMPARISON)lambdar)nonlocalzglobal NAMESPACES)passr@)raise EXCEPTIONS)returnr)r5rB)whilezbreak continue if TRUTHVALUE)r(z CONTEXTMANAGERS EXCEPTIONS yield)yieldr@)$FalseNoneTrue__peg_parser__andasr)r*r+r,r.r/defr1elifr4exceptfinallyr6fromr8r3r7r;isr>r?notorr@rArCr5rDr(rEcCsg|]}dD] }||q qS)'r:r)rprrrrrArzHelper.)r frurUz'''r:r)+r***rz//%<<>>r|^~rr<=>===!=<>)rrrbrcrdrerf)rra) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)r]r^rr_r`ra)jJ)STRINGS OPERATORSr=UNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classri PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)r\r[,rrX:@rr~r}`r;rK[]r)typeszRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES)zstring-methodszSTRINGS FORMATTING)Z formatstringsrj)ryz: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@)rxz!class SPECIALMETHODS PRIVATENAMES)Z typesmodulesr7)zoperator-summaryzlambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIES EXPRESSIONS)Zobjectsr{)Z specialnameszbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES)Z customizationzhash repr str SPECIALMETHODS)zattribute-accesszATTRIBUTES SPECIALMETHODS)zcallable-typeszCALLS SPECIALMETHODS)sequence-typesz(SEQUENCES SEQUENCEMETHODS SPECIALMETHODS)r~zMAPPINGS 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<)Zcallsr})Zpowerr})Zunaryr})binaryr})Zshiftingr})Zbitwiser})Z comparisonszEXPRESSIONS BASICMETHODS)ZbooleanszEXPRESSIONS TRUTHVALUEr))Z assignmentrl)Z augassign NUMBERMETHODSr1rC)Zcompoundzfor while break continue)truthz if while and or not BASICMETHODS)ZdebuggerZpdb)zcontext-managersr()Ir{riZ STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERFLOATrnrZMAPPINGSrZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSNONErpZSPECIALATTRIBUTESrr:ZPACKAGESr}rjZ PRECEDENCEZOBJECTSZSPECIALMETHODSr2ZATTRIBUTEMETHODSZCALLABLEMETHODSr<ZMAPPINGMETHODSrZ EXECUTIONrZDYNAMICFEATURESZSCOPINGZFRAMESrBZ CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSrqZLITERALSZTUPLESZ TUPLELITERALSZLISTSrrzrZ ATTRIBUTESZ SUBSCRIPTSr|ZCALLSrorkZBINARYZSHIFTINGrmr=r'Z ASSERTIONZ ASSIGNMENTrlZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGr9Z DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dSr)_input_output)r4inputrrrrrszHelper.__init__cCs |jp tjSr)rrrrrrrrsz Helper.inputcCs |jp tjSr)rrrrrrrrsz Helper.outputcCs2tdddkr|dSd|jj|jjfS)NrGrW?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. )_GoInteractiverintrointeractrrr4Zrequestrrr__call__s   zHelper.__call__c Cs|jdz|d}|s WqWnttfy<YqYn0|}t|dkr|d|dkrndvrnn |d|ddvr|dd}|dvrq|d kr|q | |q dS) NrFzhelp> rHrrrTrG)rquitr) rrgetlinerEOFErrorrIrJrrrrrrrrs    ,  zHelper.interactcCs8|jtjurt|S|j||j|jSdS)z.Read one line, using input() when appropriate.N)rrrrrrr)r4promptrrrrs    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 rG)rHrFrGz Help on %s:)rrF)r<rI listkeywords listsymbols listtopics listmodulesrr showsymbolr7evalr showtopicrrr=r)r&rrrrrrrs$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.%drH)rrr,rrrrrrrs z Helper.introrPc Cstt|}||}t||d|}t|D]v}t|D]\}|||}|t|kr<|j||||dkr<|jdd|dt||q<|jdq0dS)NrGrrF)r+rrJr*rr) r4itemscolumnsr#Zcolwr-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+rrgrrrrr.s 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+rrgrrrrr5s zHelper.listsymbolscCs |jd||jdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrr+rrgrrrrr=s 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@rFrRelated help topics: rJHz %s )pydoc_data.topicsrrrrrrrr<rKeyErrorrItextwraprKrwrapr) r4topic more_xrefs pydoc_datatargetlabelxrefsr7rrTZ wrapped_textrrrrDs4       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)r4rrrrrrr7rrrrds      zHelper._gettopiccCs*|j|}|d\}}}|||dS)Nr)r partitionr)r4symbolrrr~rrrrrs 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__rrrrG)find)rrNrrrrrcallbacksz$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+rg)r4rjrrrrrrs     zHelper.listmodules)NN)rr)r@)r@)r@)!r$rrrZ _strprefixesZ_symbols_inverserrrZsymbols_rrrrr*rrrr:rrrrrrr+rrrrrrrrrrrr& sD(    W       r&c@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__rGr@rFrrr get_source get_filenamert)rrrrrr9rrrcr" _get_specrrrrrxrrStringIOrrrrrrr)r4rrjZ completerrseenrNrrrmrnrrsourcerrrrrrs^            zModuleScanner.run)NNN)r$rrr9rrrrrrsrcCsXdd}dd}t,tdtj|||dWdn1sJ0YdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dSNrrrz- )rrrNrrrrrszapropos..callbackcSsdSrrrrrrrszapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rjrrrrrrs   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) rrZ send_responseZ send_headerZ end_headersZwfiler urlhandlerr)r4 content_typerrrdo_GET, s   z(_start_server..DocHandler.do_GETcWsdSrr)r4rrrr log_message< sz-_start_server..DocHandler.log_messageN)r$rrrrrrrr DocHandler* srcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dSNF)hostaddressrr6rhandlerr)r4rportrrrrrB s  z)_start_server..DocServer.__init__cs>|js2|jgggd\}}}|r|q|dSrb)rselectsocketrZhandle_requestZ server_close)r4Zrdwrexrrrserve_until_quitI s  z1_start_server..DocServer.serve_until_quitcSs |j||jr||dSr)r6server_activaterrrrrrP s z0_start_server..DocServer.server_activateN)r$rrrrrrrrr DocServer@ s rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dSr)rrr@rThreadrservingerror)r4rrr) threadingrrrW 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 HTTPServerr6rrZMessageZ MessageClass staticmethodrrrready docserverrrxr)r4Zdocsvre)rremailhttprrr_ s    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr7)r4rrrrrl sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrrKrr7rrrrstopr s z(_start_server..ServerThread.stopN)r$rrrrrrr)rrrrrrr ServerThreadU s  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrrFrrtimesleep)rhostnamerrthreadr)rrrrrrr _start_servers8'   rrcs6Gfdddt}|fddfddfddfd d fd d fd dfddfddfdd}|dr|dd}|dkrtjtjt}tj||}t|}d| WdS1s0Yn|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. cseZdZfddZdS)z_url_handler.._HTMLDoccsd}d|}d|||fS)rzpydoc_data/_pydoc.cssz1a  Pydoc: %s %s%s
%s
r)r4rrcss_pathZcss_link html_navbarrrr s z#_url_handler.._HTMLDoc.pageN)r$rrrrrrr_HTMLDoc srcs>dttdtf}d|tjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)Zterse)rrZpython_versionZ python_buildZpython_compiler)rjr rrr s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}tjD]}|||qT|d d d |fS)zModule Index page.cSs d||fSNr4rrrrr bltinlink sz3_url_handler..html_index..bltinlinkz7Index of ModulesrWrXcSsg|]}|dkr|qS)rr)rrrrrr sz4_url_handler..html_index..z

zBuilt-in Modulesr\z|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr@) r!rrr/r%rr rrK)rr!namesrrrrrr 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|fdSrrlrZ search_resultrrr sz3_url_handler..html_search..callbackrcSsdSrrrrrrr sz2_url_handler..html_search..onerrorrNcSs d||fSrrrrrrr sz4_url_handler..html_search..bltinlinkz5Search ResultsrWrXzkey = %sr\
zSearch Results) rrrrrr!r r%rK) rjrrrrr!rrrrrr html_search s$   0 z!_url_handler..html_searchcsLdd}ddd}ttj}||}|ddd|}d|fS)zIndex of topic texts available.cSs d||fSNz%srrrrrr sz4_url_handler..html_topics..bltinlink,INDEXrWrXZTopicsr\)r!rr&rrgr/r%)rr!rrrrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.rrWrXcSs d||fSrrrrrrr sz6_url_handler..html_keywords..bltinlinkZKeywordsr\)r!rr&rrgr/r%)r!rrrrrr 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.ZKEYWORDZTOPICrSrWrXz

%s
r\cSs d||fSrrrrrrr" sz7_url_handler..html_topicpage..bltinlinkrz%s %sr@) rrr&rrr!rIr%rrr/r$rK)rbufZhtmlhelprrrr!rrrrhtml_topicpage s,     z$_url_handler..html_topicpagecs@t|dd}|dur$|dkr$tdt|}||}||fS)NrG)rrGzcould not find object)rrrr)r7r3rcontentrrr html_getobj+ s   z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,ErrorrWrXrc3s|]}|VqdSr)rrrrrr7 rz3_url_handler..html_error..z#bb0000z Error - %s)r!rKrr<r%)r7rr!rrrr html_error3 s  z _url_handler..html_errorc sp|}|dr|dd}z|dvr2\}}n|dkrF\}}n|dkrZ\}}nd|vr |d\}}}|dkr|\}}n|d krz|\}}Wnty|\}}Yn0nZ|d kr|dvr\}}n2z|\}}Wn ty|\}}Yn0ntd n |\}}Wn4tyb}z||\}}WYd}~n d}~00||S) zGenerate an HTML page for url.rN)r@rrrrz search?keyz topic?keyzget?keyz bad pydoc url)rrrrxr)r7Z complete_urlrr opr~r)r r r rrrrrrr get_html_page= s>          $z#_url_handler..get_html_pagerrGNrr@rz"unknown content type %r for url %s) rrr rdirnamerealpathrtrKr readlinesr>)r7rrrZ path_hererfpr) r r r rrrrrrr _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> rr zServer stopped) webbrowserrrrrrrr7rrrrr)rrrrZ serverthreadZserver_help_msgrrrrbrowser s8     rcCst|to|tjdkSr)r)r=rr sep)rprrrispath 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$rGzbk: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)getoptrxr#rr"rrrr rexistsrrrr r%r!rrrrrr,r)r%r$ZoptsrwritingZ start_serverrrroptvalargrkrrrrcli s`    $r+r)NN)r)r)rrN)rrN)r)r@N)r)r)^r9r]ryrrrwrZimportlib._bootstraprZimportlib._bootstrap_externalZimportlib.machineryimportlib.utilrrr rcrrArrrr urllib.parser^r collectionsrreprlibr tracebackrrr r8r1r?rErMrOrSrVr\r< IGNORECASEr]r_rarfrqrrrrrrrxrrrrrrrrrrrrrrrrrrrrTrr rrr7r!r%r&rrrrrrrr!r#r+r$rrrrs&      3      ' 0:*; " ,    = n% U