B “äî\Í\ã@sLdZdZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z mZddl mZddlmZmZddlmZmZmZdd lmZmZdd lmZdd lmZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„deƒZ"Gdd„deƒZ#Gdd„deƒZ$Gdd„deƒZ%Gdd„deƒZ&dS) zMiscellaneous directives.ZreStructuredTextéN)ÚioÚnodesÚ statemachineÚutils)Ú SafeStringÚ ErrorString)Úlocale_encoding)Ú DirectiveÚconvert_directive_function)Ú directivesÚrolesÚstates)Ú CodeBlockÚ NumberLines)Ú set_classes)Úmiscc @sheZdZdZdZdZdZejej ej e e e ej ej ej ej ej dœ Zej ej ej¡d¡Zdd„Zd S) ÚIncludea] Include content read from a separate source file. Content may be parsed by the parser, or included as a literal block. The encoding of the included file can be specified. Only a part of the given file argument may be included by specifying start and end line or text to match before and/or after the text to be used. érT) ÚliteralÚcodeÚencodingz tab-widthz start-linezend-linez start-afterz end-beforez number-linesÚclassÚnameÚincludec Cs@|jjjjs| d|j¡‚|jj |j |jj d¡}t j   t j  |¡¡}t  |jd¡}| d¡rˆ| d¡rˆt j  |j|dd…¡}t j  t j  ||¡¡}t d|¡}t |¡}|j d|jjjj¡}|jjjj}|j d |jjjj¡}y&|jjjj  |¡t!j"|||d }Wnvt#k rN}z| $d |jt%|ƒf¡‚Wdd}~XYn<t&k rˆ}z| $d |jt'|ƒf¡‚Wdd}~XYnX|j d d¡} |j dd¡} y8| s¸| dk rÔ| (¡} d | | | …¡} n| )¡} Wn<t*k r}z| $d|jt'|ƒf¡‚Wdd}~XYnX|j dd¡} | rh|  +| ¡}|dkrT| $d|j¡‚| |t,| ƒd…} |j dd¡}|r¬|  +|¡}|dkr | $d|j¡‚| d|…} t-j.| |dd}d|jkrà|dkrÞ|  /|¡}n| }tj0| ||j dg¡d}d|_1| 2|¡d|jkrÊyt3|jdp*dƒ} Wn t4k rP| 5d¡‚YnX| t,|ƒ} | d¡rv|dd…}t6g|fg| | ƒ}xP|D]6\}}|r²|tj7|||d7}n|t 8||¡7}qŽWn|t 8||¡7}|gSd|jkr.||jd<t9|j|j :d¡g|j||j |j;|j<|j|jƒ }| =¡S|j >||¡gS) z8Include a file as part of the content of this reST file.z"%s" directive disabled.rrú<ú>éÿÿÿÿNrz tab-width)Ú source_pathrÚ error_handlerzVProblems with "%s" directive path: Cannot encode input file path "%s" (wrong locale?).z&Problems with "%s" directive path: %s.z start-linezend-lineÚzProblem with "%s" directive: %sz start-afterzDProblem with "start-after" option of "%s" directive: Text not found.z end-beforezCProblem with "end-before" option of "%s" directive: Text not found.T)Zconvert_whitespacerr)ÚsourceÚclassesz number-linesz+:number-lines: with non-integer start valueÚ )r!rr )?ÚstateÚdocumentÚsettingsÚfile_insertion_enabledÚwarningrÚ state_machineZ input_linesr ÚlinenoZ input_offsetÚosÚpathÚdirnameÚabspathr Ú argumentsÚ startswithÚendswithÚjoinÚstandard_include_pathÚnormpathrÚ relative_pathrZ reprunicodeÚoptionsÚgetÚinput_encodingÚinput_encoding_error_handlerÚ tab_widthÚrecord_dependenciesÚaddrÚ FileInputÚUnicodeEncodeErrorÚsevererÚIOErrorrÚ readlinesÚreadÚ UnicodeErrorÚfindÚlenrZ string2linesÚ expandtabsÚ literal_blockÚlineZadd_nameÚintÚ ValueErrorÚerrorrÚinlineÚTextrÚpopÚcontent_offsetÚ block_textÚrunZ insert_input)Úselfr Ú source_dirr+rÚ e_handlerr9Z include_filerJÚ startlineÚendlineÚlinesZrawtextZ after_textZ after_indexZ before_textZ before_indexZ include_linesÚtextrFÚtokensr!ÚvalueZ codeblock©rZúH/tmp/pip-build-uw_ogi45/docutils/docutils/parsers/rst/directives/misc.pyrP5s¶     "$ $                    z Include.runN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Úrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespacer ÚflagZ unchangedrrHÚunchanged_requiredÚ class_optionÚ option_specr*r+r1r,r Ú__file__r2rPrZrZrZr[rs$  rc@s:eZdZdZdZdZdZejej ej dœZ dZ dd„Z dS) ÚRawzÉ Pass through content unchanged Content is included in output based on type argument Content may be included inline (content section of directive) or imported from a file or url. rrT)ÚfileÚurlrc Cs|jjjjr,|jjjjsrrArBÚurllib.requestÚ urllib.errorÚ urllib.parseÚrequestÚurlopenÚURLErrorÚOSErrorZ StringInputÚassert_has_contentrÚrawr(Zget_source_and_liner)r rG) rQÚ attributesrrSrWrRr+Zraw_filerJr ÚurllibZraw_textZraw_noderZrZr[rP´sx          $ $   , $ zRaw.runN)r\r]r^r_r`rarbr r+ÚurirrfÚ has_contentrPrZrZrZr[rh¡s  rhc@seZdZdZdd„ZdS)ÚReplaceTcCsÊt|jtjƒs| d|j¡‚| ¡d |j¡}t   |¡}|j  |j|j |¡d}g}x^|D]V}|sxt|t j ƒrx|}q^t|t jƒr˜g|d<| |¡q^|jjjd|j|jdgSq^W|rÆ||jS|S)NzVInvalid context: the "%s" directive can only be used within a substitution definition.r"Zbackrefsz=Error in "%s" directive: may contain a single paragraph only.)rG)Ú isinstancer#r ÚSubstitutionDefrJrrwr1rorÚElementÚ nested_parserNZ paragraphZsystem_messageÚappendr(Úreporterr)Úchildren)rQrWÚelementÚnodeÚmessagesÚelemrZrZr[rPÿs.       z Replace.runN)r\r]r^r|rPrZrZrZr[r}ûsr}c@s@eZdZdZdZdZdZejejejdœZ e   d¡Z dd„Z d S) ÚUnicodea{ Convert Unicode character codes (numbers) to characters. Codes may be decimal numbers, hexadecimal numbers (prefixed by ``0x``, ``x``, ``\x``, ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style numeric character entities (e.g. ``☮``). Text following ".." is a comment and is ignored. Spaces are ignored, and any other text remains as-is. rrT)ÚtrimÚltrimÚrtrimz ( |\n|^)\.\. c Csøt|jtjƒs| d|j¡‚|jj}d|jkrDd|j d<d|j d<d|jkrXd|j d<d|jkrld|j d<|j   |j d¡d  ¡}t  ¡}xb|D]Z}yt |¡}Wn8tk rÞ}z| d|t|ƒf¡‚Wdd}~XYnX|t  |¡7}q”W|jS)NzVInvalid context: the "%s" directive can only be used within a substitution definition.rŠrr‹rŒrzInvalid character code: %s %s)r~r#r rrJrr(r†r5ryÚcomment_patternrnr.rr€r Z unicode_coderIrrLr„)rQZsubstitution_definitionÚcodesr…rÚdecodedrJrZrZr[rP.s,         "z Unicode.runN)r\r]r^r_r`rarbr rcrfÚreÚcompilerrPrZrZrZr[r‰s  r‰c@s(eZdZdZdZdZdZdZdd„ZdS)ÚClassz¿ Set a "class" attribute on the directive content or the next element. When applied to the next element, a "pending" element is inserted, and a transform does the work later. rrTc CsÊyt |jd¡}Wn.tk rB| d|j|jdf¡‚YnXg}|jr”t ¡}|j   |j|j |¡x|D]}|d  |¡qpW|  |j ¡n2t tj||jdœ|j¡}|jj |¡| |¡|S)Nrz7Invalid class attribute value for "%s" directive: "%s".r!)rZ directive)r rer.rIrJrrorr€r#rrNÚextendr„ÚpendingrZClassAttributerOr(r$Z note_pendingr‚)rQZ class_valueZ node_listÚ containerr†r”rZrZr[rPTs*   z Class.runN) r\r]r^r_r`rarbr|rPrZrZrZr[r’Gs r’c@s0eZdZdZe dejjfd¡Z dd„Z dS)ÚRoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$éc Cs |j|jks|js"| d|j¡‚|jd}|j |¡}|sP| d|j|f¡‚| d¡}| d¡}g}|rÄt  ||j j |j|j j ¡\}}|dkrÊ|j j jd|t |j|j¡|jd}||gSntj}t|d ƒrætd |j|fƒ‚y4t|ƒ}|j j|jdd…|j|id \} } } } WnXtjk rr} z6|j j jd |j| ft |j|j¡|jd}||gSd} ~ XYnXd | krìyt |¡| d <WnZtk rê} z:|j j jd|jt| ƒft |j|j¡|jd}||gSd} ~ XYnXt ||| | ¡}t ||¡|S)z?Dynamically create and register a custom interpreted text role.z4"%s" directive requires arguments on the first line.rz4"%s" directive arguments not valid role names: "%s".réNz#Unknown interpreted text role "%s".)rGr.z[Supplemental directive arguments for "%s" directive not supported (specified by "%r" role).)Zoption_presetszError in "%s" directive: %s.rz(Invalid argument for "%s" directive: %s.)rNr)rorJrÚargument_patternÚmatchÚgroupr Úroler(Úlanguager#rƒrrFrOZgeneric_custom_roleÚhasattrÚAssertionErrorr Zparse_directive_blockr Z MarkupErrorr rerIrZ CustomRoleZregister_local_role)rQÚargsršZ new_role_nameZbase_role_namer‡Z base_rolerJZconverted_roler.r5rorNZdetailrœrZrZr[rPts`             zRole.runN) r\r]r^r|rr‘r ZInlinerZ simplenamer™rPrZrZrZr[r–msr–c@s eZdZdZdZdZdd„ZdS)Ú DefaultRolez&Set the default interpreted text role.rFcCsŠ|jsdtjkrtjd=gS|jd}t ||jj|j|jj¡\}}|dkr||jjj d|t   |j |j ¡|jd}||gS|tjd<|S)Nrrz#Unknown interpreted text role "%s".)rG) r.r Z_rolesrœr(rr)r#rƒrJrrFrO)rQZ role_namerœr‡rJrZrZr[rP±s      zDefaultRole.runN)r\r]r^r_rarbrPrZrZrZr[r¡ªsr¡c@s eZdZdZdZdZdd„ZdS)ÚTitlerrTcCs|jd|jjd<gS)NrÚtitle)r.r(r$)rQrZrZr[rPËsz Title.runN)r\r]r^r`rarbrPrZrZrZr[r¢Åsr¢c@seZdZdZdd„ZdS)ÚDateTcCsØt|jtjƒs| d|j¡‚d |j¡p,d}tj dkrny|  t pDd¡}Wn"t k rl|  dt ¡‚YnXt |¡}tj dkrÌy| t pŽd¡}Wn6tk rÊ| t p®dd¡}|  d|t f¡‚YnXt |¡gS) NzVInvalid context: the "%s" directive can only be used within a substitution definition.r"z%Y-%m-%d)r˜rzutf-8z;Cannot encode date format string with locale encoding "%s".Úreplacez-Error decoding "%s"with locale encoding "%s".)r~r#r rrJrr1roÚsysÚ version_infoÚencoderr=r'ÚtimeÚstrftimeÚdecodeÚUnicodeDecodeErrorrrL)rQZ format_strrWrZrZr[rPÔs(    zDate.runN)r\r]r^r|rPrZrZrZr[r¤Ðsr¤c@s.eZdZdZdZdZdejiZdZ dd„Z dS)Ú TestDirectivez3This directive is useful only for testing purposes.rTÚoptioncCsl|jrBd |j¡}|jjjd|j|j|jft  ||¡|j d}n$|jjjd|j|j|jf|j d}|gS)Nr"zBDirective processed. Type="%s", arguments=%r, options=%r, content:)rGzGDirective processed. Type="%s", arguments=%r, options=%r, content: None) ror1r(rƒÚinforr.r5rrFr))rQrWr¯rZrZr[rPs  zTestDirective.runN) r\r]r^r_rarbr rdrfr|rPrZrZrZr[r­þs  r­)'r_Z __docformat__r¦Úos.pathr*rr©ZdocutilsrrrrZdocutils.utils.error_reportingrrrZdocutils.parsers.rstr r r r r Z$docutils.parsers.rst.directives.bodyrrZdocutils.parsers.rst.rolesrZdocutils.transformsrrrhr}r‰r’r–r¡r¢r¤r­rZrZrZr[Ús0    Z ,&= .