U .e̠@sdZdgZdZdZdZddlZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZd d Zd d ZddZ ddZ!ddZ"ddZ#ddZ$e%dej&Z'ddZ(ddZ)ddZ*dd Z+dxd!d"Z,d#d$Z-d%d&Z.d'd(Z/d)d*Z0ifd+d,Z1Gd-d.d.e2Z3d/d0Z4difd1d2Z5Gd3d4d4Z6Gd5d6d6eZ7Gd7d8d8e6Z8Gd9d:d:eZ9Gd;d<dd>e:Z;d?d@adEdFZ?dGdHZ@dIdJZAdKdLZBdMdNZCdOdPZDdydQdRZEe:ZFe;ZGe8ZHdzdSdTZId{dVdWZJd|dXdYZKd}dZd[ZLd~d]d^ZMGd_d`d`ZNeNZOGdadbdbZPdcddZQdedfZRddhdiZSddjdkdldmdnZTdodpZUdqdrZVdsdtZWdudvZXeYdwkreXdS)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|}||krtj|r||||q|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr/usr/lib64/python3.8/pydoc.pypathdirsPs    rcCs.t|pt|}|r*tdd|p,dS)z-Get the doc string or comments for an object.z^ * )inspectgetdocZ getcommentsresubrstrip)objectresultrrrr\srcCsf|d}t|dkr&|ddfSt|dkrX|dsX|dd|ddfSdd|fS)z>Split a doc string into a synopsis line (if any) and the rest. rrN)stripsplitlenrjoin)doclinesrrrsplitdocas   r$cCs"|j}|j|kr|jd|}|S)z@Get a class name and qualify it with a module name if necessary.r)__name__ __module__)rmodnamenamerrr classnamejs r)cCs>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.)rismoduleisclass isroutineZisframeZ istracebackZiscoderrrrisdataqsr.cGs.|r*|d||d}|dd}q|S)z/Do a series of global replacements on a string.rrrN)r!r)textZpairsrrrreplacewsr0cCsXt||krTtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrN...)r max)r/maxlenZpreZpostrrrcram~s  $r5z at 0x[0-9a-f]{6,16}(>+)$cCs td|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidrr/rrrstripidsr8cCs<t|rdSt|r8t|dd}t|p4|dk SdS)zo Returns True if fn is a bound method, regardless of whether fn was implemented in Python or in C. T__self__NF)rismethod isbuiltingetattrr*)fnselfrrr_is_bound_methods    r?cCs^i}t|tjD]\}}d||<q|jD]}|t|q*|D]}t||||<qF|SNr)r getmembersr, __bases__update allmethodskeysr<)clmethodskeyvaluebaserrrrDs   rDcCs8g}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  rOcCs\|dkr dS|dr$|dr$dS|dr __slots____date____path__ __qualname__ __builtins__ __credits____doc__ __author__ __version____file__r% __cached__r& __loader____spec__ __package__r__r__fieldsTN) startswithendswithhasattr)r(allobjrrr visiblenamesrfcCsXg}t|D]D\}}}}t|r@d}t|tr@|jdkr@d}|||||fq|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.data descriptorNreadonly property)rclassify_class_attrsisdatadescriptor isinstancepropertyfsetr )rresultsr(kindclsrIrrrris rics\t|dgzfddtDWntk r>iYnXfdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namer`csi|]\}}||tqSr)r ).0ir()fieldsrr sz#sort_attributes..cs|dd|dfSNr)get)attr) field_orderrrz!sort_attributes..rHN)r< enumerate TypeErrorsort)attrsrZkeyfuncr)rxrsrsort_attributess   rcCs:tj|r6dD]$}tjtj|d|rdSqdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfiler!)rextrrr ispackages  rcCs|}|dddks |s0|}|sq0q|}|dddkrT|dd}|dddkr|dd}|dddkr|dd}|s|}|sqq|dd }nd}|S) Nr#zr"""r1"""\r)readlinerr)filelinerrrrsource_synopsiss&   rc Cs t|j}||d\}}|dks.||kr|ttjjrJtjj }n |ttjj rftjj }nd}|dkrzt |}Wntk rYdSX|t|}W5QRXn^|d|}tjjd||d}ztj|} WnYdSXtjd=| jr | jdnd}||f||<|S)z.Get the one-line summary out of a module file.)NNNZ__temp__loaderr)r statst_mtimervrbtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrmodulesrV splitlines) filenamecachemtimeZ lastupdaterZ loader_clsrrspecmodulerrrsynopsiss6      rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dSN)rexcrItb)r>rexc_inforrrr#szErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr%rrI)r>rrrr__str__'szErrorDuringImport.__str__N)r%r&rSrVrrrrrrr!src Cstjj}t|d}||t|k}W5QRXtj|}tj |\}}|r`tj ||}ntj ||}tjj |||d}ztj|WSt|tYnXdS)z|tkrt|j| n(t |t r|j krYdSttYnX dddD].} zt || }Wqtk rYdSXq|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)ra)rqmrrr Qszsafeimport..Nrr)rrbuiltin_module_names __import__rrrY SyntaxErrorr issubclass ImportErrorr(rr<AttributeError) r forceloadrZsubsrHrrrIrinfopartrrr safeimport=s.     rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrcGs||f|}zFt|r$|j|WSt|r:|j|WSt|rP|j|WSWntk rfYnXt|r||j |S|j |S)z%Generate documentation for an object.) rr* docmoduler+docclassr, docroutinerrjdocdatadocother)r>rr(argsrrrdocumentss     z Doc.documentcGs*d|odt|t|jf}t|dS)z+Raise an exception for unimplemented types.z.don't know how to document object%s of type %s N)reprtyper%r})r>rr(rmessagerrrfails zDoc.failZstdlibcCszt|}Wntk r&d}YnXtjd|j}tj|}t |t tr|j dksz| |r| tj |ds|j dkr| 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 getabsfiler}r environrvrrr rkrr%rar!rlower)r>rZbasedirrdoclocrrr getdoclocs(   z Doc.getdocloc)N)N)r%r&rSr rrvr version_inforrrrrrr docpropertyr sysconfigZget_pathrrrrrrms   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 maxstringmaxotherr>rrrrs  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)r0r>r/rrrescapeszHTMLRepr.escapecCs t||Sr)rrr>rrrrrsz HTMLRepr.reprcCsZtt|dr@ddt|j}t||r@t||||S|ttt ||j SNr%repr_r_) rcrr!r%rr<rr5r8rrr>rNlevelZ methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|krJdt|ddkrJd|d|||dStdd||S)Nr\\rrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r5rrr0rrrr>rNrZtestZtestreprrrr repr_strings zHTMLRepr.repr_stringcCs@z|ttt||jWS|d|jjYSXdSNz <%s instance>)rr5r8rr __class__r%r>rNrrrr repr_instanceszHTMLRepr.repr_instanceN) r%r&rSrVrrrrrrepr_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)r>titlecontentsrrrpagesz HTMLDoc.pagercCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
 r)r>rfgcolbgcolZextrasrrrheadingszHTMLDoc.headingNrc Cs^|dkrdd|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) r>rr r rwidthZpreludeZ marginaliaZgaprrrrsections zHTMLDoc.sectioncGsd|}|j|f|S)z$Format a section with a big heading.z%s)r)r>rrrrr bigsectionszHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text. z rrr
)r expandtabsr0rrrr preformat s 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.rrzrrzz7%s
)r range)r>listformatZcolsrrowscolrrrrr multicolumns   zHTMLDoc.multicolumncCsd|S)Nz%srrrrrgreyrzz HTMLDoc.greycGs*|D] }||krd|||fSq|S)z:Make a link for an identifier, given name-to-URL mappings.%sr)r>r(ZdictsdictrrrnamelinkszHTMLDoc.namelinkcCsN|jtj|j}}t||rDt|||krDd|j|t||fSt||S)zMake a link for a class.z%s)r%rrrvr&rcr<r))r>rr'r(rrrr classlink%szHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.%s)r%rrrr modulelink-szHTMLDoc.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)r>Z modpkginfor(rrshadowedurlr/rrr modpkglink1s   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%sr)r>r"rrrrfilelink@szHTMLDoc.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.rzD\b((http|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?(\w+))"z"rz'http://www.rfc-editor.org/rfc/rfc%d.txtz(http://www.python.org/dev/peps/pep-%04d/r(zself.zself.%sNr) rrcompilesearchspanr groupsr0intrr!)r>r/rfuncsclassesrGrnherepatternmatchstartendrdZschemeZrfcZpepZselfdotr(r"rrrmarkupDs:      zHTMLDoc.markupc Csd}|D]}t|tdkr|\}}|d}||||}|r||fkrg}|D]} ||| |qR|dd|d}|d}qt|tgkr|d||||}qd |S) zAProduce HTML for a class tree as given by inspect.getclasstree().rrz"

r&, )z
z
%s
z
%s
)rrr r! formattree) r>treer'parentrentrycbasesparentsrJrrrr6os&  zHTMLDoc.formattreec# s|j}z |j}Wntk r(d}YnX|d}g}tt|dD],}|dd|d|d||fqHd||dd} d| } z&t |} t j | } | | } Wntk rd} YnXg}t|dr6t|j}|dd d kr"|ddd kr"|d d}|d |t|d rX|t|j|rp| dd|} |}|dk rdt}nd}| ddd| |}t|tj}gi}}t|tjD]Z\}}|dk st|p||krt|||r|||fd|||<||<q|D]\}}|jD]n}|j|j}}tj !|}||kr@|r@t||r@t"|||kr@||kr@|d|||<||<q@q2gi}}t|tj#D]p\}}|dk st$|st||krt|||r|||fd|||<t%|r||||<qg}t|t&D]&\}}t|||rN|||fqN't(|j)||}|od|}|d|}t|drg}t*+|j,D]\}}} |||| dfq|-.|j/}!|0ddd|!}n.|r<.|fdd}!|0d dd|!}|rd!d"|D}"1t2|"d|g}!|D]"\}}|!3|||||qj|0d#dd$d%|!}|rg}!|D]"\}}|!3|||||q|0d&dd'd%|!}|r:g}!|D]\}}|!3||q|0d(dd)d*|!}t|d+rn't|j4j)}!|0d,dd|!}t|d-r't|j5j)}!|0d.dd|!}|S)/z/Produce HTML documentation for a module object.Nrrz5%sr)%srrX $Revision: $z version %srQz (%s)r4z-
Module Referencer#ffffff#7799eezindex
rz.html#z#-z %sz

%s

rRrzPackage Contentsz#aa55cccs|dSr@)r trrrryrzz#HTMLDoc.docmodule..ZModulescSsg|] \}}|qSrrrqrHrIrrrrsz%HTMLDoc.docmodule..ZClasses#ee77aarZ Functionsz#eeaa77ZDataz#55aa55rrWZAuthorrUZCredits)6r%__all__rrrr r r!rrurllibparseZquoter$r}rcstrrXrrrQrlocalsr rAr*r+ getmodulerfrBr&rrrvr<r,r; isfunctionr.r3rrpkgutil iter_modulesrRr~rr#rr6 getclasstreerrWrU)#r>rr(modignoredrdpartsZlinksrrZ linkednameheadrr"r$rversionrrrr-ZcdictrHrIrJr'rr,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]n\}}}}d|d||<}zt |}Wnt k r4YnXz ||<Wqt k rXYqXq|rx| rr| n |ddt|fdd\}}tjk rtjkr|}q\n"krd}ndj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|d!||d"d}|gkspt|}q\d#| } ||krd$||f}nd%|||f}|rg}|D]} || j q|d&d'|}d#}zt}Wntt fk rd(}YnX|rFt|}|rF|d)krF||d*}t}|rb||p^d#}|j}|od+|}|d,d-| d.|S)/z.Produce HTML documentation for a class object.cs eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecSs d|_dSruZneedonerrrrrsz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
rr[rpushrrmaybe sz.HTMLDoc.docclass..HorizontalRule.maybeNr%r&rSrr^rr\rrHorizontalRulesr`rz&
Method resolution order:
z
%s

c st||\}}|r||D]d\}}}}zt|}Wn&tk rf||YnX||dq&|S)NrrOr^r< ExceptionrrmsgrrMokr(rohomeclsrIr-r,hrmdictrQrr]r>rrspills"  zHTMLDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|SrrOr^rrdrirQr]r>rrspilldescriptors+sz*HTMLDoc.docclass..spilldescriptorsc st||\}}|r||D]\}}}}t||}t|sXt|rft|dd} nd} | dkrd|n0t|j } d| } d|| fdq&|S)NrVz
%s
z
%sz
%s%s
r) rOr^rr<callablerrjr3rr) rerrMrfr(rorgrIrJr"rhrr spilldata4s( z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS)rerfrqr(rorprIr-rrrIs  z$HTMLDoc.docclass..r-rcs |dkSNrrrC thisclassrrrybrzz"HTMLDoc.docclass.. defined hereinherited from %sz:
z Methods %scSs |ddkSNrmethodrrCrrrryrrzzClass methods %scSs |ddkSNrz class methodrrCrrrrytrzzStatic methods %scSs |ddkSNrz static methodrrCrrrryvrzzReadonly properties %scSs |ddkSNrrhrrCrrrryxrzzData descriptors %scSs |ddkSNrrgrrCrrrryzrzzData and other attributes %scSs |ddkSNrrVrrCrrrry|rzrz*class %sz/%s = class %s(%s)r4N()rz%s
 
z#000000z#ffc8d8r1)r%rBr rrgetmror r^rr&rir<rcr}popleftrObuiltinsrrAssertionErrorr! signature ValueErrorrJrrr3rr)r>rr(rQr,r-rRrealnamer;rr`mrorJrkrnrprrHrorgrIanchor inheritedtagrr<declrargspecr"r) r-r,rirjrQrr]r>rwrrs                   zHTMLDoc.docclasscCs|d||Sz)Format an argument default value as text.=)rrrrrr formatvalueszHTMLDoc.formatvaluec Cs|j}|p |}|r|jpdd|} d} d} t|r|jj} |rZ| |k rd|| |} n0|jdk rzd||jj|} nd|| |} t|st|rd} nd} ||krd | |f}nD|rt||g|krd |jd||f}d } n|}d | ||f}d}t |rlzt |}Wnt t fk r>d}YnX|rlt |}|d krld|}|d d}|svd}| |||| o|d| }| rd|S|t||j|||}|od|}d||fSdS)z;Produce HTML documentation for a function or method object.rrtr from N method of %s instance unbound %s methodasync z$%sz%srz)%s = %sz$%s lambda r(...)z'%sz
%s
z
%s
z
%s
%s
)r%r?r9rrriscoroutinefunctionisasyncgenfunctiongetattr_staticr,rrr}rJrrr3rr)r>rr(rQr,r-rGrFrrnoteskipdocsimclassasyncqualifierrZreallinkrrrr"rrrrs|        zHTMLDoc.docroutinecCsNg}|j}|r|d||t||j}|r<|d||dd|S)z1Produce html documentation for a data descriptor.z!
%s
z
%s
rar)r r3rrr!r>rr(rQrFrnr]r"rrrrs  zHTMLDoc.docdatacGs|r d|pd}|||S)z-Produce HTML documentation for a data object.z%s = rr)r>rr(rQrRZlhsrrrrszHTMLDoc.docothercCsg}|dkri}t|gD]<\}}}tdd|Dr:q||d|||kfd||<q||||j}||dd|S)z2Generate an HTML index for a directory of modules.Ncss*|]"}dt|kodknVqdS)iiN)ordrqZchrrr sz HTMLDoc.index..rrrArF)rNrOanyr r~rr#r)r>rr!rWrXr(rYrrrrindexs z HTMLDoc.index)r)r rNr)r)N)NN)NNN)NN)N)r%r&rSrVr_repr_instancerrrr rrrrrrrr r#r$r3r6rrrrrrrrrrrrrsH   +  y& A  rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,t|d|_|_d|_d|_|_dSrrrrrrr s  zTextRepr.__init__cCsTtt|dr@ddt|j}t||r@t||||Sttt||j Sr) rcrr!r%rr<r5r8rrrrrrrs  zTextRepr.repr1cCsHt||j}t|}d|krDdt|ddkrDd|d||dS|S)Nrrrrr)r5rrr0rrrrrs  zTextRepr.repr_stringcCs4zttt||jWSd|jjYSXdSr)r5r8rrrr%rrrrr%szTextRepr.repr_instanceN) r%r&rSrVrrrrrrrrrr s  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.rcss|]}|d|VqdS)Nrrrrrr5szTextDoc.bold..)r!rrrrbold3sz TextDoc.bold cs>|sdSfdd|dD}|r4|d|d<d|S)z6Indent text by prepending a given prefix to each line.rcsg|] }|qSrrrqrprefixrrr:sz"TextDoc.indent..rr)rrr!)r>r/rr#rrrindent7s zTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rr)rrr)r>rrZclean_contentsrrrr>szTextDoc.sectionNrc sd}|D]}t|tdkrr|\}}||t|}|rh||fkrhfdd|D} |dd| }|d}qt|tgkr|||||d}q|S) zBRender in text a class tree as returned by inspect.getclasstree().rrc3s|]}t|VqdSrr))rqr:r'rrrMsz%TextDoc.formattree..rr4rr)rr)r!r6) r>r7r'r8rrr9r:r;r<rrrr6Es" zTextDoc.formattreec Cs$|j}tt|\}}|d||o(d|}t|dd}||}|dk r`||d|d}|rt||d|}g} t|tjD]<\} } |dk st | p||krt | ||r| | | fqg} t|tj D]F\} } |dk st | st | |krt | ||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| |kr| | 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$k rd"}YnX||d#|}|S)$z5Produce text documentation for a given module object.NAME - rGNzMODULE 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 CONTENTSrrZ SUBMODULEScSsg|] \}}|qSrrrErrrrsz%TextDoc.docmodule..rCLASSES FUNCTIONSF)r4ZDATArXr>r?rr@ZVERSIONrQZDATErWZAUTHORrUZCREDITSrZFILE)%r%r$rrr<rrrAr+rLrfr r,r;r.setrcrNrOrRaddr~r!r*rar6rPrrrJrXrrQrWrUrr})r>rr(rQZsynopdescrrdrr-rHrIr,rVrWZ modpkgs_namesrXr'rYZ submodulesrZrrUrrrrrUs               $    zTextDoc.docmodulec sZj}|p |}j}jfdd}||kr:d|}n|d|}|rlt||} |dd| }g} | jzt} Wnt t fk rd} YnX| rt | } | r| dkrʈ|| d t } | r| d t t}t|d kr*d |D]}d ||q d tddtDt jd}t|}d}|rd|d|D]}d |qn||krdt ||dd Gfddd}|fdd}fdd}fdd}fddtD}|r&|r*|n |dd t|fd d!\}}tjk rntjkrn|}qn kr~d"}nd#tj}t||d$||d%d!}|d&||d'd!}|d(||d)d!}|d*||d+d!}|d,||d-d!}|d.||d/d!}|gkst|}qd | } | s>|d S|d | d0d S)1z4Produce text documentation for a given class object.cSs t||Srr)r:rrrrmakenamesz"TextDoc.docclass..makenameclass z = class rr4NrrrzMethod resolution order:rrcss.|]&}|jds|jdkrt|jVqdS)r_rN)r%rar&rJ)rqrprrrrs z#TextDoc.docclass..r{rzBuilt-in subclasses:z ... and z other subclassescs eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dSrur[rrrrrsz1TextDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)NzF----------------------------------------------------------------------rr[rr\rrr^sz.TextDoc.docclass..HorizontalRule.maybeNr_rr\rrr`sr`c st||\}}|r~||D]V\}}}}zt|}Wn&tk rf||Yq&X||q&|SrrbrdrirQrr]r>rrrkszTextDoc.docclass..spillcsJt||\}}|rF||D]\}}}}||q&|Srrlrdrmrrrnsz*TextDoc.docclass..spilldescriptorsc st||\}}|r||D]v\}}}}t|sDt|rNt|}nd}zt|} Wntk r~|j|} YnXj | |d|ddq&|S)Nr)r4r"r) rOr^rorrjrr<r__dict__r) rerrMrfr(rorgrIr"rerrrrps  z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqSrqrrrsr-rrr+s  z$TextDoc.docclass..rcs |dkSrurrCrvrrry4rzz"TextDoc.docclass..rxryz Methods %s: cSs |ddkSrzrrCrrrryCrzzClass methods %s: cSs |ddkSr|rrCrrrryErzzStatic methods %s: cSs |ddkSr}rrCrrrryGrzzReadonly properties %s: cSs |ddkSr~rrCrrrryIrzzData descriptors %s: cSs |ddkSrrrCrrrryKrzzData and other attributes %s: cSs |ddkSrrrCrrrryMrzz | )r%rBr&rmapr!r rrrr}rJrrrr sortedr__subclasses__rrirrOrrr)rrrr)r>rr(rQrRrr;rrr<rrrr"rrJZ subclassesZno_of_subclassesZMAX_SUBCLASSES_TO_DISPLAYZ subclassnamer`rkrnrprrrr)rirQrr]r>rwrrs                   zTextDoc.docclasscCsd||SrrrrrrrWszTextDoc.formatvaluec Cs|j}|p |}d}d}t|rn|jj}|rB||k rndt||}n,|jdk r`dt|jj|}ndt||}t|st|rd} nd} ||kr||} n,|rt ||g|krd}||d |} d} t |rrr(rQrFrrrrrrrrrr"rrrr[sV       zTextDoc.docroutinecCsTg}|j}|r$||||dt|p.d}|rJ||||dd|S)z1Produce text documentation for a data descriptor.rr)r rrrr!rrrrrs zTextDoc.docdatac Cs||}|rF|r|dpd|}|t|} | dkrF|d| d}|rX||dpZd|}|dk r~|d|t|7}|S)z-Produce text documentation for a data object.rrrNr2r)rr rrrJ) r>rr(rQr8r4r"rrZchoprrrrs  zTextDoc.docother)r)Nr)NN)NN)NNN)NNN)NNNNN)r%r&rSrVrrrrrrr6rrrrrrrrrrrr+s   e  7 rc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|Srrrrrrrsz_PlainTextDoc.boldN)r%r&rSrVrrrrrrsrcCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpagerr7rrrrsrc s@ttjdstSttjds tStjr4tjs8tStjdpNtjdrtj dkrjfddStjddkrfd dSfd dStjddkrtStj dkrd dSttd rt d dkrddSddl }| \}}t |z8ttd r$t d|dkr$ddWStWSW5t|XdS)z2Decide what method to use for paging through text.isattyZMANPAGERZPAGERwin32cstt|Sr tempfilepagerplainr7Z use_pagerrrryrzzgetpager..ZTERM)ZdumbZemacscstt|Sr) pipepagerrr7rrrryrzcs t|Srrr7rrrryrzcSstt|dS)Nzmore /dev/nullrcSs t|dS)NZlessrr7rrrryrzNz more "%s"cSs t|dS)NZmorerr7rrrryrz)rcrstdin plainpagerstdoutrr rrvplatformrtempfileZmkstempcloseunlinkttypager)rfdrrrrrs6            rcCstdd|S)z%Remove boldface formatting from text.z.r)rrr7rrrrsrc Csddl}|j|d|jd}zDtj|jdd*}z||Wntk rPYnXW5QRXWntk rrYnXz| WqWqttk rYqtXqtdS)z3Page through text by feeding it to another program.rNT)shellrbackslashreplace)errors) subprocessPopenPIPEio TextIOWrapperrwriteKeyboardInterruptrwait)r/cmdrprocpiperrrrsrc Cs~ddl}|d}tj|d}t|ddtjdkr.cSstjddddS)Nrr)rrrrrrrryrzZLINESrz -- more --)qQz ) r)bB)rrrttyrrfilenoZ tcgetattrZ setcbreakrrrUnsupportedOperationZ tcsetattrZ TCSAFLUSHr+r rrvrrrr!flush) r/r#rroldZgetcharhrZincr:rrrr sL              &rcCstjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrrr7rrrr5srcCst|r>|jtjkr 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 )rr*r%rrrcr;Zisgetsetdescriptor __objclass__r&Zismemberdescriptorr+rMr:r)thingrrrdescribe9s6                rc Csdd|dD}d\}}|t|kr\td|d|d|}|r\||d}}qq\q|rf|}nt}||dD],}zt||}Wqvtk rYdSXqv|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|] }|r|qSrr)rqrrrrrVszlocate..rruNr)rr rr!rr<r)rrrSrnZ nextmodulerrrrrlocateTs   rcCsVt|tr0t||}|dkr(td|||fSt|dd}|t|trL|ndfSdS)zDGiven an object or a path to an object, get the object and its name.Nz~No Python documentation found for %r. Use help() to get the interactive help utility. Use help(str) for help on the str class.r%)rkrJrrr<)rrrr(rrrresolvems   r Python Library Documentation: %scCs|dkr t}t||\}}t|}t|}|rTd|krT|d|d|d7}n|rn||k rn|d|j7}t|st|st |st |st |}|d7}||d| ||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module z objectr) r/rrrrLrfindr%r*r+r,rjrr)rrrZrendererrr(rrrrr render_doc{s&    rc Csfz2|dkrtt|||n|t|||tWn.ttfk r`}z t|W5d}~XYnXdS)zCDisplay text documentation, given an object or a path to an object.N)rrr plaintextrrprint)rrroutputrIrrrr"s r"c Csz`t||\}}tt|t||}t|dddd}||W5QRXtd|dWn.tt fk r}z t|W5d}~XYnXdS)zd?d@dAdBdCdDdEdFdGdHdIdJdKdLdLdMdNdOdPdQddRdSdSdTdUdVdWdXdYdZd[d\d]d^d_d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{dd d|d}d~ddIZ dddZ eddZeddZddZeZefddZddZddZddZddZdddZddZddZddZdddZdddZddZdddZ dS)HelperrBOOLEANwith)assertr)asyncr)awaitr)break while for)classzCLASSES SPECIALMETHODS)continuer)Zfunctionr)del BASICMETHODSif)elsertry)forzbreak continue whileimport)globalznonlocal NAMESPACES)r TRUTHVALUE)rMODULES)inSEQUENCEMETHODS COMPARISON)lambdar)nonlocalzglobal NAMESPACES)passr)raise EXCEPTIONS)returnr)rr')whilezbreak continue if TRUTHVALUE)rz CONTEXTMANAGERS EXCEPTIONS yield)yieldr)#FalseNoneTrueandasrrrrrrdefrelifrexceptfinallyrfromrrrr isr#r$notorr%r&r(rr)rr*cCsg|]}dD] }||q qS)'r%r)rqprrrrrszHelper.)rfrur9'''r%r)+rt***rz//%<<>>r|^~rr<=>===!=<>)rrrGrHrIrJrK)rtrF) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)rBrCrrDrErF)jJ)STRINGS OPERATORSr"UNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classrN PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rAr@,rr2:@rr_r^`r&r5[]r)typeszRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES)zstring-methodszSTRINGS FORMATTING)Z formatstringsrO)r^z: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)r]z!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)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)rczMAPPINGS 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)rzDICTIONARIES LITERALS)zattribute-referencesz(getattr hasattr setattr ATTRIBUTEMETHODS)Z subscriptionsr!)Zslicingsr!)Zcallsrb)Zpowerrb)Zunaryrb)Zbinaryrb)Zshiftingrb)Zbitwiserb)Z comparisonszEXPRESSIONS BASICMETHODS)ZbooleanszEXPRESSIONS TRUTHVALUEr)Z assignmentrQ)Z augassign NUMBERMETHODSrr()Zcompoundzfor while break continue)truthz if while and or not BASICMETHODS)ZdebuggerZpdb)zcontext-managersr)Ir`rNZ STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERZFLOATrSreZMAPPINGSrZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSZNONErUZSPECIALATTRIBUTESrrZPACKAGESrbrOZ PRECEDENCEZOBJECTSZSPECIALMETHODSrZATTRIBUTEMETHODSZCALLABLEMETHODSr!ZMAPPINGMETHODSrhZ EXECUTIONrdZDYNAMICFEATURESZSCOPINGZFRAMESr'Z CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSrVZLITERALSZTUPLESZ TUPLELITERALSZLISTSrfr_rgZ ATTRIBUTESZ SUBSCRIPTSraZCALLSrTrPZBINARYZSHIFTINGrRr"r Z ASSERTIONZ ASSIGNMENTrQZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGrZ DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dSr)_input_output)r>inputrrrrr^szHelper.__init__cCs |jp tjSr)rkrrrrrrrmbsz Helper.inputcCs |jp tjSr)rlrrrrrrrfsz Helper.outputcCs2tdddkr|dSd|jj|jjfS)Nrr1?rz<%s.%s instance>)rstackrr&rSrrrr__repr__js zHelper.__repr__cCs6||jk r||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. )_GoInteractiverintrointeractrrr>Zrequestrrr__call__rs   zHelper.__call__c Cs|jdz|d}|s WqWnttfk r>YqYnX|}t|dkr|d|dkrpdkrnn |d|ddkr|dd}|dkrq|d kr|q | |q dS) Nrzhelp> rrrr8r)rquitr) rrgetlinerEOFErrorrr rrrrrtrrrrss"   ,   zHelper.interactcCs8|jtjkrt|S|j||j|jSdS)z.Read one line, using input() when appropriate.N)rmrrrrrr)r>promptrrrrws    zHelper.getlinecCs<t|tdkr|}|dkr,|n|dkr>|n|dkrP|n|dkrb|n|dddkr||dn||jkr||nj|d krt t |d nR||j kr| |n<||j kr| |n&|rt |d |jd nt td |jd n$t|tr|nt |d |jd |jd dS) Nrkeywordssymbolstopicsrzmodules r)r-r+r,z Help on %s:)rr)rr listkeywords listsymbols listtopics listmodulesrr{ showsymbolr"evalrz showtopicr|rlrJrkr rrrtrrrrs6        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.%dr)rrrrrrrrrrrs z Helper.introrPc Cstt|}||}t||d|}t|D]v}t|D]\}|||}|t|kr<|j||||dkr<|jdd|dt||q<|jdq0dS)Nrrr)rrr rrr) r>itemscolumnsr Zcolwrrowrrrrrrrs      &z Helper.listcCs |jd||jdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrrrzrErrrrr~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. )rrrr{rErrrrrs zHelper.listsymbolscCs |jd||jdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrrr|rErrrrrs zHelper.listtopicsc Cs0z ddl}Wn"tk r.|jdYdSX|j||j|}|sb|jdt|dSt|tdkr~| ||S|\}}z|jj|}Wn*t k r|jdt|YdSX| 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 rrrRelated help topics: r4Hz %s )pydoc_data.topicsrrrr|rvrzrrrKeyErrorrtextwrapr!rZwrapr) r>topic more_xrefs pydoc_datatargetlabelxrefsr"rr/Z wrapped_textrrrrs4     zHelper.showtopiccCsz ddl}Wntk r"YdSX|j||j|}|sFtdt|tr\|||S|\}}|jj|}|r|pzdd|}||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)rrzcould not find topicrr) rrr|rvrzrrkrJ _gettopic)r>rrrrrrr"rrrrs     zHelper._gettopiccCs*|j|}|d\}}}|||dS)Nr)r{ partitionr)r>symbolrrr_rrrrr!s 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__rrrr)find)rr'rrrrrcallback4sz$Helper.listmodules..callbackcsd|ddSrrrrrronerror9sz#Helper.listmodules..onerrorrz Enter any module name to get more help. Or, type "modules spam" to search for modules whose name or summary contain the string "spam". )rrrapropos ModuleScannerrunrrE)r>rHrrrrrr&s     zHelper.listmodules)r9r=r%r)NN)rr)r)r)r)!r%r&rSrzZ _strprefixesZ_symbols_inverser{rrZsymbols_rrvr|rrlrmrrprrqrursrwrrrrr~rrrrrrrrrrr sB'    W       r c@seZdZdZdddZdS)rz7An interruptible scanner that searches module synopses.Nc Cs |r |}d|_i}tjD]p}|dkrd||<|dkrF|d|dqt|jpRd}|dd}|d|}||dkr|d||qtj |dD]\\} }} |jrq|dkr|d|dqzt | |} Wnt k rYqYnX| j } t | d rnz| |} Wn(tk r:|r2||YqYnXtt| pNd}t | d rh| |}nd}n`ztj| }Wn(tk r|r||YqYnX|jr|jdnd}t|d d}|d|}||dkr||||q|r|dS) NF__main__rrrrrr get_source get_filenamerY)rrvrrrrVrrrNr  _get_specrrrcrrcrrStringIOrrrrrrr<)r>rrHZ completerrseenr'r(rrXrYrrsourcerrrrrrGs`          zModuleScanner.run)NNN)r%r&rSrVrrrrrrDsrc CsDdd}dd}t"tdtj|||dW5QRXdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dSNrrrz- )rrr'rrrrrszapropos..callbackcSsdSrrrrrrrszapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rHrrrrrrs   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) rrbZ send_responseZ send_headerZ end_headersZwfiler urlhandlerr)r> content_typerrrdo_GETs   z(_start_server..DocHandler.do_GETcWsdSrr)r>rrrr log_messagesz-_start_server..DocHandler.log_messageN)r%r&rSrrrrrr DocHandlersrcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dSNF)hostZaddressrrJrhandlerrv)r>rportrrrrrs  z)_start_server..DocServer.__init__cs>|js2|jgggd\}}}|r|q|dSr@)rvselectZsocketrZhandle_requestZ server_close)r>ZrdZwrZexrrrserve_until_quits  z1_start_server..DocServer.serve_until_quitcSs |j||jr||dSr)rJserver_activaterrrrrrs z0_start_server..DocServer.server_activateN)r%r&rSrrrrrrr DocServers rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dSr)rrr+rThreadrservingerror)r>rrr) threadingrrrs   z,_start_server..ServerThread.__init__c sxzJjj__jj_t|j_|j |j |j }||_ | Wn(tk rr}z ||_W5d}~XYnXdS)zStart the server.N)server HTTPServerrJrrZMessageZ MessageClass staticmethodrrrready docserverrrcr)r>Zdocsvre)rremailhttprrr s    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rrZ server_portrr")r>rrrrr sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrvr!rr"rrrrstop s z(_start_server..ServerThread.stopN)r%r&rSrrrrr)rrrrrrr ServerThreads  rg{Gz?) Z http.serverZ email.messagerrrZBaseHTTPRequestHandlerrrr1rrtimesleep)rhostnamerrthreadr)rrrrrrr _start_servers8'   rrc s(Gfdddt}|fddfddfddfd d fd d fd dfddfddfdd}|dr|dd}|dkrtjtjt}tj||}t|}d| W5QRSQRXn|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)r>rrcss_pathZcss_link html_navbarrrr2 s z#_url_handler.._HTMLDoc.pageN)r%r&rSrrrrr_HTMLDoc0 srcs>dttdtf}d|tjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)Zterse)rrZpython_versionZ python_buildZpython_compiler)rUrrrrB s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}tjD]}|||qT|d d d |fS)zModule Index page.cSs d||fSNrrr(rrr bltinlink` sz3_url_handler..html_index..bltinlinkz7Index of ModulesrArBcSsg|]}|dkr|qS)rr)rqr(rrrrf sz4_url_handler..html_index..z

zBuilt-in ModulesrFz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr) r rrrrrr rr!)rr namesrrrrrr html_index] s*  z _url_handler..html_indexc sgfdd}t*tddd}tj|||dW5QRXdd}g}d d d }D]\}}||||qf|d |d d d|}d|fS)zSearch results page.cs:|dddkr |ddd}||o0d|fdSrrKrZ search_resultrrr{ sz3_url_handler..html_search..callbackrcSsdSrrrrrrr sz2_url_handler..html_search..onerrorrcSs d||fSrrrrrrr sz4_url_handler..html_search..bltinlinkz5Search ResultsrArBzkey = %srF
zSearch Results) rrrrrr r rr!) rHrrrrnr r(rrrrr html_searchv s,    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,INDEXrArBZTopicsrF)r rr r|rErr)rr rrrrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.rrArBcSs d||fSrrrrrrr sz6_url_handler..html_keywords..bltinlinkZKeywordsrF)r rr rzrErr)r rrrrrr html_keywords s z#_url_handler..html_keywordscst}t||}||\}}||jkr0d}nd}d|dd}d|}|dd|}|rt| }dd } ||} d dd|}d ||fd |||ffS) zTopic or keyword help page.ZKEYWORDZTOPICr=rArBz

%s
rFcSs d||fSrrrrrrr sz7_url_handler..html_topicpage..bltinlinkrz%s %sr) rrr rrzr r3rrrrrr!)rZbufZhtmlhelprrrr rrrrhtml_topicpage s2     z$_url_handler..html_topicpagecs@t|dd}|dkr$|dkr$tdt|}||}||fS)Nr)rr,zcould not find object)rrrr)r"rercontentrrr html_getobj s   z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,ErrorrArBrc3s|]}|VqdSr)rrrrrr sz3_url_handler..html_error..z#bb0000z Error - %s)r r!rrr)r"rr rrrr html_error s  z _url_handler..html_errorc sr|}|dr|dd}z|dkr2\}}n|dkrF\}}n|dkrZ\}}nd|kr$|d\}}}|dkr|\}}n|d krz|\}}Wn tk r|\}}YnXn\|d kr|dkr\}}n4z|\}}Wn"tk r|\}}YnXntd n |\}}Wn2tk rd}z||\}}W5d}~XYnX||S) zGenerate an HTML page for url.rN)rrr|rzrz search?keyz topic?keyzget?keyz bad pydoc url)rbrrrcr)r"Z complete_urlrropr_r)rrrrrrrrrr get_html_page s>          z#_url_handler..get_html_pagerrNrrrz"unknown content type %r for url %s) rrar rdirnamerealpathrYr!r readlinesr})r"rrrZ path_hererfpr) rrrrrrrrrr _url_handler' s*         (    " rT localhost) open_browserrc Csddl}tt||}|jr(t|jdS|jrd}|rB||jz~zZtd|jt||jrt d}| }|dkr|qqZ|dkr||jqZt|qZWnt t fk rtYnXW5|jr|tdXdS) zStart the enhanced pydoc Web server and open a Web browser. Use port '0' to start the server on an arbitrary port. Set open_browser to False to suppress opening a browser. rNz"Server commands: [b]rowser, [q]uitzServer stoppedzServer ready atzserver> rr) webbrowserrrrrrrr"rrmrrrx)rrrrZ serverthreadZserver_help_msgrrrrbrowse s2    rcCst|to|tjdkSru)rkrJrr sep)rNrrrispath9 srcCsvd|kstj|kst|kr"dStjt}tj|}|}||krbtj||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. rNr) r curdirgetcwdrrrYcopysamefileremoveinsert)Z given_pathZargv0Z stdlib_dirZ script_dir revised_pathrrr_get_revised_path< s    rcCs,ttjtjd}|dk r(|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)rrrargv)rrrr_adjust_cli_sys_pathX src Csddl}Gdddt}tzv|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| Wqtk r} z t | W5d} ~ XYqXqWnN|j|fk rtj tj tjdd} t dj| tjdYnXdS)z@Command-line interface (looks at sys.argv to decide what to do).rNc@s eZdZdS)zcli..BadUsageN)r%r&rSrrrrBadUsagee srrzbk: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)getoptrcrrrrrrr rexistsrrrr r rrrrrrrr)rrZoptsrZwritingZ start_serverrrroptvalargrIrrrrclib sd     rr)NN)r)r)rrN)rrN)r)rN)r)r)ZrVrGrWrQrUrZimportlib._bootstraprZimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrr rNrrrrrrZ urllib.parserHr collectionsrreprlibr tracebackrrrr$r)r.r0r5r' IGNORECASEr6r8r?rDrOrfrirrrrrcrrrrrrrrrrrrrrrrrrrr/rrrrr"rr r rrrrrrrrrrr%rrrrs&           ' 0:*> " ,    = n% U