B ç0œ`C]ã@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 CsR|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<|dkr|  9¡}t:|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ÚTextÚ splitlinesrÚ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©r[ú/private/var/folders/sf/wxz_36012wxg_prv29r6623x5vlqx8/T/pip-target-tft40_m7/lib/python/docutils/parsers/rst/directives/misc.pyrQ5sº     "$ $                     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__r2rQr[r[r[r\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) rRÚ attributesrrTrXrSr+Zraw_filerJr ÚurllibZraw_textZraw_noder[r[r\rQ·sx          $ $   , $ zRaw.runN)r]r^r_r`rarbrcr r+ÚurirrgÚ has_contentrQr[r[r[r\ri¤s  ric@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 ÚSubstitutionDefrJrrxr1rprÚElementÚ nested_parserOZ paragraphZsystem_messageÚappendr(Úreporterr)Úchildren)rRrXÚelementÚnodeÚmessagesÚelemr[r[r\rQs.       z Replace.runN)r]r^r_r}rQr[r[r[r\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 Cst|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  ¡}xj|D]b}yt |¡}Wn8tk rÞ}z| d|t|ƒf¡‚Wdd}~XYnX|t  t |¡|¡7}q”W|jS)NzVInvalid context: the "%s" directive can only be used within a substitution definition.r‹rrŒrrzInvalid character code: %s %s)rr#r r€rJrr(r‡r5rzÚcomment_patternror.rrr Z unicode_coderIrrLrÚunescaper…)rRZsubstitution_definitionÚcodesr†rÚdecodedrJr[r[r\rQ1s,         "z Unicode.runN)r]r^r_r`rarbrcr rdrgÚreÚcompilerŽrQr[r[r[r\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!)rÚ directive)r rfr.rIrJrrprrr#r‚rOÚextendr…ÚpendingrZClassAttributerPr(r$Z note_pendingrƒ)rRZ class_valueZ node_listÚ containerr‡r—r[r[r\rQWs*   z Class.runN) r]r^r_r`rarbrcr}rQr[r[r[r\r”Js 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.)rOr)rprJrÚargument_patternÚmatchÚgroupr Úroler(Úlanguager#r„rrFrPZgeneric_custom_roleÚhasattrÚAssertionErrorr Zparse_directive_blockr Z MarkupErrorr rfrIrZ CustomRoleZregister_local_role)rRÚargsrZ new_role_nameZbase_role_namerˆZ base_rolerJZconverted_roler.r5rprOZdetailrŸr[r[r\rQws`             zRole.runN) r]r^r_r}r’r“r ZInlinerZ simplenamerœrQr[r[r[r\r™psr™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(r r)r#r„rJrrFrP)rRZ role_namerŸrˆrJr[r[r\rQ´s      zDefaultRole.runN)r]r^r_r`rbrcrQr[r[r[r\r¤­sr¤c@s eZdZdZdZdZdd„ZdS)ÚTitlerrTcCs|jd|jjd<gS)NrÚtitle)r.r(r$)rRr[r[r\rQÍsz Title.runN)r]r^r_rarbrcrQr[r[r[r\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".)rr#r r€rJrr1rpÚsysÚ version_infoÚencoderr=r'ÚtimeÚstrftimeÚdecodeÚUnicodeDecodeErrorrrL)rRZ format_strrXr[r[r\rQÖs(    zDate.runN)r]r^r_r}rQr[r[r[r\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) rpr1r(r„Úinforr.r5rrFr))rRrXr²r[r[r\rQ s  zTestDirective.runN) r]r^r_r`rbrcr rergr}rQr[r[r[r\r°s  r°)'r`Z __docformat__r©Úos.pathr*r’r¬ZdocutilsrrrrZdocutils.utils.error_reportingrrrZdocutils.parsers.rstr r r r r Z$docutils.parsers.rst.directives.bodyrrZdocutils.parsers.rst.rolesrZdocutils.transformsrrrir~rŠr”r™r¤r¥r§r°r[r[r[r\Ús0   Z ,&= .