o w[e<@s6dZdgZdZdZdZddlZddlZddlZddl 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^ZO  dd`daZP  ddbdcZQddddeZRddgdhZSGdidjdjZTeTZUGdkdldlZVdmdnZWdodpZXddrdsZYddtdudvdwdxZZdydzZ[d{d|Z\d}d~Z]ddZ^e_dkre^dSdS)a^Generate Python documentation in HTML or text for interactive use. At the Python interactive prompt, calling help(thing) on a Python object documents the object, and calling help() starts up an interactive help session. Or, at the shell command line outside of Python: Run "pydoc " to show documentation on something. may be the name of a function, module, package, or a dotted reference to a class or function within a module or module in a package. If the argument contains a path segment delimiter (e.g. slash on Unix, backslash on Windows) it is treated as the path to a Python source file. Run "pydoc -k " to search for a keyword in the synopsis lines of all available modules. Run "pydoc -n " to start an HTTP server with the given hostname (default: localhost) on the local machine. Run "pydoc -p " to start an HTTP server on the given port on the local machine. Port number 0 can be used to get an arbitrary unused port. Run "pydoc -b" to start an HTTP server on an arbitrary unused port and open a web browser to interactively browse documentation. Combine with the -n and -p options to control the hostname and port used. Run "pydoc -w " to write out the HTML documentation for a module to a file named ".html". Module docs for core modules are assumed to be in /usr/share/doc/pythonX.Y/html/library if the pythonX.Y-doc package is installed or in https://docs.python.org/X.Y/library/ This can be overridden by setting the PYTHONDOCS environment variable to a different URL or to a local directory containing the Library Reference Manual pages. helpzKa-Ping Yee z26 February 2001zGuido van Rossum, for an excellent programming language. Tommy Burnette, the original creator of manpy. Paul Prescod, for all his work on onlinehelp. Richard Chamberlain, for the first implementation of textdoc. N)deque)Repr)format_exception_onlycCs\g}g}tjD]$}tj|pd}tj|}||vr+tj|r+||||q|S)zAConvert sys.path into a list of absolute, existing, unique paths..)syspathosabspathnormcaseisdirappend)dirsnormdirsdirnormdirr/usr/lib/python3.10/pydoc.pypathdirsVs    rcCst|o t|tj SN)inspectisclass isinstancetypes GenericAliasobjectrrr_isclassbsrcCsNtj|j}|dur dS|jdddD]}t||}qt|s%dS|S)Nr)rmodulesget __module__ __qualname__splitgetattrr)funcclsnamerrr _findclasses r(c Cst|r#|jj}|j}t|rtt||dd|jur|}n|j}nt|r=|j}t |}|dus:t|||urSplit a doc string into a synopsis line (if any) and the rest. rrIN)stripr#lenrMjoin)r?linesrrrsplitdocs   rWcCs"|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 rYcCs<t|pt|pt|pt|pt|pt| S)z>Check if an object is of a type that probably means it's data.)rismoduler isroutineisframe istracebackiscoderrrrisdatasr_cGs0|r|d||d}|dd}|s|S)z/Do a series of global replacements on a string.rQrrRN)rUr#)textpairsrrrreplaces  rbcCsXt||kr*td|dd}td|d|}|d|d|t||dS|S)zCOmit part of a string if needed to make it fit in a maximum length.rrRN...)rTmax)r`maxlenprepostrrrcrams $riz at 0x[0-9a-f]{6,16}(>+)$cCs td|S)z>Remove the hexadecimal id from a Python object representation.z\1) _re_stripidrLr`rrrstripids rlcCs<t|rdSt|rt|dd}t|p|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+r0r$rZ)fnr<rrr_is_bound_methods   rncCs^i}t|tjD]\}}d||<q |jD] }|t|q|D] }t||||<q#|SNrQ)r getmembersr[ __bases__update allmethodskeysr$)clmethodskeyvaluer>rrrrss   rscCs8g}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 predicateyesnoxrrr _split_lists  rcCsX|dvrdS|dr|drdS|drt|drdS|dur&||vS|d S) z3Decide whether to show documentation on a variable.>rA__date____file__r,__path____spec__r* __author__ __cached__ __loader__r! __credits__ __package__ __version__ __builtins__r"r__rQ__fieldsTN) startswithendswithhasattr)r'allr;rrr visiblenames rcCsXg}t|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_attrsr4rr1fsetr )rresultsr'kindr&rxrrrr-s rcsZt|dgz fddtDWn tyiYnwfdd}|j|ddS)zGSort the attrs list in-place by _fields and then alphabetically by namercsi|] \}}||tqSr)rT).0ir')fieldsrr >z#sort_attributes..cs|dd|dfSNr)r )attr) field_orderrrAsz!sort_attributes..rwN)r$ enumeraterFsort)attrsrkeyfuncr)rrrsort_attributes8s   rcCs:tj|rdD]}tjtj|d|rdSqdS)z3Guess whether a path refers to a package directory.)z.pyz.pyc__init__TF)r rr isfilerU)rextrrr ispackageFs rcCs|}|dddks|s#|}|sn |dddks|r|}|dddkr5|dd}|dddkrk|dd}|dddkrQ|dd}|s`|}|s\n|rU|dd }|Sd}|S) NrQ#zr"""rc"""r\r)readlinerSr#)filelinerNrrrsource_synopsisNs$ rc Cs,t|j}||d\}}|dus||kr|ttjjr$tjj }n|ttjj r2tjj }nd}|durazt |}Wn tyIYdSw| t|}Wdn1s[wYn-|d|}tjjd||d}ztj|} WnYdStjd=| jr| jdnd}||f||<|S)z.Get the one-line summary out of a module file.NNN__temp__loaderr)r statst_mtimer rtuple importlib machineryBYTECODE_SUFFIXESSourcelessFileLoaderEXTENSION_SUFFIXESExtensionFileLoadertokenizeopenOSErrorrutilspec_from_file_location _bootstrap_loadrrrA splitlines) filenamecachemtime lastupdaterN loader_clsrrspecmodulerrrsynopsis_s<        rc@s eZdZdZddZddZdS)ErrorDuringImportzEErrors that occurred while trying to import something to document it.cCs||_|\|_|_|_dSr)rexcrxtb)r<rexc_inforrrrszErrorDuringImport.__init__cCs|jj}d|j||jfS)Nzproblem in %s - %s: %s)rr,rrx)r<rrrr__str__szErrorDuringImport.__str__N)r,r!r"rArrrrrrrs rc Cstjj}t|d}||t|k}Wdn1swYtj|}tj |\}}|r:tj ||}ntj ||}tjj |||d}ztj|WSt|t)zrzsafeimport..NrrQ)rrbuiltin_module_names __import__rrr SyntaxErrorr issubclass ImportErrorr'r#r$r:) r forceloadrsubsrwrrrxrinfopartrrr safeimports*     rc@sfeZdZejddejddZd ddZ d ddZ e Z Z Z ZZZed fd d ZdS) Doc PYTHONDOCSz%https://docs.python.org/%d.%d/libraryNrRcGs||f|}z"t|r|j|WSt|r|j|WSt|r'|j|WSWn ty1Ynwt|r<|j |S|j |S)z%Generate documentation for an object.) rrZ docmodulerdocclassr[ docroutiner:r4docdatadocother)r<rr'argsrrrdocuments   z Doc.documentcGs&d|odt|t|jf}t|)z+Raise an exception for unimplemented types.z.don't know how to document object%s of type %s )reprrCr,rF)r<rr'rmessagerrrfailszDoc.failstdlibcCszt|}Wn tyd}Ynwtjd|j}tj|}t |t trl|j dvsF| |rl| tj |dsl| tj |dsl|j dvrl| dr^d|d |j }|Stj ||j d }|Sd }|S) z*Return the location of module docs or None (built-in)r) errno exceptionsgcimpmarshalposixsignalr_thread zipimportz dist-packagesz site-packages)z xml.etreeztest.pydoc_mod)zhttp://zhttps://z {}/{}.html/.htmlN)r getabsfilerFr environr rrr rrCr,rrUformatrMlower)r<rbasedirrdoclocrrr getdoclocs.     z Doc.getdoclocr)r,r!r"r rr r version_inforrrrrrr docpropertyr sysconfigget_pathr rrrrrs   rc@sHeZdZdZddZddZddZdd Zd d ZeZ d d Z eZ dS)HTMLReprzBClass for safely making an HTML representation of a Python object.cC,t|d|_|_d|_d|_|_dSN drrmaxlistmaxtuplemaxdict maxstringmaxotherr<rrrr  zHTMLRepr.__init__cCst|ddddddS)N&z&z>)rbr<r`rrrescapeszHTMLRepr.escapecCs t||Sr)rrr<rrrrr z HTMLRepr.reprcCsZtt|dr ddt|j}t||r t||||S|ttt ||j SNr,repr_r) rrCrUr,r#r$r$rirlrrr<r~level methodnamerrrrepr1s  zHTMLRepr.repr1cCs^t||j}t|}d|vr%dt|ddvr%d|d|||dStdd||S)Nr\\rIrrz-((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)z\1)rirrrbr$rKrLr<r~r*testtestreprrrr repr_string"s zHTMLRepr.repr_stringcCs:z|ttt||jWS|d|jjYSNz <%s instance>)r$rirlrrr.r,r<r~r*rrr repr_instance/szHTMLRepr.repr_instanceN) r,r!r"rArr$rr,r2repr_strr5 repr_unicoderrrrr s rc@seZdZdZeZejZejZddZd1ddZ  d2d d Z d d Z ddZ d3ddZ ddZddZddZddZddZddZdiiifdd Zd4d!d"Zd5d#d$Zddiifd%d&Zd'd(Zddiiidfd)d*Zd6d+d,ZeZd5d-d.Zd4d/d0ZdS)7HTMLDocz'Formatter class for HTML documentation.cC d||fS)Format an HTML page.z Python: %s %s r)r<titlecontentsrrrpage@sz HTMLDoc.pagerIcCsd|||||pdfS)zFormat a page heading.a'
 
 
%s
%s
 r)r<r;fgcolbgcolextrasrrrheadingJszHTMLDoc.headingNr>c Cs^|dur dd|d}d|||f} |r | d||||f} n | d|||f} | d|S) z Format a section with a heading.Nzr>zz

zR z( z'
 
%s
%s %s
%s
%s%s%s
r) r<r;r?r@r<widthprelude marginaliagaprNrrrsectionUs  zHTMLDoc.sectioncGsd|}|j|g|RS)z$Format a section with a big heading.z%s)rH)r<r;rrrr bigsectionkszHTMLDoc.bigsectionc Cs&||}t|dddddddd S)z!Format literal preformatted text. z rr>rP
)r$ expandtabsrbr#rrr preformatps zHTMLDoc.preformatrcCsd}t||d|}t|D],}|dd|}t|||||D]}|t|kr7||||d}q%|d}qd|S)z0Format a list of items into a multi-column list.rIrQzrrKzz7%s
)rTrange)r<listr colsrNrowscolrrrr multicolumnvs   zHTMLDoc.multicolumncCsd|S)Nz%srr#rrrgreysz HTMLDoc.greycGs*|D]}||vrd|||fSq|S)z:Make a link for an identifier, given name-to-URL mappings.%sr)r<r'dictsr7rrrnamelinks zHTMLDoc.namelinkcCsN|jtj|j}}t||r"t|||ur"d|j|t||fSt||S)zMake a link for a class.z%s)r,rrr r!rr$rY)r<rrXr'rrrr classlinks  zHTMLDoc.classlinkcCsd|j|jfS)zMake a link for a module.%s)r,r%rrr modulelinkszHTMLDoc.modulelinkcCsR|\}}}}|r ||S|rd||f}nd|}|r!d|}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)rU)rT)r< modpkginfor'rrshadowedurlr`rrr modpkglinks    zHTMLDoc.modpkglinkcCr9)zMake a link to source file.z%sr)r<r]rrrrfilelink zHTMLDoc.filelinkcCs|p|j}g}d}td} |||} | sn| \} } ||||| | \} } }}}}| rG|| dd}|d||fng|r[dt|}|d||| fnS|rodt|}|d||| fn?|r|| | d d kr|d | ||n'|d |n|| | d d kr|| ||||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+))T"z"rUz'http://www.rfc-editor.org/rfc/rfc%d.txtz)https://www.python.org/dev/peps/pep-%04d/rQ(zself.zself.%sNrI) r$rKcompilesearchspanr groupsrbintrWrU)r<r`r$funcsclassesrvrherepatternmatchstartendrschemerfcpepselfdotr'r]rrrmarkups<       zHTMLDoc.markupc Csd}|D]T}t|tdurE|\}}|d}||||}|r@||fkr@g}|D] } ||| |q)|dd|d}|d}qt|tgurX|d||||}qd |S) zAProduce HTML for a class tree as given by inspect.getclasstree().rIrz"

rb, )z
z
%s
z
%s
)rCrXr rU formattree) r<treerXparentrNentrycbasesparentsr>rrrrvs$ zHTMLDoc.formattreec# s|j}z|j}Wn tyd}Ynw|d}g}tt|dD]}|dd|d|d||fq#d||dd} d| } zt |} t j | } | | } Wn tygd} Ynwg}t|drt|j}|dd d kr|ddd kr|d d}|d |t|d r|t|j|r| dd|} |}|durdt}nd}| ddd| |}t|tj}gi}}t|tD]*\}}|dust|p||ur t|||r |||fd|||<||<q|D]@\}}|jD]7}|j|j}}tj !|}||krJ|rJt||rJt"|||urJ||vrJ|d|||<||<qq gi}}t|tj#D]8\}}|dusqt$|sqt||urt|||r|||fd|||<t%|r||||<qZg}t|t&D]\}}t|||r|||fq't(|j)||}|od|}|d|}t|drg}t*+|j,D]\}}} |||| dfq|-.|j/}!|0ddd|!}n|r.|fdd}!|0d dd|!}|rHd!d"|D}"1t2|"d|g}!|D]\}}|!3|||||q)|0d#dd$d%|!}|rng}!|D]\}}|!3|||||qO|0d&dd'd%|!}|rg}!|D]\}}|!3||qu|0d(dd)d*|!}t|d+r't|j4j)}!|0d,dd|!}t|d-rň't|j5j)}!|0d.dd|!}|S)/z/Produce HTML documentation for a module object.NrrQz5%sr)%srr $Revision: $z version %srz (%s)rtz-
Module ReferencerI#ffffff#7799eezindex
rz.html#z#-z %sz

%s

rrzPackage Contentsz#aa55cccs|dSro)rZtrrrr>z#HTMLDoc.docmodule..ModulescSg|]\}}|qSrrrrwrxrrrrCz%HTMLDoc.docmodule..Classes#ee77aar Functionsz#eeaa77Dataz#55aa55rKrAuthorrCredits)6r,__all__r:r#rNrTr rUrrurllibparsequoter_rFrrDrrSr$rr localsrBrprZr getmodulerrqr!rrr r$r[r0r/r_rsrOrMpkgutil iter_modulesrrrSr^rIrv getclasstreerrr)#r<rr'modignoredrpartslinksr linkednameheadrr]r_rversionr rNrricdictrwrxr>rXrrhfdictdatar?modpkgsimporterispkgr< classlistrrrrs                             zHTMLDoc.docmodulec sj}|p|}j}g} | jGfddd} | tt} t| dkrDd| D] } d| j q2dfdd} fd d }fd d }fd dt D}i|D]2\}}}}d|d||<}zt |}Wn t yYnwz||<Wqvt yYqvw|r1| r| n|ddt|fdd\}}tjurшtjur|}qurd}n dj }|d7}t|| d||dd}| d||dd}| d||dd}|d||dd}|d||d d}|d!||d"d}|gks-J|}|sd#| } ||krBd$||f}nd%|||f}|rgg}|D] } || j qP|d&d'|}d#}zt}Wntt fy~d(}Ynw|rt|}|r|d)kr||d*}t}|r||pd#}|j}|od+|}|d,d-| d.|S)/z.Produce HTML documentation for a class object.c eZdZddZfddZdS)z(HTMLDoc.docclass..HorizontalRulecS d|_dSrneedonerrrrrm z1HTMLDoc.docclass..HorizontalRule.__init__c|jrdd|_dS)Nz
rQrrpushrrmaybeo z.HTMLDoc.docclass..HorizontalRule.maybeNr,r!r"rrrrrrHorizontalRulelrrRz&
Method resolution order:
z
%s

c st||\}}|rE||D]1\}}}}zt|}Wnty2||Ynw||dq|S)NrPrrr$ Exceptionrrmsgrr{okr'rhomeclsrxrirhhrmdictrrrr<rrspills   zHTMLDoc.docclass..spillcJt||\}}|r#||D]\}}}}||q|Srrrrrrrrr<rrspilldescriptorsz*HTMLDoc.docclass..spilldescriptorsc st||\}}|rM||D]9\}}}}t||}t|} | s0d|nt|j} d| } d|| fdq|S)Nz
%s
z
%sz
%s%s
rP)rrrr$rOrsrM) rrr{rr'rrrxr>r?rrr spilldatas  z#HTMLDoc.docclass..spilldatac,g|]\}}}}t|dr||||fqS)r;rrr'rr&rxrrrr  z$HTMLDoc.docclass..r-rc |duSNrRrr thisclassrrr z"HTMLDoc.docclass.. defined hereinherited from %sz:
z Methods %scS |ddkSNrQmethodrrrrrrrzClass methods %scSrNrQz class methodrrrrrrrzStatic methods %scSrNrQz static methodrrrrrrrzReadonly properties %scSrNrQrrrrrrrrzData descriptors %scSrNrQrrrrrrrrzData and other attributes %scSrNrQrrrrrrrrrIz*class %sz/%s = class %s(%s)rtN()rJz%s
 
z#000000z#ffc8d8rc)r,rqr rrgetmrorTrrXr!rr$rrFpopleftrbuiltinsrrrU signature ValueErrorrDr$rOrsrMrH)r<rr'rrhrirrealnamer{r<rmror>rrrrrwrrrxanchor inheritedtagr;r|declrargspecr?r) rirhrrrrrr<rrras                 # zHTMLDoc.docclasscCs|d||Sz)Format an argument default value as text.=)rTrr%rrr formatvaluezHTMLDoc.formatvaluec Cs|j}|p|}|r |jp dd|} d} d} t|rE|jj} |r-| |ur,d|| |} n|jdur=d||jj|} nd|| |} t|sOt|rRd} nd} ||kr_d | |f}n"|rxt||g|urxd |jd||f}d } n|}d | ||f}d}t |rzt |}Wn t t fyd}Ynw|rt |}|d krd|}|d d}|sd}| |||| o|d| }| rd|S|t||j|||}|od|}d||fS)z;Produce HTML documentation for a function or method object.rIrr from N method of %s instance unbound %s methodasync z$%sz%srQz)%s = %sz$%s lambda r(...)z'%sz
%s
z
%s
z
%s
%s
)r,rnr-r.rXriscoroutinefunctionisasyncgenfunctiongetattr_staticr[rrrFrDr$rTrsrOrM)r<rr'rrhrirvrurrnoteskipdocsimclassasyncqualifierr;reallinkrrrr?rrrrsp       zHTMLDoc.docroutinecCsNg}|j}|r |d||t||j}|r|d||dd|S)z1Produce html documentation for a data descriptor.z!
%s
z
%s
rrI)r rsrOrMrUr<rr'rrurrr?rrrrHs   zHTMLDoc.docdatacGs|rd|pd}|||S)z-Produce HTML documentation for a data object.z%s = rIr)r<rr'rrlhsrrrrXszHTMLDoc.docothercCsg}|duri}t|gD]\}}}tdd|Drq||d|||vfd||<q||||j}||dd|S)z2Generate an HTML index for a directory of modules.Ncss,|]}dt|kodknVqdS)iiN)ordrchrrr bs*z HTMLDoc.index..rIrQrr)rranyr rrSr^rI)r<rr\rrr'rr<rrrindex]s  z HTMLDoc.indexrI)rCrINr>)rrrNNN)r,r!r"rAr_repr_instancerr$r=rBrHrIrMrSrTrWrXrZr^r_rsrvrrrrrrrrrrrrr87s@      + y# A r8c@s4eZdZdZddZddZddZeZdd Zd S) TextReprzAClass for safely making a text representation of a Python object.cCrrrrrrrrprzTextRepr.__init__cCsTtt|dr ddt|j}t||r t||||Sttt||j Sr') rrCrUr,r#r$rirlrrr)rrrr,vs  zTextRepr.repr1cCsHt||j}t|}d|vr"dt|ddvr"d|d||dS|S)Nrr-rIr.r)rirrrbr/rrrr2}s zTextRepr.repr_stringcCs.z ttt||jWSd|jjYSr3)rirlrrr.r,r4rrrr5szTextRepr.repr_instanceN) r,r!r"rArr,r2r6r5rrrrrns 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.rIcss|] }|d|VqdS)NrrrrrrszTextDoc.bold..)rUr#rrrboldrz TextDoc.bold cs>|sdSfdd|dD}|r|d|d<d|S)z6Indent text by prepending a given prefix to each line.rIcsg|]}|qSrrrrprefixrrrrz"TextDoc.indent..rPr)r#rMrU)r<r`r rVrr rindents zTextDoc.indentcCs$||}||d|dS)z&Format a section with a given heading.rPrJ)rrMr )r<r;r<clean_contentsrrrrHszTextDoc.sectionNrIc sd}|D]I}t|tdur9|\}}||t|}|r4||fkr4fdd|D} |dd| }|d}qt|tgurM|||||d}q|S) zBRender in text a class tree as returned by inspect.getclasstree().rIrc3s|]}t|VqdSrrY)rrzrXrrrz%TextDoc.formattree..rrtrPr )rCrYrUrv) r<rwrXrxr rNryrzr{r|rrrrvs  zTextDoc.formattreec Cs |j}tt|\}}|d||od|}t|dd}||}|dur0||d|d}|r:||d|}g} t|tD]\} } |dusSt | pP||ur`t | ||r`| | | fqBg} t|tj D]!\} } |dus~t | s~t | |urt | ||r| | | fqjg} t|tD]\} } t | ||r| | | fqg}t}t|drt|jD]\}}}|||r| |d q| |q|||d d |}g}t|tjD]\} } | j|d r| |vr| | q|r|||d d |}| rBdd| D}|t|d|g}| D]\} } | || | |q'||dd |}| rdg}| D]\} } | || | |qI||dd |}| rg}| D]\} } | |j| | |ddqk||dd |}t|drt|j}|dddkr|dddkr|dd}||d|}t|dr||dt|j }t|dr||dt|j!}t|d r||d!t|j"}zt#|}Wn t$yd"}Ynw||d#|}|S)$z5Produce text documentation for a given module object.NAME - rNzMODULE 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. DESCRIPTIONr (package)zPACKAGE CONTENTSrPr SUBMODULEScSrrrrrrrrrz%TextDoc.docmodule..rQCLASSES FUNCTIONSF)rfDATArr~rrrVERSIONrDATErAUTHORrCREDITSrFILE)%r,rWrOrHr$r rrprrrr r[r0r_setrrrraddrrUrZrrvrrrrDrrSrrrrrF)r<rr'rsynopdescrNrr rirwrxrhrr modpkgs_namesrrXr submodulesrr<rrrrrrs                  $   zTextDoc.docmodulec sNj}|p|}j}jfdd}||krd|}n |d|}|r6t||} |dd| }g} | jzt} Wn t t fyOd} Ynw| rdt | } | rd| dkrd|| d t } | rp| d t t}t|d krd |D] }d ||qd tddtDt jd}t|}d}|rЈd|d|D]}d |q||kr̈dt ||dd Gfddd}|fdd}fdd}fdd}fddtD}|r|r|n|dd t|fd d!\}}tjur0tjur0|}qur8d"}nd#tj}t||d$||d%d!}|d&||d'd!}|d(||d)d!}|d*||d+d!}|d,||d-d!}|d.||d/d!}|gksJ|}|sd | } | s|d S|d | d0d S)1z4Produce text documentation for a given class object.cSs t||Srr)rzrrrrmakename#rz"TextDoc.docclass..makenameclass z = class rrtNrrPrRzMethod resolution order:r rIcss0|]}|jds|jdkrt|jVqdS)rrN)r,rr!rD)rr&rrrrHs  z#TextDoc.docclass..rrzBuilt-in subclasses:z ... and z other subclassescr)z(TextDoc.docclass..HorizontalRulecSrrrrrrrrZrz1TextDoc.docclass..HorizontalRule.__init__cr)NzF----------------------------------------------------------------------rQrrrrrr\rz.TextDoc.docclass..HorizontalRule.maybeNrrrrrrYrrc st||\}}|r>||D]*\}}}}zt|}Wnty2||Yqw||q|Srrrrrrrr<rrrbs zTextDoc.docclass..spillcrrrrrrrrsrz*TextDoc.docclass..spilldescriptorsc st||\}}|rB||D].\}}}}t|}zt|} Wnty2|j|} Ynwj| |d|ddq|S)Nr)rfr?rP)rrrOr$r:__dict__r) rrr{rr'rrrxr?r;r)rrr|s z#TextDoc.docclass..spilldatacrrrrrrrrrz$TextDoc.docclass..rcrrrrrrrrrz"TextDoc.docclass..rrz Methods %s: cSrrrrrrrrrzClass methods %s: cSrrrrrrrrrzStatic methods %s: cSrrrrrrrrrzReadonly properties %s: cSrrrrrrrrrzData descriptors %s: cSrrrrrrrrrzData and other attributes %s: cSrrrrrrrrrz | )r,rqr!r maprUr rrrrFrDrOrrrTsortedrC__subclasses__r rrrrrrYrrrM)r<rr'rrrr{r'r;r|r<rrr?rr> subclassesno_of_subclassesMAX_SUBCLASSES_TO_DISPLAY subclassnamerrrrrrrr)rrrrr<rrrs                 #zTextDoc.docclasscCsd||Srrr%rrrrzTextDoc.formatvaluec Cs|j}|p|}d}d}t|r7|jj}|r!||ur dt||}n|jdur0dt|jj|}ndt||}t|sAt|rDd} nd} ||krP||} n|r]t ||g|ur]d}||d |} d} t |rzt |} Wn t t fyd} Ynw| rt| } |d kr||d } | dd } | sd } | | | |} |r| dSt|pd}| d|o||dS)z;Produce text documentation for a function or method object.rIrrNrrrrQ = rz lambda rrrP)r,rnr-r.rYrrrr rr[rrrFrDrOrrM)r<rr'rrurrrrrr;rrrr?rrrrsX      zTextDoc.docroutinecCsTg}|j}|r||||dt|pd}|r%||||dd|S)z1Produce text documentation for a data descriptor.rPrI)r r rOrrUrrrrrs  zTextDoc.docdatac Cs||}|r#|r |dpd|}|t|} | dkr#|d| d}|r,||dp-d|}|s6t|}|rE|d|t|d7}|S)z-Produce text documentation for a data object.r3rIrNrdrP)rrTr rOrrD) r<rr'rrxrfr?rrchoprrrrs  zTextDoc.docother)r )NrIrr)NNNNN)r,r!r"rArrrr rrHrvrrrrrrrrrrrrs     e  7rc@seZdZdZddZdS) _PlainTextDocz2Subclass of TextDoc which overrides string stylingcCs|Srrr#rrrr z_PlainTextDoc.boldN)r,r!r"rAr rrrrr5s r5cCstat|dS)zCThe first time this is called, determine what kind of pager to use.N)getpagerpagerrkrrrr8s r8c sdttjdstSttjdstStjrtjstStjdp'tjdrItj dkr5fddStjddvrCfd dSfd dStjddvrStStj dkr\d dSttd rlt d dkrlddSttd r|t ddkr|ddSddl }| \}}t |z ttd rt d|dkrddWt|StWt|St|w)z2Decide what method to use for paging through text.isattyMANPAGERPAGERwin32ctt|Sr tempfilepagerplainrk use_pagerrrr(rzgetpager..TERM)dumbemacscr=r) pipepagerr@rkrArrr*rcs t|SrrFrkrArrr, cSstt|dS)Nzmore rkrrrr0rsystemz(pager) 2>/dev/nullrcS t|dS)Nr8rGrkrrrr2rHz(less) 2>/dev/nullcSrJ)NlessrGrkrrrr4rHNz more "%s"cSrJ)NmorerGrkrrrr;rH)rrstdin plainpagerstdoutr9r rr platformrItempfilemkstempcloseunlinkttypager)rQfdrrrArr7s<          r7cCstdd|S)z%Remove boldface formatting from text.z.rI)rKrLrkrrrr@Ar2r@c Csddl}|j|d|jdd}z&|j}z||Wn ty#YnwWdn1s.wYWn ty=Ynw z|WdStyOYnwq?)z3Page through text by feeding it to another program.rNTbackslashreplace)shellrMerrors) subprocessPopenPIPErMwriteKeyboardInterruptrwait)r`cmdrZprocpiperrrrFEs2    rFc Csddl}|B}tj|d}t|ddtjdkrtdndd }| |Wdn1s2wYt |d|d WddS1sMwYdS) z.cSstjddddS)NrrQ)rrMrrrrrrysLINESrQz -- more --)qQz ) rP)bB)r@rkr#ttyrrMfileno tcgetattr setcbreakrr:ioUnsupportedOperationrgr rr rrOr]rUflush tcsetattr TCSAFLUSH) r`rVrtrVoldgetcharhr.incrzrrrrUnsX             & rUcCstjtt|dS)z>Simply print unformatted text. This is the ultimate fallback.N)rrOr]r@rkrkrrrrNsrNcCst|r|jtjvrd|jSt|drd|jSd|jSt|r)d|jSt|r:d|jj |jj|jfSt |rKd|jj |jj|jfSt |rTd|jSt |r^d |jSt |rhd |jSt|jS) z/Produce a short description of the given thing.zbuilt-in module rzpackage zmodule zbuilt-in function zgetset descriptor %s.%s.%szmember descriptor %s.%s.%sr(z function zmethod )rrZr,rrrr0isgetsetdescriptorr5r!r6rr/r+rC)thingrrrdescribes2                  rc Csdd|dD}d\}}|t|kr3td|d|d|}|r,||d}}nn|t|ks|r8|}nt}||dD]}zt||}Wq@tyTYdSw|S)z@Locate an object by name or dotted path, importing as necessary.cSsg|]}|r|qSrr)rrrrrrrzlocate..rrNrQ)r#rTrrUrr$r:)rrrrn nextmodulerrrrrlocates"   rcCsTt|trt||}|durtd|||fSt|dd}|t|tr'|fSdfS)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,)rrDrrr$)rrrr'rrrresolves   r Python Library Documentation: %scCs|durt}t||\}}t|}t|}|r*d|vr*|d|d|d7}n |r7||ur7|d|j7}t|s_t|s_t |s_t |s_t |s_t |drW|j }nt|}|d7}||d|||S)zBRender text documentation, given an object or a path to an object.Nrz in z in module __origin__z objectrJ)r`rrrrrfindr,rZrr[r4rHrrrCr)rr;rrendererrr'r$rrrr render_docs.     rc Cslz|durtt|||WdS|t|||tWdSttfy5}z t|WYd}~dSd}~ww)zCDisplay text documentation, given an object or a path to an object.N)r8rr] plaintextrrprint)rr;routputrxrrrr?sr?c Csz;t||\}}tt|t||}t|dddd }||Wdn1s-wYtd|dWdStt fyT}z t|WYd}~dSd}~ww)zd?d@DZdAdBdCdDgeRdEdFdGdHdIdJdKZdLdMdNdOdPdQdRdSdTdUdVdWdWdXdXdYZeD]\ZZ e D]Z e e eZ ee vre dZeZ e ee <qqid[d\dSd]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxd[dyd[idzd{dPd|d}d~dddddd#ddddddddddddddddddddddidddddddddddddddddddTdddddldddddddodddidddddddddMdddddddÓddœd+dƓddǓdd ddʓdd̓dddd6dd#ddddddԜZ dddׄZ eddلZeddۄZdd݄ZeZefdd߄ZddZddZddZddZdddZddZddZddZdddZdddZddZdddZ dS)HelperFalserINoneTrueandBOOLEANaswithassert)rrIasync)rrIawait)rrIbreak)r while forclass)rzCLASSES SPECIALMETHODScontinue)rrdef)functionrIdel)r BASICMETHODSelififelse)rrexcepttryfinallyfor)rzbreak continue whilefromimportglobal)rznonlocal NAMESPACES)r TRUTHVALUE)rMODULESin)rSEQUENCEMETHODSis COMPARISONlambda)rrnonlocal)rzglobal NAMESPACESnotorpass)rrIraise)r EXCEPTIONSreturn)rr)rrwhile)rzbreak continue if TRUTHVALUE)rz CONTEXTMANAGERS EXCEPTIONS yieldyield)rrIcCsg|] }dD]}||qqS)'rar)rprnrrrrLrzHelper.)rqfr.urz'''rar)+r***rz//%<<>>r |^~r!r"<=>===!=<>)r!r"rrrrr)rr) z+=z-=z*=z/=z%=z&=z|=z^=z<<=z>>=z**=z//=)rrr rrr)jJ)STRINGS OPERATORSrUNARYAUGMENTEDASSIGNMENTBITWISECOMPLEXzOPERATORS FORMATTINGPOWERzTUPLES LISTS FUNCTIONSz ATTRIBUTES FLOAT MODULES OBJECTSELLIPSISzSLICINGS DICTIONARYLITERALSz def classr PRIVATENAMESzPRIVATENAMES SPECIALMETHODS BACKQUOTESzTUPLES FUNCTIONS CALLSzLISTS SUBSCRIPTS SLICINGS)rr,rrd:@rrr`rbru[]rTYPES)rzRSTRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect)stringsz4str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES STRINGMETHODS)zstring-methodszSTRINGS FORMATTING FORMATTING) formatstringsrUNICODE)rz:encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPESNUMBERS)numberszINTEGER FLOAT COMPLEX TYPESINTEGER)integersz int rangeFLOAT)floatingz float mathr) imaginaryz complex cmath SEQUENCES)typesseqz$STRINGMETHODS FORMATTING range LISTSMAPPINGS DICTIONARIESr)typesfunctionsz def TYPESMETHODS) typesmethodszclass def CLASSES TYPES CODEOBJECTS)zbltin-code-objectszcompile FUNCTIONS TYPES TYPEOBJECTS)zbltin-type-objectsz types TYPES FRAMEOBJECTS TRACEBACKSNONE)zbltin-null-objectrI)zbltin-ellipsis-objectSLICINGSSPECIALATTRIBUTES) specialattrsrIr)rz!class SPECIALMETHODS PRIVATENAMESr) typesmodulesrPACKAGES EXPRESSIONS)zoperator-summaryzlambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIESr PRECEDENCEOBJECTS)objectsrSPECIALMETHODS) specialnameszbBASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS MAPPINGMETHODS NUMBERMETHODS CLASSESr) customizationzhash repr str SPECIALMETHODSATTRIBUTEMETHODS)zattribute-accesszATTRIBUTES SPECIALMETHODSCALLABLEMETHODS)zcallable-typeszCALLS SPECIALMETHODSr)sequence-typesz(SEQUENCES SEQUENCEMETHODS SPECIALMETHODSMAPPINGMETHODS)rzMAPPINGS SPECIALMETHODS NUMBERMETHODS)z numeric-typesz*NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS EXECUTION) execmodelz%NAMESPACES DYNAMICFEATURES EXCEPTIONS NAMESPACES)namingz3global nonlocal ASSIGNMENT DELETION DYNAMICFEATURESDYNAMICFEATURES)zdynamic-featuresrISCOPINGFRAMESr)rztry except finally raise CONVERSIONS) conversionsrI IDENTIFIERS) identifierszkeywords SPECIALIDENTIFIERSSPECIALIDENTIFIERS)z id-classesrI)zatom-identifiersrILITERALS)z atom-literalsz=STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALSTUPLES TUPLELITERALS) exprlistszTUPLES LITERALSLISTS)ztypesseq-mutable LISTLITERALSr$)listszLISTS LITERALS) typesmappingDICTIONARYLITERALSr')r7zDICTIONARIES LITERALS ATTRIBUTES)zattribute-referencesz(getattr hasattr setattr ATTRIBUTEMETHODS SUBSCRIPTS) subscriptionsrr)slicingsrCALLS)callsr)powerrr)unaryrBINARY)binaryrSHIFTING)shiftingrr)bitwiser) comparisonszEXPRESSIONS BASICMETHODS)booleanszEXPRESSIONS TRUTHVALUE ASSERTION ASSIGNMENT) assignmentrr) augassignrDELETION RETURNING IMPORTING)compoundzfor while break continue)truthz if while and or not BASICMETHODS)debuggerpdb)zcontext-managersr) CONDITIONALLOOPINGr DEBUGGINGCONTEXTMANAGERSNcCs||_||_dSr)_input_output)r<inputrrrrrs zHelper.__init__cC |jptjSr)rFrrMrrrrrHr`z Helper.inputcCrIr)rGrrOrrrrrr`z Helper.outputcCs2tdddkr|dSd|jj|jjfS)NrQrc?rIz<%s.%s instance>)rstackr.r!r"rrrr__repr__s zHelper.__repr__cCs8||jur ||dS|||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__s zHelper.__call__c Cs|jd z |d}|sWdSWn ttfyYdSw|}t|dkrJ|d|dkr8dvrJnn|d|ddvrJ|dd}|d vrRdS|d kr[|n| |q) NrPTzhelp> rRrrrrQ)rnquitr) rr]getliner^EOFErrorrSrTr rNrrPrrrrOs"  ,   zHelper.interactcCs4|jtjur t|S|j||j|jS)z.Read one line, using input() when appropriate.)rHrrMrr]rzr)r<promptrrrrTs    zHelper.getlinecCs8t|tdur|}|dkr|n|dkr|nv|dkr'|nm|dkr0|nd|dddkrB||dnR||jvrM||nG|d vrYt t |d n;||j vrd| |n0||j vro| |n%|rzt |d |jd nt td |jd nt|tr|nt |d |jd |jd dS) NrIkeywordssymbolstopicsrzmodules rQ)rrrz Help on %s:)rrP)rCrS listkeywords listsymbols listtopics listmodulesr#rX showsymbolr?evalrW showtopicrYrGrDrrrr]rPrrrrs$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.%drR)rr]r rrrrrrrNsz Helper.introrPc Cstt|}||}t||d|}t|D];}t|D].}|||}|t|krL|j||||dkrL|jdd|dt||q|jdqdS)NrQrrP)rOr,rTrNrr]) r<itemscolumnsrDcolwrQrowrRrrrrrO,s      $z Helper.listcC |jd||jdS)NzN Here is a list of the Python keywords. Enter any keyword to get more help. )rr]rOrWrtrrrrr[9 zHelper.listkeywordscCrg)Nzx Here is a list of the punctuation symbols which Python assigns special meaning to. Enter any symbol to get more help. )rr]rOrXrtrrrrr\@s zHelper.listsymbolscCrg)NzN Here is a list of available topics. Enter any topic name to get more help. )rr]rOrYrtrrrrr]HrhzHelper.listtopicsc Cs*zddl}Wnty|jdYdSw|j||j|}|s0|jdt|dSt|tdur>| ||S|\}}z|jj|}Wnt y^|jdt|YdSw| d}|ro|pjdd|}|rddl }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 rIrPrRelated help topics: rtHz %s )pydoc_data.topicsrrr]rYr rWrrCraKeyErrorrStextwraprUr#wrapr8) r<topic more_xrefs pydoc_datatargetlabelxrefsr?rnr` wrapped_textrrrraOs8        zHelper.showtopiccCszddl}Wn tyYdSw|j||j|}|s"tdt|tr-|||S|\}}|jj|}|rA|p.callbackcsd|ddSrrrr}rronerrorsz#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". )rr]r apropos ModuleScannerrunrOrt)r<rwrrrr~rr^s    zHelper.listmodulesr)rrbr)!r,r!r"rW _strprefixes_symbols_inverserXrcrpsymbols_ryr rYrr1rHrrLrrMrRrOrTrrNrOr[r\r]rarwr_r^rrrrrs       !"#'          !"%&'(*+-./012345679:;<=>?@ABCDEFGHIJKLMNOP W         rc@seZdZdZdddZdS)rz7An interruptible scanner that searches module synopses.Nc Cs|r|}d|_i}tjD]8}|dkrFd||<|dur#|d|dqt|jp)d}|dd}|d|}||dkrF|d||qtj |dD]\} }} |jrWn|durb|d|dqMzt | |} Wn t ysYqMw| j } t | d rz| |} Wnty|r||YqMwtt| pd}t | d r| |}n-d}n*ztj| }Wnty|r||YqMw|jr|jdnd}t|d d}|d|}||dkr||||qM|r|dSdS) NF__main__rQrIrPrrr get_source get_filenamer)r rSrrrrAr#r|rr _get_specrrrrrrrxStringIOrrrrrrr$)r<r}rw completerrseenrXr'r$rrrrsourcerrrrrrsj              zModuleScanner.runr)r,r!r"rArrrrrrsrcCsZdd}dd}ttdtj|||dWddS1s&wYdS)zAPrint all the one-line module summaries that contain a substring.cSs6|dddkr|ddd}t||od|dSNrzr{rz- )rrrXr$rrrr}szapropos..callbackcSdSrrrrrrrr6zapropos..onerrorignorerN)warningscatch_warningsfilterwarningsrr)rwr}rrrrrs   "rcsddlddlddlddlGdddjjGfdddjjGfdddj}||||}||j sP|j sPt d |j sP|j rE|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|jdr d}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-8rhN) rr send_response send_header end_headerswfiler] urlhandlerri)r< content_typerrrdo_GET7 s   z(_start_server..DocHandler.do_GETcWrrr)r<rrrr log_messageG sz-_start_server..DocHandler.log_messageN)r,r!r"rrrrrr DocHandler5 s rcs(eZdZddZfddZddZdS)z _start_server..DocServercSs6||_|j|f|_||_|j||j|jd|_dSNF)hostaddressr}r>rhandlerrS)r<rportr}rrrrM s   z)_start_server..DocServer.__init__csB|js|jgggd\}}}|r||jr|dSro)rSselectsocketruhandle_request server_close)r<rdwrexrrrserve_until_quitT s  z1_start_server..DocServer.serve_until_quitcSs$|j||jr||dSdSr)r>server_activater}rrrrr[ s z0_start_server..DocServer.server_activateN)r,r!r"rrrrrrr DocServerK s  rcs:eZdZfddZfddZddZddZd S) z#_start_server..ServerThreadcs2||_||_t||_j|d|_d|_dSr)rrrgrThreadrservingerror)r<rrr) threadingrrrb s    z,_start_server..ServerThread.__init__c szz&jj__jj_t|j_|j |j |j }||_ | WdSty<}z ||_WYd}~dSd}~ww)zStart the server.N)server HTTPServerr>rrMessage MessageClass staticmethodrrrready docserverrrr)r<docsvre)rremailhttprrrj s   z'_start_server..ServerThread.runcSs,d|_|j|_|j|_d|j|jf|_dS)NTz http://%s:%d/)rr server_portrr])r<rrrrrw sz)_start_server..ServerThread.readycSs&d|j_|d|_d|_d|_dS)z&Stop the server and this thread nicelyTNF)rrSrUrr]rrrrstop} s  z(_start_server..ServerThread.stopN)r,r!r"rrrrr)rrrrrrr ServerThread` s   rg{Gz?) http.server email.messagerrrBaseHTTPRequestHandlerrrrmrrtimesleep)rhostnamerrthreadr)rrrrrrr _start_servers8 '   rrcs,Gfdddt}|fddfddfddfd d fd d fd dfddfddfdd}|drU|dd}|dkrtjtjt}tj||}t|}d| WdS1swYn|dkr||St d||f)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)r:zpydoc_data/_pydoc.cssz1a  Pydoc: %s %s%s
%s
r)r<r;r<css_pathcss_link html_navbarrrr= s z#_url_handler.._HTMLDoc.pageN)r,r!r"r=rrrr_HTMLDoc srcs>dttdtf}d|tjddfS)Nz %s [%s, %s]raZ
Python %s
%s
T)terse)r$rPpython_version python_buildpython_compiler)rrrrr s  z!_url_handler..html_navbarcsdd}ddd}ddtjD}||}|dd dd |g}i}tjD] }|||q*|d d d |fS)zModule Index page.cS d||fSNrYrr'rrr bltinlink r&z3_url_handler..html_index..bltinlinkz7Index of ModulesrrcSsg|]}|dkr|qS)rr)rr'rrrr sz4_url_handler..html_index..z

zBuilt-in Modulesrz|

pydoc by Ka-Ping Yee<ping@lfw.org>zIndex of ModulesrI) rBrrrSrIrr rrU)rrBnamesr<rrrrr html_index s"  z _url_handler..html_indexc sgfdd}ttddd}tj|||dWdn1s)wYdd }g}d d d }D] \}}||||q=|d |d dd|}d|fS)zSearch results page.cs:|dddkr|ddd}||od|fdSrryr search_resultrrr} sz3_url_handler..html_search..callbackrcSrrrrrrrr r6z2_url_handler..html_search..onerrorrNcSrrrrrrrr r&z4_url_handler..html_search..bltinlinkz5Search Resultsrrzkey = %sr
zSearch Results) rrrrrrBr rIrU) rwr}rrrrBr'r$r<rrr html_search s&    z!_url_handler..html_searchcsLdd}ddd}ttj}||}|ddd|}d|fS)zIndex of topic texts available.cSrNz%srrrrrr r&z4_url_handler..html_topics..bltinlink,INDEXrrTopicsr)rBr,rrYrtrSrI)rrBrr<rrr html_topics s z!_url_handler..html_topicscsLddd}ttj}dd}||}|ddd|}d|fS)zIndex of keywords.rrrcSrrrrrrrr r&z6_url_handler..html_keywords..bltinlinkKeywordsr)rBr,rrWrtrSrI)rBrrr<rrr html_keywords s z#_url_handler..html_keywordscst}t||}||\}}||jvrd}nd}d|dd}d|}|dd|}|rLt| }dd } ||} d dd|}d ||fd |||ffS) zTopic or keyword help page.KEYWORDTOPICr}rrz

%s
rcSrrrrrrrr- r&z7_url_handler..html_topicpage..bltinlinkrjz%s %srI) rxrrrwrWrBrsrIr,r#rSrHrU)rpbufhtmlhelpr<rur;rBrrrrhtml_topicpage s,     z$_url_handler..html_topicpagecs@t|dd}|dur|dkrtdt|}||}||fS)NrQ)rrzcould not find object)rrrr)r]r;r;contentrrr html_getobj6 s  z!_url_handler..html_getobjcsPddd}dfddtt||D}||dd|}d||fS) Nz,Errorrrrc3s|]}|VqdSr)r$r rrrrB rz3_url_handler..html_error..z#bb0000z Error - %s)rBrUrrCrI)r]rrBr<rrr html_error> s   z _url_handler..html_errorc s`|}|dr |dd}z|dvr\}}nw|dkr"\}}nm|dkr,\}}ncd|vr|d\}}}|dkrC|\}}nL|d kr_z|\}}Wn?ty^|\}}Yn1w|d kr|dvrm\}}n"z|\}}Wnty|\}}Yn wtd |\}}Wnty}z ||\}}WYd}~nd}~ww||S) zGenerate an HTML page for url.rN)rIrrYrWrz search?keyz topic?keyzget?keyz bad pydoc url)rrxrrr=)r] complete_urlr;roprr)rrrrrrrrrr get_html_pageH sH          z#_url_handler..get_html_pagerrQNrrIrz"unknown content type %r for url %s) r8rr rdirnamerealpathrrUr readlinesrF)r]rrr path_hererfpr) rrrrrrrrrr _url_handler s,          (   "rT localhost) open_browserrc Csddl}tt||}|jrt|jdS|jr|d}|r!||jzMz.td|jt||jrOtd}| }|dkr=n|dkrH||jnt||js0Wnt t fy^tYnwW|jrm| tddSdS|jr{| tdwwdS) 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> rnrqzServer stopped) webbrowserrrrrrrr]rHr r^rUr)rrrr serverthreadserver_help_msgr`rrrbrowse} sD        rcCst|to |tjdkSr)rrDr|r sep)r~rrrispath srcCsvd|vstj|vst|vrdStjt}tj|}|}||vr1tj||s1||| 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. rINr) r curdirgetcwdrrrcopysamefileremoveinsert) given_pathargv0 stdlib_dir script_dir revised_pathrrr_get_revised_path s    r cCs0ttjtjd}|dur|tjdd<dSdS)zEnsures current directory is on sys.path, and __main__ directory is not. Exception: __main__ dir is left alone if it's also pydoc's directory. rN)r rrargv)r rrr_adjust_cli_sys_path sr c Csddl}Gdddt}tz|tjddd\}}d}d}d}d}d}|D].\} } | d kr5d }d }| d krAt| WdS| d krId }| }| d krOd }| dkrWd }| }q)|rdt|||dWdS|sh||D]W} t| rtj | st d| WdSz+t| rtj | rt | } |rt| rtj | rt| n t| nt| Wqjty} z t | WYd} ~ qjd} ~ wwWdS|j|fytj tj tjdd} t dj| tjdYdSw)z@Command-line interface (looks at sys.argv to decide what to do).rNc@s eZdZdS)zcli..BadUsageN)r,r!r"rrrrBadUsage rrrQzbk: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. )r`r)getoptrr rr rrrr rexistsrrrr rrrrrrrr r)rroptsrwriting start_serverrrroptvalargrxr`rrrcli sl     rrr)r)rrN)rIN)r)`rArrrrrimportlib._bootstraprimportlib._bootstrap_externalimportlib.machineryimportlib.utilrrxr rrPrKrrrrr urllib.parserr collectionsrreprlibr tracebackrrrr(r@r9rHrOrWrYr_rbrirc IGNORECASErjrlrnrsrrrrrrrrrrrrrr8rrr5r8r7r@rFr?rkrUrNrrr`rrrrr?rrrrrrrrrrr r rr,rrrrs*      3     ' 0;*; $ ,    = n% U