eaiovnaovbqoebvqoeavibavo B  f@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+d!d"Z,dzd#d$Z-d%d&Z.d'd(Z/d)d*Z0d+d,Z1ifd-d.Z2Gd/d0d0e3Z4d1d2Z5difd3d4Z6Gd5d6d6Z7Gd7d8d8eZ8Gd9d:d:e7Z9Gd;d<dd>e7Z;Gd?d@d@e;ZdEdFZ?dGdHZ@dIdJZAdKdLZBdMdNZCdOdPZDdQdRZEd{dSdTZFe;ZGe<ZHe9ZId|dUdVZJd}dXdYZKd~dZd[ZLdd\d]ZMdd_d`ZNGdadbdbZOeOZPGdcddddZQdedfZRdgdhZSddjdkZTddldmdndodpZUdqdrZVdsdtZWdudvZXdwdxZYeZdykreYdS)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}xRtjD]H}tj|p d}tj|}||krtj|r||||qW|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsZnormdirsdirZnormdirr*/opt/alt/python37/lib64/python3.7/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 istracebackZiscode)rrrrisdataqsr-cGs2x,|r,|d||d}|dd}qW|S)z/Do a series of global replacements on a string.rrrN)r!r)textZpairsrrrreplacewsr/cCsXt||krTtd|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrNz...)r max)r.maxlenZpreZpostrrrcram~s  $r3z at 0x[0-9a-f]{6,16}(>+)$cCs td|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidr)r.rrrstripidsr5cCs(t|p&t|p&t|p&t|S)N)r isfunctionismethod isbuiltinZismethoddescriptor)objrrr_is_some_methods   r:cCs<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)rr7r8getattrr*)fnselfrrr_is_bound_methods    r?cCshi}x t|tD]\}}d||<qWx|jD]}|t|q.Wx|D]}t||||<qNW|S)Nr)r getmembersr: __bases__update allmethodskeysr<)clmethodskeyvaluebaserrrrCs  rCcCs<g}g}x*|D]"}||r&||q||qW||fS)zSplit sequence s via predicate, and return pair ([true], [false]). The return value is a 2-tuple of lists, ([x for x in s if predicate(x)], [x for x in s if not predicate(x)]) )r )s predicateZyesZnoxrrr _split_lists  rMcCs\|dkr dS|dr$|dr$dS|dr __package__ __loader__ __author____spec____path__ __slots__ __builtins__ __qualname____doc____date__r% __version__r& __cached__ __credits____file__r__r__fieldsTN) startswithendswithhasattr)r(allr9rrr visiblenamesrccCsDg}x:t|D],\}}}}t|r*d}|||||fqW|S)zCWrap inspect.classify_class_attrs, with fixup for data descriptors.zdata descriptor)rclassify_class_attrsisdatadescriptorr )rresultsr(kindclsrHrrrrds  rdcs\t|dgyfddtDWntk r>iYnXfdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namer^csi|]\}}|t|qSr)r ).0ir()fieldsrr sz#sort_attributes..cs|dd|dfS)Nr)get)attr) field_orderrrz!sort_attributes..)rGN)r< enumerate TypeErrorsort)attrsrZkeyfuncr)rorkrsort_attributess   rvcCs<tj|r8x*dD]"}tjtj|d|rdSqWdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfiler!)rextrrr ispackages   rzcCs|}x*|dddks"|s2|}|s Pq W|}|dddkrX|dd}|dddkr|dd}|dddkr|dd}x|s|}|sPqW|dd }nd}|S) Nr#zr"""r0z"""\r)readlinerr)filelinerrrrsource_synopsiss&    rc Cst|j}||d\}}|dks.||kr|ttjjrJtjj }n |ttjj rftjj }nd}|dkryt |}Wntk rdSX|t|}WdQRXnZ|d|}tjjd||d}ytj|} Wn dStjd=| jr| jdnd}||f||<|S)z.Get the one-line summary out of a module file.)NNNZ__temp__)loaderr)r statst_mtimermr`tuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrmodulesrV splitlines) filenamecachemtimeZ lastupdaterZ loader_clsrrspecmodulerrrsynopsiss4      rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dS)N)rexcrHtb)r>rexc_inforrrrw'szErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr%rrH)r>rrrr__str__+szErrorDuringImport.__str__N)r%r&rUrVrwrrrrrr%src Cstjj}t|d}||t|k}WdQRXtj|}tj |\}}|r`tj ||}ntj ||}tjj |||d}y tj|St|tYnXdS)zUszsafeimport..Nrr)rrbuiltin_module_names __import__rrr[ SyntaxErrorr issubclass ImportErrorr(rr<AttributeError) r forceloadrZsubsrGrrrHrinfopartr)rr safeimportAs.     rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS)Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrcGs||f|}t|r |j|St|r4|j|Sy@t|rJ|j|St|r^|j|St|rr|j |SWnt k rYnXt |t r|j |S|j|S)z%Generate documentation for an object.)risgetsetdescriptordocdataismemberdescriptorr* docmoduler+docclassr, docroutiner isinstanceproperty docpropertydocother)r>rr(argsrrrdocumentws"       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%rs)r>rr(rmessagerrrfailszDoc.failZstdlibcCsyt|}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 Nonez (built-in)r) errno exceptionsZgcZimpmarshalposixsignalr_threadZ zipimportz site-packages)z xml.etreeztest.pydoc_mod)zhttp://zhttps://z%s/%s/z.htmlN)r getabsfilersr environrmrrr rrr%r_r!rlower)r>rZbasedirrdoclocrrr getdoclocs       z Doc.getdocloc)N)N)r%r&rUr rrmr version_inforrrrrrrrr sysconfigZget_pathrrrrrrqs  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|_|_dS)N d)rrwmaxlistmaxtuplemaxdict maxstringmaxother)r>rrrrws  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)r/)r>r.rrrescapeszHTMLRepr.escapecCs t||S)N)rr)r>rrrrrsz HTMLRepr.reprcCsZtt|dr@ddt|j}t||r@t||||S|ttt ||j S)Nr%repr_r]) rarr!r%rr<rr3r5rr)r>rLlevel methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|krJdt|ddkrJd|d|||dStdd||S)Nr~z\\rrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)r3rrr/rrr)r>rLrtesttestreprrrr repr_strings zHTMLRepr.repr_stringcCs8y|ttt||jS|d|jjSdS)Nz <%s instance>)rr3r5rr __class__r%)r>rLrrrr repr_instanceszHTMLRepr.repr_instanceN) r%r&rUrVrwrrrrrepr_strrZ repr_unicoderrrrrs rc@seZdZdZeZejZejZddZd5ddZ d6d d Z d d Z ddZ d7ddZ ddZddZddZddZddZddZdiiifdd Zd8d!d"Zd9d#d$Zddiifd%d&Zd'd(Zddiiidfd)d*Zd+d,Zd:d-d.Zd;d/d0ZdHTMLDocz'Formatter class for HTML documentation.cCs d||fS)zFormat an HTML page.z Python: %s %s r)r>titlecontentsrrrpagesz HTMLDoc.pagercCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
z r)r>rfgcolbgcolZextrasrrrheadings zHTMLDoc.headingN c Cs^|dkrdd|d}d|||f} |r@| d||||f} n| d|||f} | d|S) z Format a section with a heading.Nzz zz

zR z( z'
 
%s
%s %s
%s
%s%s%s
r) r>rrrrwidthZpreludeZ marginaliaZgaprrrrsectionszHTMLDoc.sectioncGsd|}|j|f|S)z$Format a section with a big heading.z%s)r)r>rrrrr bigsection szHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text.z z rz rz
)r expandtabsr/)r>r.rrr preformats zHTMLDoc.preformatr|cCsd}t||d|}xht|D]\}|dd|}x>t|||||D]$}|t|krN||||d}qNW|d}q"Wd|S)z0Format a list of items into a multi-column list.rrzrz
zz7%s
)r range)r>listformatZcolsrrowscolrjrrr multicolumns  zHTMLDoc.multicolumncCsd|S)Nz%sr)r>r.rrrgrey"rqz HTMLDoc.greycGs*x$|D]}||krd|||fSqW|S)z:Make a link for an identifier, given name-to-URL mappings.z%sr)r>r(Zdictsdictrrrnamelink$s zHTMLDoc.namelinkcCsN|jtj|j}}t||rDt|||krDd|j|t||fSt||S)zMake a link for a class.z%s)r%rrrmr&rar<r))r>rr'r(rrrr classlink+s zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.z%s)r%)r>rrrr modulelink3szHTMLDoc.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)z%s)r)r>Z modpkginfor(rrzshadowedurlr.rrr modpkglink7s   zHTMLDoc.modpkglinkcCs d||fS)zMake a link to source file.z%sr)r>r rrrrfilelinkFszHTMLDoc.filelinkcCs|p|j}g}d}td}xL|||} | s2P| \} } ||||| | \} } }}}}| r|| dd}|d||fn|rdt|}|d||| fn|rdt|}|d||| fn|r$|| | dd kr|d | ||n|d |n@|| | dd krR|| ||||n|| ||| }q W||||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"z%sz'http://www.rfc-editor.org/rfc/rfc%d.txtz(http://www.python.org/dev/peps/pep-%04d/r(zself.zself.%sNr) rrcompilesearchspanr groupsr/intrr!)r>r.rfuncsclassesrFrfherepatternmatchstartendrbZschemeZrfcZpepZselfdotr(r rrrmarkupJs<      zHTMLDoc.markupc Csd}x|D]}t|tdkr|\}}|d}||||}|r||fkrg}x|D]} ||| |qVW|dd|d}|d}q t|tgkr |d||||}q Wd |S) zAProduce HTML for a class tree as given by inspect.getclasstree().rrz"

r z, )z
z
%s
z
%s
)rrr r! formattree) r>treer'parentrentrycbasesparentsrIrrrrus    zHTMLDoc.formattreec# s|j}y |j}Wntk r(d}YnX|d}g}x@tt|dD],}|dd|d|d||fqJWd||dd} d| } y&t |} t j | } | | } Wntk rd} YnXg}t|dr:t|j}|dd d kr&|ddd kr&|d d}|d |t|d r\|t|j|rt| dd|} |}|dk rdt}nd}| ddd| |}t|tj}gi}}xlt|tjD]Z\}}|dk st|p||krt|||r|||fd|||<||<qWx|D]\}}xx|jD]n}|j|j}}tj !|}||krL|rLt||rLt"|||krL||krL|d|||<||<qLWq%sr}z)%sz (built-in)rX z $Revision: $z version %srWz (%s)z, z-
Module Referencerz#ffffffz#7799eezindex
r{z.html#z#-z %sz

%s

rRrzPackage Contentsz#aa55cccs|dS)Nr)r)t)r>rrrprqz#HTMLDoc.docmodule..ZModulescSsg|] \}}|qSrr)rirGrHrrrrsz%HTMLDoc.docmodule..ZClassesz#ee77aarZ Functionsz#eeaa77ZDataz#55aa55z
rPZAuthorrZZCredits)6r%__all__rrrr r r!rrurllibparseZquoter rsrastrrXrrrWrlocalsrr@r*r+ getmodulercrAr&rrrmr<r,r8r6r-rrrpkgutil iter_modulesrRrtrr rr getclasstreerrPrZ)#r>rr(modignoredrbpartsZlinksrjZ linkednameheadrr r rversionrrrrZcdictrGrHrIr'rrZfdictdatar"modpkgsimporterispkgr classlistr)r>rrs   &     $         $        zHTMLDoc.docmodulec sj}|p |}j}g} | jGfddd} | tt} t| dkrdx"| D]} d| j qfWdfdd} fd d }fd d }fd dt D}ixv|D]n\}}}}d|d||<}yt |}Wnt k r:YnXy ||<Wqt k r^YqXqWx|rb| r|| n |ddt|fdd\}}tjkr|}qfn"krd}ndj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|gksZt|}qfWd!| } ||krd"||f}nd#|||f}|rg}x"|D]} || j qW|d$d%|}d!}yt}Wntt fk rd&}YnX|r6t|}|r6|d'kr6||d(}t}|rR||pNd!}|j}|ord)|}|d*d+| d,|S)-z.Produce HTML documentation for a class object.cs eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecSs d|_dS)Nr)needone)r>rrrrw sz1HTMLDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)Nz
r)r9)r>)pushrrmaybesz.HTMLDoc.docclass..HorizontalRule.maybeN)r%r&rUrwr;r)r:rrHorizontalRule sr<rz&
Method resolution order:
z
%s
z
c st||\}}|r|xl|D]d\}}}}yt|}Wn&tk rh||YnX||dq(W|S)Nr)rMr;r< Exception_docdescriptorr)msgrurKokr(rghomeclsrH)rrhrmdictr/rr:r>rrspills  zHTMLDoc.docclass..spillcsNt||\}}|rJ|x&|D]\}}}}||q(W|S)N)rMr;r>)r?rurKr@r(rgrArH)rBr/r:r>rrspilldescriptors1sz*HTMLDoc.docclass..spilldescriptorsc st||\}}|r|x|D]\}}}}t||}t|sZt|rht|dd} nd} | dkrd|n0t|j } d| } d|| fdq(W|S)NrVz
%s
z
%sz
%s%s
r) rMr;rr<callablerrerrr) r?rurKr@r(rgrArHrIr")rrrBrCr/rr:r>rr spilldata:s"  z#HTMLDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS))r9)rc)rir(rgrhrH)rrrrOs z$HTMLDoc.docclass..r{-rcs |dkS)Nrr)r%) thisclassrrrphrqz"HTMLDoc.docclass..z defined herezinherited from %sz:
z Methods %scSs |ddkS)Nrmethodr)r%rrrrpxrqzClass methods %scSs |ddkS)Nrz class methodr)r%rrrrpzrqzStatic methods %scSs |ddkS)Nrz static methodr)r%rrrrp|rqzData descriptors %scSs |ddkS)Nrzdata descriptorr)r%rrrrp~rqzData and other attributes %scSs |ddkS)Nrr4r)r%rrrrprqrz*class %sz/%s = class %sz(%s)z, Nz()z z%s
 
z#000000z#ffc8d8r0)r%rAr rrgetmror r;rr&rdr<r=rspopleftrMbuiltinsrrvAssertionErrorr! signature ValueErrorr)rrrrr)r>rr(r/rrr0realnamer!rr<mrorIrDrErGrurGrgrArHanchor inheritedtagrr"declrOargspecr"r) rrrBrCr/rr:r>rIrrs                               zHTMLDoc.docclasscCs|d||S)z)Format an argument default value as text.=)rr)r>rrrr formatvalueszHTMLDoc.formatvaluec Cs|j}|p |}|r|jpdd|} d} d} t|r|jj} |rZ| |k rd|| |} n0|jdk rzd||jj|} nd|| |} ||krd| |f} nD|rt||g|krd |jd||f}d } n|}d | ||f} d}t|rNyt|}Wnt t fk r d}YnX|rNt |}|d krNd |} |d d}|sXd}| | || ov| d| }| rd|S|t||j|||}|od|}d||fSdS)z;Produce HTML documentation for a function or method object.rrHrz from Nz method of %s instancez unbound %s methodz$%sz%srz)%s = %szz$%s lambda r}z(...)z'%sz
%s
z
%s
z
%s
%s
)r%r?r;rrrgetattr_staticr,rOrPrsr)rrrrr)r>rr(r/rrrFrErQrSnoteskipdocsimclassrZreallinkrWrOrVr"rrrrsX       zHTMLDoc.docroutinecCsTg}|j}|r|d||jdk rB|t||j}|d||dd|S)Nz!
%s
z
%s
z
r)r rVrrrr!)r>r(rHr/rfr:r"rrrr>s   zHTMLDoc._docdescriptorcCs||||S)z*Produce html documentation for a property.)r>)r>rr(r/rErrrrszHTMLDoc.docpropertycGs|r d|pd}|||S)z-Produce HTML documentation for a data object.z%s = r)r)r>rr(r/r0ZlhsrrrrszHTMLDoc.docothercCs||||S)z1Produce html documentation for a data descriptor.)r>)r>rr(r/rErrrrszHTMLDoc.docdatacCsg}|dkri}xLt|gD]<\}}}tdd|Drsz HTMLDoc.index..rrz#ffffffz#ee77aa)r,r-anyr rtrr r)r>rrr5r6r(r7rrrrindexs z HTMLDoc.index)r)rrNr)r|)N)NN)NNN)NN)NNN)N)r%r&rUrVr_repr_instancerrrrrrrrrrrrr r rrrrrYrr>rrrrbrrrrrs<   +  y$:   rc@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCs,t|d|_|_d|_d|_|_dS)Nrrr)rrwrrrrr)r>rrrrws  zTextRepr.__init__cCsTtt|dr@ddt|j}t||r@t||||Sttt||j S)Nr%rr]) rarr!r%rr<r3r5rr)r>rLrrrrrrs  zTextRepr.repr1cCsHt||j}t|}d|krDdt|ddkrDd|d||dS|S)Nr~z\\rrr)r3rrr/)r>rLrrrrrrrs  zTextRepr.repr_stringcCs,yttt||jSd|jjSdS)Nz <%s instance>)r3r5rrrr%)r>rLrrrrr(szTextRepr.repr_instanceN) r%r&rUrVrwrrrrrrrrrds  rdc@seZdZdZeZejZddZdddZddZ dd d Z dd dZ d ddZ ddZ d!ddZddZd"ddZd#ddZd$ddZd S)%TextDocz'Formatter class for text documentation.cCsddd|DS)z(Format a string in bold by overstriking.rcss|]}|d|VqdS)Nr)rir_rrrr`8szTextDoc.bold..)r!)r>r.rrrbold6sz TextDoc.bold cs>|sdSfdd|dD}|r4|d|d<d|S)z6Indent text by prepending a given prefix to each line.rcsg|] }|qSrr)rir)prefixrrr=sz"TextDoc.indent..rr})rrr!)r>r.rir#r)ririndent:s zTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rz )rjrrg)r>rrZclean_contentsrrrrAszTextDoc.sectionNrc sd}x|D]}t|tdkrt|\}}||t|}|rj||fkrjfdd|D} |dd| }|d}q t|tgkr |||||d}q W|S) zBRender in text a class tree as returned by inspect.getclasstree().rrc3s|]}t|VqdS)N)r))rir )r'rrr`Psz%TextDoc.formattree..z(%s)z, rz )rr)r!r) r>rr'rrirrr r!r"r)r'rrHs  zTextDoc.formattreec CsD|j}tt|\}}|d||o(d|}t|dd}||}|dk r`||d|d}|rt||d|}g} xNt|tjD]<\} } |dk st | p||krt | ||r| | | fqWg} xXt|tj D]F\} } |dk st | st | |krt | ||r| | | fqWg} x6t|tD]&\} } t | ||r8| | | fq8Wg}t}t|drxFt|jD]6\}}}|||r| |d n | |qW|||d d |}g}xBt|tjD]0\} } | j|d r| |kr| | qW|rJ|||d d |}| rdd| D}|t|d|g}x&| D]\} } | || | |qzW||dd |}| rg}x&| D]\} } | || | |qW||dd |}| rFg}x*| D]"\} } | |j| | |ddq W||dd |}t|drt|j}|dddkr|dddkr|dd}||d|}t|dr||dt|j }t|dr||dt|j!}t|d r||d!t|j"}yt#|}Wnt$k r.d"}YnX||d#|}|S)$z5Produce text documentation for a given module object.NAMEz - 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 DESCRIPTIONrRz (package)zPACKAGE CONTENTSrrZ SUBMODULEScSsg|] \}}|qSrr)rirGrHrrrrsz%TextDoc.docmodule..rCLASSES FUNCTIONSF)r2ZDATArXr#z $Revision: r}r$ZVERSIONrWZDATErPZAUTHORrZZCREDITSz (built-in)ZFILE)%r%r$rrr<rrr@r+r+rcr r,r8r-setrar,r-rRaddrtr!r*r_rr.rrr)rXrrWrPrZrrs)r>rr(r/ZsynopdescrrbrrrGrHrr4r5Z modpkgs_namesr6r'r7Z submodulesr8rr3rrrrrXs           $    zTextDoc.docmodulec sj}|p |}j}jfdd}||kr:d|}n|d|}|rlt||} |dd| }g} | jyt} Wnt t fk rd} YnX| rt | } | r| dkrʈ|| d t } | r| d t t}t|d kr.d x|D]}d ||q Wd Gfddd}|fdd}fdd}fdd}fddtD}x|r|r|n |dd t|fdd\}}tjkr|}qn krd}ndtj}t||d||dd}|d||d d}|d!||d"d}|d#||d$d}|d%||d&d}|gkst|}qWd | } | s|d S|d | d'd S)(z4Produce text documentation for a given class object.cSs t||S)N)r))r rrrrmakenamesz"TextDoc.docclass..makenamezclass z = class z(%s)z, Nz()rrzMethod resolution order:z rcs eZdZddZfddZdS)z(TextDoc.docclass..HorizontalRulecSs d|_dS)Nr)r9)r>rrrrwsz1TextDoc.docclass..HorizontalRule.__init__cs|jrdd|_dS)NzF----------------------------------------------------------------------r)r9)r>)r:rrr;sz.TextDoc.docclass..HorizontalRule.maybeN)r%r&rUrwr;r)r:rrr<sr<c st||\}}|r|x^|D]V\}}}}yt|}Wn&tk rh||Yq(X||q(W|S)N)rMr;r<r=r>r)r?rurKr@r(rgrArH)rBr/rr:r>rrrDszTextDoc.docclass..spillcsNt||\}}|rJ|x&|D]\}}}}||q(W|S)N)rMr;r>)r?rurKr@r(rgrArH)rBr/r:r>rrrEsz*TextDoc.docclass..spilldescriptorsc st||\}}|r|x~|D]v\}}}}t|sFt|rPt|}nd}yt|} Wntk r|j|} YnXj | |d|ddq(W|S)Nrn)r2r"r) rMr;rFrrerr<r__dict__r) r?rurKr@r(rgrArHr"r9)rBr/rr:r>rrrG s  z#TextDoc.docclass..spilldatacs,g|]$\}}}}t|dr||||fqS))r9)rc)rir(rgrhrH)rrrrs z$TextDoc.docclass..rcs |dkS)Nrr)r%)rIrrrp%rqz"TextDoc.docclass..z defined herezinherited from %sz Methods %s: cSs |ddkS)NrrJr)r%rrrrp4rqzClass methods %s: cSs |ddkS)Nrz class methodr)r%rrrrp6rqzStatic methods %s: cSs |ddkS)Nrz static methodr)r%rrrrp8rqzData descriptors %s: cSs |ddkS)Nrzdata descriptorr)r%rrrrp:rqzData and other attributes %s: cSs |ddkS)Nrr4r)r%rrrrp<rqz | )r%rAr&rgmapr!r rrOrPrsr)rrrKr rdrLrMrMrr)rvrNrjr)r>rr(r/r0rQr!rrrr"rrOrWr"rRrIr<rDrErGrurTrUr)rBr/rr:r>rIrrs                          zTextDoc.docclasscCsd||S)z)Format an argument default value as text.rX)r)r>rrrrrYFszTextDoc.formatvaluec Csr|j}|p |}d}d}t|rn|jj}|rB||k rndt||}n,|jdk r`dt|jj|}ndt||}||kr||} n,|rt||g|krd}||d|} d} t|ryt |} Wnt t fk rd} YnX| rt | } |d kr||d } | dd } | s&d } | | |} |r@| d St |pLd} | d | oj|| d SdS)z;Produce text documentation for a function or method object.rrz from Nz method of %s instancez unbound %s methodrz = zz lambda r}z(...)r)r%r?r;rr)rgrrZr,rOrPrsr)rrjr)r>rr(r/rErQr[r\r]rrWrOrVr"rrrrJsH       zTextDoc.docroutinecCsTg}|j}|r$||||dt|p.d}|rJ||||dd|S)Nrr)r rgrrjr!)r>r(rHr/rfr:r"rrrr>{s zTextDoc._docdescriptorcCs||||S)z*Produce text documentation for a property.)r>)r>rr(r/rErrrrszTextDoc.docpropertycCs||||S)z1Produce text documentation for a data descriptor.)r>)r>rr(r/rErrrrszTextDoc.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.z = rrNz...r)rr rgrjr)) r>rr(r/rr2r"rrZchoprrrrs  zTextDoc.docother)rh)Nr)NN)NN)NNN)NNN)NNN)NNNNN)r%r&rUrVrdrcrrgrjrrrrrYrr>rrrrrrrre.s    e   1  rec@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|S)Nr)r>r.rrrrgsz_PlainTextDoc.boldN)r%r&rUrVrgrrrrrusrucCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpager)r.rrrrwsrwc s8ttjdstSttjds tStjr4tjs8tStjdpNtjdrtj dkrjfddStjddkrfd dSfd dStjddkrtStj dkrd dSttd rt d dkrddSddl }| \}}t |z0ttd r t d|dkr ddStSWdt|XdS)z2Decide what method to use for paging through text.isattyZMANPAGERZPAGERZwin32cstt|S)N) tempfilepagerplain)r.) use_pagerrrrprqzgetpager..ZTERM)ZdumbZemacscstt|S)N) pipepagerrz)r.)r{rrrprqcs t|S)N)r|)r.)r{rrrprqcSstt|dS)Nzmore <)ryrz)r.rrrrprqsystemz(less) 2>/dev/nullrcSs t|dS)NZless)r|)r.rrrrprqNz more "%s"cSs t|dS)NZmore)r|)r.rrrrprq)rarstdin plainpagerstdoutrxr rrmplatformr}tempfileZmkstempclosettypagerunlink)rfdrr)r{rrvs6          rvcCstdd|S)z%Remove boldface formatting from text.z.r)rr)r.rrrrzsrzc Csddl}|j|d|jd}yDtj|jdd*}y||Wntk rPYnXWdQRXWntk rrYnXx(y| PWqvtk rYqvXqvWdS)z3Page through text by feeding it to another program.rNT)shellr~backslashreplace)errors) subprocessPopenPIPEio TextIOWrapperr~writeKeyboardInterruptrwait)r.cmdrprocpiperrrr|s r|c Cs`ddl}|}t|ddd}||WdQRXzt|d|dWdt|XdS)z.cSstjddddS)Nr}r)rr~rrrrrrprqZLINESrz -- more --)qQz ) r)bB)rzrrttyrr~filenoZ tcgetattrZ setcbreakrrrUnsupportedOperationrr rrmrPrrr!flushZ tcsetattrZ TCSAFLUSH) r.r#rroldZgetcharhrZincr rrrrsL              &rcCstjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrrrzr)r.rrrr"srcCst|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.%szclass z function zmethod )rr*r%rrrar8r __objclass__r&rr+r6r7r)thingrrrdescribe&s.                    rc Csdd|dD}d\}}xB|t|kr^td|d|d|}|rZ||d}}qPqW|rj|}nt}x8||dD](}yt||}Wq|tk rdSXq|W|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|] }|r|qSrr)rirrrrrCszlocate..r)NrNr)rr rr!rMr<r)rrr1rnZ nextmodulerrrrrlocateAs  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%)rr)rrr<)rrrr(rrrresolveZs    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 |st |t st|}|d7}||d|||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module z objectz )r.rrrr+rfindr%r*r+r,rrrrrr)rrrZrendererrr(rqrrrr render_dochs$         rc Csfy2|dkrtt|||n|t|||tWn.ttfk r`}z t|Wdd}~XYnXdS)zCDisplay text documentation, given an object or a path to an object.N)rwrr plaintextrrprint)rrroutputrHrrrr"s r"c Csy`t||\}}tt|t||}t|dddd}||WdQRXtd|dWn.tt fk r}z t|Wdd}~XYnXdS)z\ZZ x4e D],Z e e eZ ee kre d<eZ e ee <qWqWd=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdLdMdNdOdPdQddRdSdSdTdUdVdWdXdYdZd[d\d]d^d_d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{dd d|d}d~ddIZ dddZ eddZeddZddZeZefddZddZddZddZddZdddZddZddZddZdddZdddZddZdddZ dS)HelperrBOOLEANwith)assertr)asyncr)awaitr)breakz while for)classzCLASSES SPECIALMETHODS)continuez while for)Zfunctionr)del BASICMETHODSif)elsez while fortry)forzbreak continue whileimport)globalznonlocal NAMESPACES)r TRUTHVALUE)rMODULES)inSEQUENCEMETHODS COMPARISON)lambdarm)nonlocalzglobal NAMESPACES)passr)raise EXCEPTIONS)returnrm)rr)whilezbreak continue if TRUTHVALUE)rz CONTEXTMANAGERS EXCEPTIONS yield)yieldr)#FalseNoneTrueandasrrrrrrdefrelifrexceptfinallyrfromrrrrisrrnotorrrrrrrrcCsg|]}dD] }||q qS))'r r)riprrrrrszHelper.)rfrur'''r """)+rH*z**rz//%z<>r|^~rrz<=z>=z==z!=z<>)rrz<=z>=z==z!=z<>)rHr) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)z<>rrrr)jJ)STRINGS OPERATORSrUNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classr PRIVATENAMESzPRIVATENAMES SPECIALMETHODSZ BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rz**,rz...:@r~r]r\`r r[]r)typeszRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES)zstring-methodszSTRINGS FORMATTING)Z formatstringsr)rz: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)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)Zobjectsr)Z specialnameszbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSES)Z customizationzhash repr str SPECIALMETHODS)zattribute-accesszATTRIBUTES SPECIALMETHODS)zcallable-typeszCALLS SPECIALMETHODS)zsequence-typesz(SEQUENCES SEQUENCEMETHODS SPECIALMETHODS)zsequence-typeszMAPPINGS 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)Zcallsr)Zpowerr)Zunaryr)Zbinaryr)Zshiftingr)Zbitwiser)Z comparisonszEXPRESSIONS BASICMETHODS)ZbooleanszEXPRESSIONS TRUTHVALUEr)Z assignmentr)Z augassign NUMBERMETHODSrr)Zcompoundzfor while break continue)truthz if while and or not BASICMETHODS)ZdebuggerZpdb)zcontext-managersr)IrrZ STRINGMETHODSZ FORMATTINGUNICODEZNUMBERSZINTEGERZFLOATrrZMAPPINGSrmZMETHODSZ CODEOBJECTSZ TYPEOBJECTSZ FRAMEOBJECTSZ TRACEBACKSZNONErZSPECIALATTRIBUTESrlrZPACKAGESrrZ PRECEDENCEZOBJECTSZSPECIALMETHODSrZATTRIBUTEMETHODSZCALLABLEMETHODSrZMAPPINGMETHODSr Z EXECUTIONrZDYNAMICFEATURESZSCOPINGZFRAMESrZ CONVERSIONSZ IDENTIFIERSZSPECIALIDENTIFIERSrZLITERALSZTUPLESZ TUPLELITERALSZLISTSrrr Z ATTRIBUTESZ SUBSCRIPTSrZCALLSrrZBINARYZSHIFTINGrrrZ ASSERTIONZ ASSIGNMENTrZDELETIONZ RETURNINGZ IMPORTINGZ CONDITIONALZLOOPINGrZ DEBUGGINGZCONTEXTMANAGERSNcCs||_||_dS)N)_input_output)r>inputrrrrrwMszHelper.__init__cCs |jp tjS)N)r rr~)r>rrrrQsz Helper.inputcCs |jp tjS)N)rrr)r>rrrrUsz Helper.outputcCs2tdddkr|dSd|jj|jjfS)Nrr0?rz<%s.%s instance>)rstackrr&rU)r>rrr__repr__Ys 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. )_GoInteractiverintrointeractrr)r>requestrrr__call__as   zHelper.__call__c Cs|jdxy|d}|s PWnttfk r<PYnX|}t|dkr|d|dkrndkrnn |d|ddkr|dd}|dkrP|d kr|q| |qWdS) Nrzhelp> rrr})rr r)rquitr) rrgetlinerEOFErrorrr rrr)r>rrrrrns"  ,   zHelper.interactcCs8|jtjkrt|S|j||j|jSdS)z.Read one line, using input() when appropriate.N)rrr~rrrr)r>promptrrrrs    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)rrrz Help on %s:)rr)rr listkeywords listsymbols listtopics listmodulesrr showsymbolr"evalr showtopicrrr)rrrr)r>rrrrrs6        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)rrrrr)r>rrrrsz Helper.intror|Pc Cstt|}||}t||d|}xt|D]z}xht|D]\}|||}|t|kr@|j||||dkr@|jdd|dt||q@W|jdq2WdS)Nrrr)rsortedr rrr) r>itemscolumnsrZcolwrrowrrjrrrrs    (z Helper.listcCs |jd||jdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rrrrrD)r>rrrr szHelper.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. )rrrrrD)r>rrrr!szHelper.listsymbolscCs |jd||jdS)NzN Here is a list of available topics. Enter any topic name to get more help. )rrrrrD)r>rrrr"szHelper.listtopicsc Cs,y ddl}Wn tk r,|jddSX|j||j|}|s`|jdt|dSt|tdkr|| ||S|\}}y|jj|}Wn(t k r|jdt|dSX| d}|r|pdd|}|r ddl }dd |d} || d } |d d | 7}t|dS) Nrzt Sorry, topic and keyword documentation is not available because the module "pydoc_data.topics" could not be found. zno documentation found for %s rrrzRelated help topics: z, Hz %s )pydoc_data.topicsrrrrrmrrrr&KeyErrorrtextwrapr!rZwraprw) r>topic more_xrefs pydoc_datatargetlabelxrefsr"r/r.Z wrapped_textrrrr&s6    zHelper.showtopiccCsy ddl}Wntk r dSX|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)zt Sorry, topic and keyword documentation is not available because the module "pydoc_data.topics" could not be found. rzcould not find topicrr) r-rrrmrrPrr) _gettopic)r>r0r1r2r3r4r5r"rrrr6s     zHelper._gettopiccCs*|j|}|d\}}}|||dS)Nr)r partitionr&)r>symbolr3r0r]r5rrrr$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)Niz .__init__z (package)rrr)find)rr'rqrrrrcallback#sz$Helper.listmodules..callbackcsd|ddS)Nr)r')r:rronerror(sz#Helper.listmodules..onerror)r;z 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 ModuleScannerrunrrD)r>rGrr;r)r:rr#s    zHelper.listmodules)rrr r)NN)r|r')r)r)r)!r%r&rUrZ _strprefixesZ_symbols_inverserr)r0Zsymbols_r8rmrrwrrrrrrrrrrrrr r!r"r&r6r$r#rrrrrs6          rc@seZdZdZdddZdS)r=z7An interruptible scanner that searches module synopses.Nc Cs |r |}d|_i}xztjD]p}|dkrd||<|dkrH|d|dqt|jpTd}|dd}|d|}||dkr|d||qWxdtj |dD]R\} }} |jrP|dkr|d|dqyt | |} Wnt k rwYnX| j } t | d rny| |} Wn&tk r:|r4||wYnXtt| pNd}t | d rh| |}nd}n^ytj| }Wn&tk r|r||wYnX|jr|jdnd}t|d d}|d|}||dkr||||qW|r|dS) NF__main__rrrrz - )r; get_source get_filenamer[)rrrrrrVrr9r,r _get_specrrrar@r=rrStringIOrArrrrrr<)r>r:rGZ completerr;seenr'r(rqr6r7rrsourcerrrrrr>6s`       zModuleScanner.run)NNN)r%r&rUrVr>rrrrr=3sr=c CsDdd}dd}t"tdtj|||dWdQRXdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr |ddd}t||o.d|dS)Niz .__init__z (package)z- )r)rr'rqrrrr:rszapropos..callbackcSsdS)Nr)r'rrrr;vszapropos..onerrorignore)r;N)warningscatch_warningsfilterwarningsr=r>)rGr:r;rrrr<ps   r<csddlddlddlddlGdddjjGfdddjjGfdddj}||||}|x|j s|j st d qW|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.cssztext/cssz text/htmlz Content-Typez%s; charset=UTF-8zutf-8N) rr`Z send_responseZ send_headerZ end_headersZwfiler urlhandlerr)r> content_typerrrdo_GETs   z(_start_server..DocHandler.do_GETcWsdS)Nr)r>rrrr log_messagesz-_start_server..DocHandler.log_messageN)r%r&rUrMrNrrrr DocHandlersrOcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dS)NF)hostZaddressr:rIrwhandlerr)r>rPportr:rrrrws  z)_start_server..DocServer.__init__csBx4|js4|jgggd\}}}|r|qW|dS)Nr)rselectZsocketrZhandle_requestZ server_close)r>ZrdZwrZex)rSrrserve_until_quits  z1_start_server..DocServer.serve_until_quitcSs |j||jr||dS)N)rIserver_activater:)r>rrrrUs z0_start_server..DocServer.server_activateN)r%r&rUrwrTrUr)rSrr DocServers rVcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dS)NF)rKrPrrRThreadrwservingerror)r>rKrPrR) threadingrrrws   z,_start_server..ServerThread.__init__c sxyJjj__jj_t|j_|j |j |j }||_ | Wn(tk rr}z ||_Wdd}~XYnXdS)zStart the server.N)server HTTPServerrIrQrZMessageZ MessageClass staticmethodrKrPrRready docserverrTr=rY)r>Zdocsvre)rOrVemailhttprrr>s    z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rXrPZ server_portrRr )r>r[rrrr^sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)r_rr!rXr )r>rrrstop s z(_start_server..ServerThread.stopN)r%r&rUrwr>r^rcr)rOrVrarbrZrr ServerThreads  rdg{Gz?) Z http.serverZ email.messagerSrZr[ZBaseHTTPRequestHandlerr\rWrrYrXtimeZsleep)rKhostnamerRrdZthreadr)rOrVrarbrSrZr _start_server~s8' rg text/htmlc sGfdddt}|fddfddfddfd d fd d fd dfddfddfdd}|dr|dd}|dkrtjtjt}tj||}t|}d| SQRXn|dkr||St d||fdS)aThe pydoc url handler for use with the pydoc server. If the content_type is 'text/css', the _pydoc.css style sheet is read and returned if it exits. If the content_type is 'text/html', then the result of get_html_page(url) is returned. cseZdZfddZdS)z_url_handler.._HTMLDoccsd}d|}d|||fS)zFormat an HTML page.zpydoc_data/_pydoc.cssz1a  Pydoc: %s %s%s
%s
r)r>rrcss_pathZcss_link) html_navbarrrr! sz#_url_handler.._HTMLDoc.pageN)r%r&rUrr)rjrr_HTMLDoc srkcs>dttdtf}d|tjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)Zterse)rrZpython_versionZ python_buildZpython_compiler)r3)rrrrj1 s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}x tjD]}|||qVW|d d d |fS)zModule Index page.cSs d||fS)Nz%sr)r(rrr bltinlinkO sz3_url_handler..html_index..bltinlinkz7Index of Modulesz#ffffffz#7799eecSsg|]}|dkr|qS)r?r)rir(rrrrU sz4_url_handler..html_index..z

zBuilt-in Modulesz#ee77aaz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of Modulesr) rrrrrrr rbr!)rlrnamesrrDr)rrr html_indexL s  z _url_handler..html_indexc sgfdd}t*tddd}tj|||dWdQRXdd }g}d d d }x"D]\}}||||qhW|d |d dd|}d|fS)zSearch results page.cs:|dddkr |ddd}||o0d|fdS)Niz .__init__z (package)z- )r )rr'rq) search_resultrrr:j sz3_url_handler..html_search..callbackrFcSsdS)Nr)r'rrrr;q sz2_url_handler..html_search..onerror)r;NcSs d||fS)Nz%sr)r(rrrrlv sz4_url_handler..html_search..bltinlinkz5Search Resultsz#ffffffz#7799eezkey = %sz#ee77aaz
zSearch Results) rGrHrIr=r>rr rr!) rGr:r;rlrfrr(rqr)r)ror html_searche s    z!_url_handler..html_searchcsLdd}ddd}ttj}||}|ddd|}d|fS)zIndex of topic texts available.cSs d||fS)Nz%sr)r(rrrrl sz4_url_handler..html_topics..bltinlinkz,INDEXz#ffffffz#7799eeZTopicsz#ee77aa)rr(rrrDrr)rlrrmr)rrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.z,INDEXz#ffffffz#7799eecSs d||fS)Nz%sr)r(rrrrl sz6_url_handler..html_keywords..bltinlinkZKeywordsz#ee77aa)rr(rrrDrr)rrmrlr)rrr 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.ZKEYWORDZTOPICz)%sz#ffffffz#7799eez

%s
z#ee77aacSs d||fS)Nz%sr)r(rrrrl sz7_url_handler..html_topicpage..bltinlinkzRelated help topics: z%s %sr) rrCrr6rrrrr(rrrr!)r0ZbufZhtmlhelprr5rrrl)rrrhtml_topicpage s&      z$_url_handler..html_topicpagecs@t|dd}|dkr$|dkr$tdt|}||}||fS)Nr)rrzcould not find object)rrPrr)r r9rcontent)rrr html_getobj s   z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,Errorz#ffffffz#7799eez
c3s|]}|VqdS)N)r)rir)rrrr` sz3_url_handler..html_error..z#bb0000z Error - %s)rr!rrr)r rrr)rrr html_error s z _url_handler..html_errorc sr|}|dr|dd}y|dkr2\}}n|dkrF\}}n|dkrZ\}}nd|kr$|d\}}}|dkr|\}}n|d kry|\}}Wn tk r|\}}YnXn\|d kr|dkr\}}n4y|\}}Wn"tk r|\}}YnXntd n |\}}Wn2tk rd}z||\}}Wdd}~XYnX||S) zGenerate an HTML page for url.z.htmlN)rrbrrrXz search?keyz topic?keyzget?keyz bad pydoc url)r`r7rPr=r)r Z complete_urlrrtopr]r)rrvrurnrrrprsrqrr get_html_page s>          z#_url_handler..get_html_pagerrNztext/cssrz text/htmlz"unknown content type %r for url %s) rr_r rdirnamerealpathr[r!r readlinesrs)r rLrkryZ path_hererifpr) rrvrurnrrrjrprsrqr _url_handler s*         (    r~T localhost) open_browserrfc Csddl}tt||}|jr(t|jdS|jrd}|rB||jzy^td|jt|xD|jrtd}| }|dkr~Pq\|dkr||jq\t|q\WWnt t fk rtYnXWd|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 ready atzserver> rrzServer stopped) webbrowserrgr~rYrrXrr rrrrrc)rRrrfrZ serverthreadZserver_help_msgrrrrbrowse s2    rcCst|to|tjdkS)Nr)rr)r9r sep)rLrrrispath( 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 curdirgetcwdrrzr[copysamefileremoveinsert)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_pathG src Csddl}Gdddt}typ|tjddd\}}d}d}d}d}d}x`|D]X\} } | d krnd }d }| d krt| dS| d krd }| }| d krd }| dkrVd }| }qVW|rt|||ddS|s|x|D]} t| rtj | st d| Py`t| rtj | rt | } |rPt| rFtj | rFt| nt| n t| Wqtk r} z t | Wdd} ~ XYqXqWWnN|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&rUrrrrBadUsageT srrzbk:n:p:wFrz-bTz-kz-pz-wz-n)rfrzfile %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)getoptr=rrrr<rrr rexistsrrxrr rrrrrYrrrr)rrZoptsrZwritingZ start_serverrrRrfZoptvalargrHrrrrcliQ s`    "rr?)NN)r)r)rrN)rrN)r)rN)rh)r)[rVr&rPrWrZrMZimportlib._bootstraprZimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrr r,rrrrrerZ urllib.parser'rG collectionsrreprlibr tracebackrrrr$r)r-r/r3r IGNORECASEr4r5r:r?rCrMrcrdrvrzrrr=rrrrrrrdrerurwrvrzr|ryrrrrrr.rrrrr"rrrrr=r<rgr~rrrrrr%rrrr&s           ' 0<*; p" ,    = n% U