a DOg,@s*dZdgZdZdZdZddlZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZd d Zd d Z ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(ddZ)d d!Z*e+d"ej,Z-d#d$Z.d%d&Z/d'd(Z0d)d*Z1dd+d,Z2d-d.Z3d/d0Z4d1d2Z5d3d4Z6ifd5d6Z7Gd7d8d8e8Z9d9d:Z:difd;d<Z;Gd=d>d>ZGdCdDdDeZ?GdEdFdFe<Z@GdGdHdHe@ZAdIdJaBdKdLZCdMdNZDdOdPZEdQdRZFdSdTZGdUdVZHdWdXZIdYdZZJdd[d\ZKe@ZLeAZMe>ZNdd]d^ZOdd`daZPddbdcZQddddeZRddgdhZSGdidjdjZTeTZUGdkdldlZVdmdnZWdodpZXddrdsZYddtdudvdwdxZZdydzZ[d{d|Z\d}d~Z]ddZ^e_dkr&e^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)dirsZnormdirsdirZnormdirr*/opt/alt/python39/lib64/python3.9/pydoc.pypathdirsRs    rcCst|ot|tj SN)inspectZisclass isinstancetypes GenericAliasobjectrrr_isclass^srcCsNtj|j}|durdS|jdddD]}t||}q.t|sJdS|S)Nr)rmodulesget __module__ __qualname__splitgetattrr)funcclsnamerrr _findclassas r%c Cst|rH|jj}|j}t|r>tt||dd|jur>|}n|j}n"t|r||j}t |}|dusvt|||urzdSnt |r|j}|j}t|r|j d||j kr|}n|j}nt |t r|j}|j}t |}|dust|||urdSntt|st|rf|j}|j}t|||ur.dSt|rjt|dd}t |trj||vrj||SndS|jD]F}ztt||}WntyYqpYn0|durp|SqpdS)N__func__r __slots__)rismethodr&__name____self__rr! __class__ isfunctionr% isbuiltinrrpropertyfgetZismethoddescriptorisdatadescriptor __objclass__ismemberdescriptordict__mro__ _getowndocAttributeError)objr$selfr#r"slotsbasedocrrr_finddocksZ            r<cCsdzJt|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)r__getattribute__typer=rstrr6)r7r;Ztypedocrrrr5s   r5c 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)r5r<r6 TypeErrorrr@rZcleandoc)rr;rrr_getdocs  rBcCs,t|pt|}|r(tdd|p*dS)z-Get the doc string or comments for an object.z^ * )rBrZ getcommentsresubrstrip)rresultrrrgetdocsrHcCsf|d}t|dkr&|ddfSt|dkrX|dsX|dd|ddfSdd|fS)z>Split a doc string into a synopsis line (if any) and the rest. rrCN)stripr lenrFjoin)r;linesrrrsplitdocs   rPcCs"|j}|j|kr|jd|}|S)z@Get a class name and qualify it with a module name if necessary.r)r)r)rmodnamer$rrr classnames rRcCs<t|p8t|p8t|p8t|p8t|p8t| S)z>Check if an object is of a type that probably means it's data.)rismoduler isroutineZisframeZ istracebackZiscoderrrrisdatasrUcGs.|r*|d||d}|dd}q|S)z/Do a series of global replacements on a string.rJrrKN)rNr )textZpairsrrrreplacesrWcCsXt||krTtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrKN...)rMmax)rVmaxlenZpreZpostrrrcrams  $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_stripidrErVrrrstripidsr_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-r!rS)fnr8rrr_is_bound_methods    racCs^i}t|tjD]\}}d||<q|jD]}|t|q*|D]}t||||<qF|SNrJ)r getmembersrT __bases__update allmethodskeysr!)clmethodskeyvaluer:rrrrfs   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 predicateZyesZnoxrrr _split_lists  rpcCs\|dvr dS|dr$|dr$dS|dr __cached__r __author__ __builtins__ __credits__r)__path____file__ __package____spec__ __version__r=r'__date__ __loader__rr__rJ__fieldsTN) startswithendswithhasattr)r$allr7rrr 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_attrsr0rr.fsetr )rresultsr$kindr#rkrrrr)s rcsZt|dgzfddtDWnty<iYn0fdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namer~csi|]\}}||tqSr)rM).0ir$)fieldsrr :z#sort_attributes..cs|dd|dfSNr)r)attr) field_orderrr=rz!sort_attributes..rjN)r! enumeraterAsort)attrsrZkeyfuncr)rrrsort_attributes4s    rcCs:tj|r6dD]$}tjtj|d|rdSqdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfilerN)rextrrr ispackageBs  rcCs|}|dddks |s0|}|sq0q|}|dddkrT|dd}|dddkr|dd}|dddkr|dd}|s|}|sqq|dd }nd}|S) NrJ#zr"""rX"""r\r)readlinerLr )filelinerGrrrsource_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_mtimerrtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrrr= splitlines) filenamecachemtimeZ lastupdaterGZ loader_clsrrspecmodulerrrsynopsis[s6    (   rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dSr)rexcrktb)r8rexc_inforrrrszErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr)rrk)r8rrrr__str__szErrorDuringImport.__str__N)r)rrr=rrrrrrrsrc 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..NrrJ)rrbuiltin_module_names __import__rrrv SyntaxErrorr issubclass ImportErrorr$r r!r6) r forceloadrZsubsrjrrrkrinfopartrrr safeimports*    rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrKcGs||f|}zDt|r$|j|WSt|r8|j|WSt|rN|j|WSWntybYn0t|rx|j |S|j |S)z%Generate documentation for an object.) rrS docmodulerdocclassrT docroutiner6r0docdatadocother)r8rr$argsrrrdocuments  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)rA)r8rr$rmessagerrrfailszDoc.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 exceptionsZgcZimpmarshalposixsignalr_threadZ zipimportz site-packages)z xml.etreeztest.pydoc_mod)zhttp://zhttps://z%s/%s/.htmlN)r getabsfilerAr environrrrr rr?r)rrNrFlower)r8rZbasedirrdoclocrrr 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 maxstringmaxotherr8rrrr s  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)rWr8rVrrrescapeszHTMLRepr.escapecCs t||Sr)rrr8rrrrrsz HTMLRepr.reprcCsZtt|dr@ddt|j}t||r@t||||S|ttt ||j SNr)repr_r}) rr?rNr)r r!rr\r_rrr8rolevelZ methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|vrJdt|ddvrJd|d|||dStdd||S)Nr\\rCrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r\rrrWrrDrEr8ror testZtestreprrrr repr_strings zHTMLRepr.repr_stringcCs@z|ttt||jWS|d|jjYS0dSNz <%s instance>)rr\r_rrr+r)r8ror rrr repr_instance*szHTMLRepr.repr_instanceN) r)rrr=rrrr rrepr_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)r8titlecontentsrrrpage;sz HTMLDoc.pagerCcCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
 r)r8rfgcolbgcolZextrasrrrheadingEszHTMLDoc.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) r8rrrrwidthZpreludeZ marginaliaZgaprGrrrsectionPs zHTMLDoc.sectioncGsd|}|j|g|RS)z$Format a section with a big heading.z%s)r )r8rrrrr bigsectionfszHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text. z rrrI
)r expandtabsrWrrrr preformatks 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.rCrJzrr#zz7%s
)rMrange)r8listformatZcolsrGrowscolrrrr multicolumnqs   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)r8r$Zdictsr3rrrnamelinkszHTMLDoc.namelinkcCsN|jtj|j}}t||rDt|||urDd|j|t||fSt||S)zMake a link for a class.z%s)r)rrrrrr!rR)r8rrQr$rrrr 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,)r8Z modpkginfor$rrshadowedurlrVrrr modpkglinks   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%sr)r8r3rrrrfilelinkszHTMLDoc.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)https://www.python.org/dev/peps/pep-%04d/rJ(zself.zself.%sNrC) rrDcompilesearchspanr groupsrWintr.rN)r8rVrfuncsclassesrirherepatternmatchstartendrZschemeZrfcZpepZselfdotr$r3rrrmarkups8      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().rCrz"

r7, )z
z
%s
z
%s
)r?r/r rN formattree) r8treerQparentrGentrycbasesparentsr:rrrrGs"  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|tD]Z\}}|dust|p||urt|||r|||fd|||<||<q|D]\}}|jD]n}|j|j}}tj !|}||kr:|r:t||r:t"|||ur:||vr:|d|||<||<q:q,gi}}t|tj#D]p\}}|dust$|st||urt|||r|||fd|||<t%|r||||<qg}t|t&D]&\}}t|||rH|||fqH't(|j)||}|od|}|d|}t|drg}t*+|j,D]\}}} |||| dfq|-.|j/}!|0ddd|!}n.|r6.|fdd}!|0d dd|!}|rd!d"|D}"1t2|"d|g}!|D]"\}}|!3|||||qd|0d#dd$d%|!}|rg}!|D]"\}}|!3|||||q|0d&dd'd%|!}|r4g}!|D]\}}|!3||q|0d(dd)d*|!}t|d+rh't|j4j)}!|0d,dd|!}t|d-r't|j5j)}!|0d.dd|!}|S)/z/Produce HTML documentation for a module object.NrrJz5%sr)%srry $Revision: $z version %srzz (%s)rEz-
Module ReferencerC#ffffff#7799eezindex
rz.html#z#-z %sz

%s

rurzPackage Contentsz#aa55cccs|dSrb)r1trrrr9rz#HTMLDoc.docmodule..ZModulescSsg|] \}}|qSrrrrjrkrrrr>rz%HTMLDoc.docmodule..ZClasses#ee77aarZ Functionsz#eeaa77ZDataz#55aa55r#rrZAuthorrtZCredits)6r)__all__r6r r&rMr rNrrurllibparseZquoter5rArr@ryrLrrzrlocalsrrcrSr getmodulerrdrrrrr!rTr-r,rUrDrHr%pkgutil iter_modulesrurr+r4r!rG getclasstreerrrrt)#r8rr$modignoredrpartsZlinksrZ linkednameheadrr3r5rversionrrGrr>Zcdictrjrkr:rQrr=Zfdictdatar;modpkgsimporterispkgr 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|rf| rn| n |ddt|fdd\}}tjurtjur|}qXn"urd}ndj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|d!||d"d}|}qXd#| } ||krd$||f}nd%|||f}|rg}|D]} || j q|d&d'|}d#}zt}Wntt fyd(}Yn0|r2t|}|r2|d)kr2||d*}t}|rN||pJd#}|j}|ond+|}|d,d-| d.|S)/z.Produce HTML documentation for a class object.cs eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecSs d|_dSrZneedonerrrrrhsz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
rJrjrpushrrmaybejsz.HTMLDoc.docclass..HorizontalRule.maybeNr)rrrrmrrkrrHorizontalRulegsrorKz&
Method resolution order:
z
%s

c st||\}}|r||D]b\}}}}zt|}Wn$tyd||Yn0||dq&|S)NrIrprmr! Exceptionrrmsgrrnokr$rhomeclsrkr>r=hrmdictr`rrlr8rrspillzs   zHTMLDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrprmrrsrxr`rlr8rrspilldescriptorssz*HTMLDoc.docclass..spilldescriptorsc st||\}}|r||D]r\}}}}t||}t|} | s`d|n0t|j} d| } d|| fdq&|S)Nz
%s
z
%sz
%s%s
rI)rprmrr!rHrDr%) rtrrnrur$rrvrkr:r;rwrr spilldatas  z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS)r7rrr$rr#rkrrrrs  z$HTMLDoc.docclass..r-rcs |duSNrKrrT thisclassrrrrz"HTMLDoc.docclass.. defined hereinherited from %sz:
z Methods %scSs |ddkSNrJmethodrrTrrrrrzClass methods %scSs |ddkSNrJz class methodrrTrrrrrzStatic methods %scSs |ddkSNrJz static methodrrTrrrrrzReadonly properties %scSs |ddkSNrJrrrTrrrrrzData descriptors %scSs |ddkSNrJrrrTrrrrrzData and other attributes %scSs |ddkSNrJrerrTrrrrrrCz*class %sz/%s = class %s(%s)rEN()r"z%s
 
z#000000z#ffc8d8rX)r)rdr rrgetmrorMrmr/rrr!rrrApopleftrpbuiltinsrrrN signature ValueErrorr@rrHrDr%r )r8rr$r`r=r>rarealnamerLrromror:rzr}r~rrjrrvrkanchor inheritedtagrrMdeclrargspecr;r) r>r=rxryr`rrlr8rrr\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.rCrr from N method of %s instance unbound %s methodasync z$%sz%srJz)%s = %sz$%s lambda r(...)z'%sz
%s
z
%s
z
%s
%s
)r)rar*r+r/riscoroutinefunctionisasyncgenfunctiongetattr_staticrTrrrAr@rr,rDrHr%)r8rr$r`r=r>rirhrrnoteskipdocsimclassasyncqualifierrZreallinkrrrr;rrrrsl       zHTMLDoc.docroutinecCsNg}|j}|r|d||t||j}|r<|d||dd|S)z1Produce html documentation for a data descriptor.z!
%s
z
%s
rprC)r rDrHr%rNr8rr$r`rhrrlr;rrrrCs  zHTMLDoc.docdatacGs|r d|pd}|||S)z-Produce HTML documentation for a data object.z%s = rCr)r8rr$r`raZlhsrrrrSszHTMLDoc.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..rCrJrRrW)r]r^anyr rr+r4r!)r8rr2rfrgr$rhrrrrindexXs  z HTMLDoc.index)rC)rrCNr)r)N)NN)NNN)NN)N)r)rrr=r_repr_instancerrrrr r!r%r+r,r.r/r1r4r5rDrGrrrrrrrrrrrrr2s>   +  y# A  rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,t|d|_|_d|_d|_|_dSrrrrrrrks  zTextRepr.__init__cCsTtt|dr@ddt|j}t||r@t||||Sttt||j Sr) rr?rNr)r r!r\r_rrr rrrr qs  zTextRepr.repr1cCsHt||j}t|}d|vrDdt|ddvrDd|d||dS|S)Nrr rCr r)r\rrrWrrrrrxs  zTextRepr.repr_stringcCs4zttt||jWSd|jjYS0dSr)r\r_rrr+r)rrrrrszTextRepr.repr_instanceN) r)rrr=rr rrrrrrrris  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.rCcss|]}|d|VqdS)NrrrrrrrzTextDoc.bold..)rNrrrrboldsz TextDoc.bold cs>|sdSfdd|dD}|r4|d|d<d|S)z6Indent text by prepending a given prefix to each line.rCcsg|] }|qSrrrrprefixrrrrz"TextDoc.indent..rIr)r rFrN)r8rVrrOrrrindentszTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rIr")rrFr)r8rrZclean_contentsrrrr szTextDoc.sectionNrCc 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().rCrc3s|]}t|VqdSrrR)rrKrQrrrrz%TextDoc.formattree..rrErIr)r?rRrNrG) r8rHrQrIrrGrJrKrLrMrrrrGs  zTextDoc.formattreec Cs|j}tt|\}}|d||o(d|}t|dd}||}|dur`||d|d}|rt||d|}g} t|tD]<\} } |dust | p||urt | ||r| | | fqg} t|tj D]B\} } |dust | st | |urt | ||r| | | fqg} t|tD]&\} } t | ||r(| | | fq(g}t}t|drt|jD]6\}}}|||r| |d n | |qr|||d d |}g}t|tjD]0\} } | j|d r| |vr| | q|r0|||d d |}| rdd| D}|t|d|g}| D]\} } | || | |q^||dd |}| rg}| D]\} } | || | |q||dd |}| r g}| D]"\} } | |j| | |ddq||dd |}t|drzt|j}|dddkrj|dddkrj|dd}||d|}t|dr||dt|j }t|dr||dt|j!}t|d r||d!t|j"}zt#|}Wnt$yd"}Yn0||d#|}|S)$z5Produce text documentation for a given module object.NAME - rXNzMODULE 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 DESCRIPTIONru (package)zPACKAGE CONTENTSrIrZ SUBMODULEScSsg|] \}}|qSrrrVrrrrrz%TextDoc.docmodule..rJCLASSES FUNCTIONSF)r[ZDATAryrOrPrrQZVERSIONrzZDATErrZAUTHORrtZCREDITSrZFILE)%r)rPrHr r!rrrcrr\rr rTr-rUsetrr]r^ruaddrrNrSrrGr_rrr@ryrLrzrrrtrrA)r8rr$r`ZsynopdescrGrrr>rjrkr=rerfZ modpkgs_namesrgrQrhZ submodulesrirrdrrrrrs                $    zTextDoc.docmodulec sJj}|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!}|}qd | } | s.|d S|d | d0d S)1z4Produce text documentation for a given class object.cSs t||Srr)rKrrrrmakenamesz"TextDoc.docclass..makenameclass z = class rrENrrIrKzMethod resolution order:rrCcss.|]&}|jds|jdkrt|jVqdS)r}rN)r)rrr@)rr#rrrrCsz#TextDoc.docclass..rrzBuilt-in subclasses:z ... and z other subclassescs eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dSrrjrrrrrUsz1TextDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)NzF----------------------------------------------------------------------rJrjrrkrrrmWsz.TextDoc.docclass..HorizontalRule.maybeNrnrrkrrroTsroc st||\}}|r|||D]T\}}}}zt|}Wn$tyd||Yq&0||q&|Srrqrsrxr`rrlr8rrrz]s zTextDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srr{rsr|rrr}nsz*TextDoc.docclass..spilldescriptorsc st||\}}|r||D]\\}}}}t|}zt|} Wntyd|j|} Yn0j| |d|ddq&|S)Nr)r[r;rI)rprmrHr!r6__dict__r) rtrrnrur$rrvrkr;r7rrrr~ws z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqSrrrrrrrs  z$TextDoc.docclass..rcs |duSrrrTrrrrrz"TextDoc.docclass..rrz Methods %s: cSs |ddkSrrrTrrrrrzClass methods %s: cSs |ddkSrrrTrrrrrzStatic methods %s: cSs |ddkSrrrTrrrrrzReadonly properties %s: cSs |ddkSrrrTrrrrrzData descriptors %s: cSs |ddkSrrrTrrrrrzData and other attributes %s: cSs |ddkSrrrTrrrrrz | )r)rdrrmaprNr rrrrAr@rHrrrMsortedr?__subclasses__rrrrprrrRrrrF)r8rr$r`rarrLrrrMrrrr;rr:Z subclassesZno_of_subclassesZMAX_SUBCLASSES_TO_DISPLAYZ subclassnamerorzr}r~rrrr)rxr`rrlr8rrrs                   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.rCrrNrrrrJ = rz lambda rrrI)r)rar*r+rRrrrrrrTrrrAr@rHrrF)r8rr$r`rhrrrrrrrrrr;rrrrsT       zTextDoc.docroutinecCsTg}|j}|r$||||dt|p.d}|rJ||||dd|S)z1Produce text documentation for a data descriptor.rIrC)r rrHrrNrrrrrs 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.rrCrNrYrI)rrMrrHrr@) r8rr$r`rIr[r;rrZchoprrrrs  zTextDoc.docother)r)NrC)NN)NN)NNN)NNN)NNNNN)r)rrr=rrrrrr rGrrrrrrrrrrrrs   e  7 rc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|Srrrrrrr sz_PlainTextDoc.boldN)r)rrr=rrrrrr 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 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_pagerrrr#rzgetpager..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^rrrr4r)rrstdin plainpagerstdoutrr rrplatformrtempfileZmkstempcloseunlinkttypager)rfdrrrrrs>            rcCstdd|S)z%Remove boldface formatting from text.z.rC)rDrEr^rrrr:src Csddl}|j|d|jd}zVtj|jdd2}z||WntyNYn0Wdn1sd0YWntyYn0z| WqWqtyYq0qdS)z3Page through text by feeding it to another program.rNT)shellrbackslashreplace)errors) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)rVcmdrprocpiperrrr>s (  rc Csddl}|}tj|d}t|ddtjdkr.cSstjddddS)NrrJ)rrrrrrrrqrZLINESrJz -- more --)qQz ) rI)bB)rrr ttyrrfilenoZ tcgetattrZ setcbreakrr6rUnsupportedOperationr<r rrrrrrNflushZ tcsetattrZ TCSAFLUSH) rVrOrroldZgetcharhr ZincrKrrrrfsN              & 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 ruzpackage zmodule zbuilt-in function zgetset descriptor %s.%s.%szmember descriptor %s.%s.%srz function zmethod )rrSr)rrrr-Zisgetsetdescriptorr1rr2rr,r(r?)thingrrrdescribes2                 r c 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..rrNrJ)r rMrrNrr!r6)rrrbrnZ nextmodulerrrrrlocates   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))rr@r rr!)rrrr$rrrresolves   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")rVr r rr\rfindr)rSrrTr0rBrrr?r)rrrZrendererrr$rrrrr 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)rrroutputrkrrrr;s r;c 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)HelperrCBOOLEANwith)assertrC)asyncrC)awaitrC)break while for)classzCLASSES SPECIALMETHODS)continuer )ZfunctionrC)del BASICMETHODSif)elser try)forzbreak continue whileimport)globalznonlocal NAMESPACES)r% TRUTHVALUE)r)MODULES)inSEQUENCEMETHODS COMPARISON)lambdar)nonlocalzglobal NAMESPACES)passrC)raise EXCEPTIONS)returnr)r'r4)whilezbreak continue if TRUTHVALUE)rz CONTEXTMANAGERS EXCEPTIONS yield)yieldrC)$FalseNoneTrue__peg_parser__andasrrrrr!r"defr#elifr&exceptfinallyr(fromr*r%r)r-isr0r1notorr2r3r5r'r6rr7cCsg|]}dD] }||q qS)'r6r)rprrrrrErzHelper.)rfr urGz'''r6r)+r***rz//%<<>>r|^~rr<=>===!=<>)rrrTrUrVrWrX)rrS) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)rOrPrrQrRrS)jJ)STRINGS OPERATORSr/UNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classr[ PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rNrM,rrY:@rr}r|`r7rF[]r)rzRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES)zstring-methodszSTRINGS FORMATTING)Z formatstringsr\)rjz: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-objectrC)zbltin-ellipsis-objectSLICINGS)Z specialattrsrC)rz!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)Zobjectsrl)Z specialnameszbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES)Z customizationzhash repr str SPECIALMETHODS)zattribute-accesszATTRIBUTES SPECIALMETHODS)zcallable-typeszCALLS SPECIALMETHODS)sequence-typesz(SEQUENCES SEQUENCEMETHODS SPECIALMETHODS)rozMAPPINGS SPECIALMETHODS)z numeric-typesz*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS)Z execmodelz%NAMESPACES DYNAMICFEATURES EXCEPTIONS)Znamingz3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURES)zdynamic-featuresrC NAMESPACES)rztry except finally raise)Z conversionsrC)Z identifierszkeywords SPECIALIDENTIFIERS)z id-classesrC)zatom-identifiersrC)z atom-literalsz=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALS SEQUENCES)Z exprlistszTUPLES LITERALS)ztypesseq-mutable LISTLITERALS)ZlistszLISTS LITERALS)Z typesmappingDICTIONARYLITERALS)r3zDICTIONARIES LITERALS)zattribute-referencesz(getattr hasattr setattr ATTRIBUTEMETHODS)Z subscriptionsr.)Zslicingsr.)Zcallsrn)Zpowerrn)Zunaryrn)Zbinaryrn)Zshiftingrn)Zbitwisern)Z comparisonszEXPRESSIONS BASICMETHODS)ZbooleanszEXPRESSIONS TRUTHVALUEr)Z assignmentr^)Z augassign NUMBERMETHODSr#r5)Zcompoundzfor while break continue)truthz if while and or not BASICMETHODS)ZdebuggerZpdb)zcontext-managersr)Irlr[Z STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERZFLOATr`rqZMAPPINGSrZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSZNONErbZSPECIALATTRIBUTESrr,ZPACKAGESrnr\Z PRECEDENCEZOBJECTSZSPECIALMETHODSr$ZATTRIBUTEMETHODSZCALLABLEMETHODSr.ZMAPPINGMETHODSrtZ EXECUTIONrpZDYNAMICFEATURESZSCOPINGZFRAMESr4Z CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSrcZLITERALSZTUPLESZ TUPLELITERALSZLISTSrrrkrsZ ATTRIBUTESZ SUBSCRIPTSrmZCALLSrar]ZBINARYZSHIFTINGr_r/rZ ASSERTIONZ ASSIGNMENTr^ZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGr+Z DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dSr)_input_output)r8inputrrrrrszHelper.__init__cCs |jp tjSr)rwrrrrrrrysz Helper.inputcCs |jp tjSr)rxrrrrrrrsz Helper.outputcCs2tdddkr|dSd|jj|jjfS)NrJrX?rCz<%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. )_GoInteractiverintrointeractrrr8Zrequestrrr__call__s   zHelper.__call__c Cs|jdz|d}|s WqWnttfy<YqYn0|}t|dkr|d|dkrndvrnn |d|ddvr|dd}|dvrq|d kr|q | |q dS) NrIzhelp> rKrrrFrJ)rquitr) rrgetlinerEOFErrorrLrMrr~rrrrrrs    ,  zHelper.interactcCs8|jtjurt|S|j||j|jSdS)z.Read one line, using input() when appropriate.N)ryrrrrrr)r8promptrrrrs    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) NrCkeywordssymbolstopicsrzmodules rJ)r:r8r9z Help on %s:)rrI)r?rL listkeywords listsymbols listtopics listmodulesr r showsymbolr;evalr showtopicrrxr@rrrrrrrrrs$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.%drK)rrr(rrrrrrr~s z Helper.introrPc Cstt|}||}t||d|}t|D]v}t|D]\}|||}|t|kr<|j||||dkr<|jdd|dt||q<|jdq0dS)NrJrrI)r'rrMr&rr) r8itemscolumnsrZcolwr)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'rrgrrrrr2s 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'rrgrrrrr9s zHelper.listsymbolscCs |jd||jdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrr'rrgrrrrrAs 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 rCrIrRelated help topics: rEHz %s )pydoc_data.topicsrrrrrrrr?rKeyErrorrLtextwraprNr Zwrapr) r8topic more_xrefs pydoc_datatargetlabelxrefsr;rrVZ wrapped_textrrrrHs4       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)rrCzcould not find topicrCr) rrrrrrrr@ _gettopic)r8rrrrrrr;rrrrhs      zHelper._gettopiccCs*|j|}|d\}}}|||dS)Nr)r partitionr)r8symbolrrr}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__rrrrJ)find)rrQrrrrrcallbacksz$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)r8rjrrrrrrs     zHelper.listmodules)NN)rr)rC)rC)rC)!r)rrrZ _strprefixesZ_symbols_inverserrrZsymbols_rrrrr.ryrr|rr}rrrrr~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__rJrCrIrrr get_source get_filenamerv)rrrrrr=r rr]r _get_specrrrrrrrrStringIOrrrrrrr!)r8rrjZ completerrseenrQr$rrgrhrrsourcerrrrrrs^            zModuleScanner.run)NNN)r)rrr=rrrrrrsrcCsXdd}dd}t,tdtj|||dWdn1sJ0YdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dSNrrrz- )rrrQrrrrrszapropos..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)r8 content_typerrrdo_GET0 s   z(_start_server..DocHandler.do_GETcWsdSrr)r8rrrr log_message@ sz-_start_server..DocHandler.log_messageN)r)rrrrrrrr DocHandler. srcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dSNF)hostZaddressrr:rhandlerr)r8rportrrrrrF s  z)_start_server..DocServer.__init__cs>|js2|jgggd\}}}|r|q|dSrb)rselectZsocketrZhandle_requestZ server_close)r8ZrdZwrZexrrrserve_until_quitM s  z1_start_server..DocServer.serve_until_quitcSs |j||jr||dSr)r:server_activaterrrrrrT s z0_start_server..DocServer.server_activateN)r)rrrrrrrrr DocServerD s rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dSr)rrr<rThreadrservingerror)r8rrr) 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 HTTPServerr:rrZMessageZ MessageClass staticmethodrrrready docserverrrrr)r8Zdocsvre)rremailhttprrrc s    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr3)r8rrrrrp sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrrNrr3rrrrstopv s z(_start_server..ServerThread.stopN)r)rrrrrrr)rrrrrrr ServerThreadY s  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrrBrrtimesleep)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)r8rrcss_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)rdrrrr s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}tjD]}|||qT|d d d |fS)zModule Index page.cSs d||fSNr0rr$rrr bltinlink sz3_url_handler..html_index..bltinlinkz7Index of ModulesrRrScSsg|]}|dkr|qS)rr)rr$rrrr sz4_url_handler..html_index..z

zBuilt-in ModulesrWz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of ModulesrC) rrrr+r!rr rrN)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|fdSrrlrZ search_resultrrr sz3_url_handler..html_search..callbackrcSsdSrrrrrrr sz2_url_handler..html_search..onerrorrNcSs d||fSrrrrrrr sz4_url_handler..html_search..bltinlinkz5Search ResultsrRrSzkey = %srW
zSearch Results) rrrrrrr r!rN) rjrrrrrr$rrrrr 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,INDEXrRrSZTopicsrW)rrrrrgr+r!)rrrrrrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.rrRrScSs d||fSrrrrrrr sz6_url_handler..html_keywords..bltinlinkZKeywordsrW)rrrrrgr+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.ZKEYWORDZTOPICrNrRrSz

%s
rWcSs d||fSrrrrrrr& sz7_url_handler..html_topicpage..bltinlinkrz%s %srC) rrrrrrrDr!rr r+r rN)rZbufZhtmlhelprrrrrrrrhtml_topicpage s,     z$_url_handler..html_topicpagecs@t|dd}|dur$|dkr$tdt|}||}||fS)NrJ)rr9zcould not find object)r rr r)r3r7rcontentrrr html_getobj/ s   z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,ErrorrRrSrc3s|]}|VqdSr)rrrrrr; rz3_url_handler..html_error..z#bb0000z Error - %s)rrNrr?r!)r3rrrrrr html_error7 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)rCrrrrz search?keyz topic?keyzget?keyz bad pydoc url)rrrrrr)r3Z complete_urlrropr}r)rrrrrrrrrr get_html_pageA s>          $z#_url_handler..get_html_pagerrJNrrCrz"unknown content type %r for url %s) rrr rdirnamerealpathrvrNr readlinesrA)r3rrrZ path_hererfpr) rrrrrrrrrr _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) webbrowserrrrrrrr3ryrrrr)rrrrZ serverthreadZserver_help_msgrrrrbrowsev s8     rcCst|to|tjdkSr)rr@rr sep)rorrrispath 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. rCNr) r curdirgetcwdrrrvcopysamefileremoveinsert)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)rrrr_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 rJzbk: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)getoptrrr rr rrrr rexistsrrrr rrrrrrrr(r)r r ZoptsrZwritingZ start_serverrrroptvalargrkrrrrcli s`    $rr)NN)r)r)r rN)r rN)r)rCN)r)r)`r=rXrrrzrtrZimportlib._bootstraprZimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrr r]rrDrrrrrZ urllib.parserYr collectionsrreprlibr tracebackrrrr%r<r5rBrHrPrRrUrWr\r8 IGNORECASEr]r_rarfrprrrrrrrrrrrrrrrrrrrrrrrrrr r rVrrr rr;rrrrrrrrrrr r rr)rrrrs&      3      ' 0:*; " ,    = n% U