U n^C]@sLdZdZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z mZddl mZddlmZmZddlmZmZmZdd lmZmZdd lmZdd lmZGd d d eZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#GdddeZ$GdddeZ%GdddeZ&dS) zMiscellaneous directives.ZreStructuredTextN)ionodes statemachineutils) SafeString ErrorString)locale_encoding) Directiveconvert_directive_function) directivesrolesstates) CodeBlock NumberLines) set_classes)miscc @sheZdZdZdZdZdZejej ej e e e ej ej ej ej ej d ZejejejdZddZd 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) literalcodeencoding tab-width start-lineend-line start-after end-before number-linesclassnameincludec CsN|jjjjs|d|j|jj|j |jj d}t j t j |}t |jd}|dr|drt j |j|dd}t j t j ||}td|}t|}|jd|jjjj}|jjjj}|jd |jjjj}z&|jjjj |t!j"|||d }Wnvt#k rN}z|$d |jt%|fW5d}~XYn<t&k r}z|$d |jt'|fW5d}~XYnX|jd d} |jdd} z8| s| dk r|(} d| | | } n|)} Wn<t*k r}z|$d|jt'|fW5d}~XYnX|jdd} | rh| +| }|dkrT|$d|j| |t,| d} |jdd}|r| +|}|dkr|$d|j| d|} t-j.| |dd}d|jkr|dkr| /|}n| }tj0| ||jdgd}d|_1|2|d|jkrzt3|jdp*d} Wn t4k rP|5dYnX| t,|} |drv|dd}t6g|fg| | }|D]6\}}|r|tj7|||d7}n|t8||7}qn|t8||7}|gSd|jkr<||jd<|dkr| 9}t:|j|j;dg|j||j |j<|j=|j|j }|>S|j?||gS) z8Include a file as part of the content of this reST file."%s" directive disabled.rr<>Nrr source_pathr error_handlerzVProblems with "%s" directive path: Cannot encode input file path "%s" (wrong locale?).&Problems with "%s" directive path: %s.rrProblem with "%s" directive: %srzDProblem with "start-after" option of "%s" directive: Text not found.rzCProblem with "end-before" option of "%s" directive: Text not found.T)Zconvert_whitespacerr)sourceclassesrz+:number-lines: with non-integer start value )r+rr*)@statedocumentsettingsfile_insertion_enabledwarningr state_machineZ input_linesr*linenoZ input_offsetospathdirnameabspathr arguments startswithendswithjoinstandard_include_pathnormpathr relative_pathrZ reprunicodeoptionsgetinput_encodinginput_encoding_error_handler tab_widthrecord_dependenciesaddr FileInputUnicodeEncodeErrorsevererIOErrorr readlinesread UnicodeErrorfindlenrZ string2lines expandtabs literal_blocklineZadd_nameint ValueErrorerrorrinlineText splitlinesrpopcontent_offset block_textrunZ insert_input)selfr* source_dirr5r e_handlerrCZ include_filerT startlineendlinelinesZrawtextZ after_textZ after_indexZ before_textZ before_indexZ include_linestextrPtokensr+valueZ codeblockre~/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/docutils/docutils/parsers/rst/directives/misc.pyr[5s                                 z Include.runN)__name__ __module__ __qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer flagZ unchangedrrRunchanged_required class_option option_specr4r5r;r6r __file__r<r[rerererfrs(  rc@s:eZdZdZdZdZdZejej ej dZ dZ ddZ 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)fileurlrc Cs|jjjjr,|jjjjsrrFrDrErIrHrrKrLurllib.request urllib.error urllib.parserequesturlopenURLErrorOSErrorZ StringInputassert_has_contentrrawr2Zget_source_and_liner3r*rQ) r\ attributesrr^rbr]r5Zraw_filerTr*urllibZraw_textZraw_noderererfr[s                 zRaw.runN)rgrhrirjrkrlrmr r5urirrq has_contentr[rerererfrss rsc@seZdZdZddZdS)ReplaceTcCst|jtjs|d|j|d|j}t |}|j |j|j |d}g}|D]Z}|svt|t j rv|}q\t|t jrg|d<||q\|jjjd|j|jdgSq\|r||jS|S)NVInvalid context: the "%s" directive can only be used within a substitution definition.r,Zbackrefsz=Error in "%s" directive: may contain a single paragraph only.rQ) isinstancer-r SubstitutionDefrTrrr;rzrElement nested_parserYZ paragraphZsystem_messageappendr2reporterr3children)r\rbelementnodemessageselemrererfr[s<      z Replace.runNrgrhrirr[rerererfrsrc@s@eZdZdZdZdZdZejejejdZ e dZ ddZ 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)trimltrimrtrimz ( |\n|^)\.\. c Cst|jtjs|d|j|jj}d|jkrDd|j d<d|j d<d|jkrXd|j d<d|jkrld|j d<|j |j dd }t }|D]b}zt|}Wn8tk r}z|d|t|fW5d}~XYnX|t t||7}q|jS)NrrrrrrzInvalid character code: %s %s)rr-r rrTrr2rr?rcomment_patternryr8rrr Z unicode_coderSrrVrunescaper)r\Zsubstitution_definitioncodesrrdecodedrTrererfr[1s2        z Unicode.runN)rgrhrirjrkrlrmr rnrqrecompilerr[rerererfrs rc@s(eZdZdZdZdZdZdZddZdS)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 Cszt|jd}Wn.tk rB|d|j|jdfYnXg}|jrt}|j |j|j ||D]}|d |qn| |j n2ttj||jd|j}|jj||||S)Nrz7Invalid class attribute value for "%s" directive: "%s".r+)r directive)r rpr8rSrTrrzrrr-rrYextendrpendingrZClassAttributerZr2r.Z note_pendingr)r\Z class_valueZ node_list containerrrrererfr[Ws2   z Class.runN) rgrhrirjrkrlrmrr[rerererfrJs rc@s0eZdZdZedejjfdZ ddZ dS)RoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$c Cs|j|jks|js"|d|j|jd}|j|}|sP|d|j|f|d}|d}g}|rt ||j j |j|j j \}}|dkr|j j jd|t|j|j|jd}||gSntj}t|d rtd |j|fz4t|}|j j|jdd|j|id \} } } } Wn`tjk rz} z>|j j jd |j| ft|j|j|jd}||gWYSd} ~ XYnXd | krzt|| d <Wnbtk r} zB|j j jd|jt| ft|j|j|jd}||gWYSd} ~ 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".rN#Unknown interpreted text role "%s".rr8z[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.)rYr3rzrTrargument_patternmatchgroupr roler2languager-rrrPrZZgeneric_custom_rolehasattrAssertionErrorr Zparse_directive_blockr Z MarkupErrorr rprSrZ CustomRoleZregister_local_role)r\argsrZ new_role_nameZbase_role_namerZ base_rolerTZconverted_roler8r?rzrYZdetailrrererfr[ws             zRole.runN) rgrhrirrrr ZInlinerZ simplenamerr[rerererfrps  rc@s eZdZdZdZdZddZdS) 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)Nr(rrr) r8r Z_rolesrr2rr3r-rrTrrPrZ)r\Z role_namerrrTrererfr[s$     zDefaultRole.runN)rgrhrirjrlrmr[rerererfrsrc@s eZdZdZdZdZddZdS)TitlerrTcCs|jd|jjd<gS)Nrtitle)r8r2r.)r\rererfr[sz Title.runN)rgrhrirkrlrmr[rerererfrsrc@seZdZdZddZdS)DateTcCst|jtjs|d|jd|jp,d}tj dkrnz| t pDd}Wn"t k rl| dt YnXt|}tj dkrz|t pd}Wn6tk r|t pdd}| d|t fYnXt|gS) Nrr,z%Y-%m-%d)rrzutf-8z;Cannot encode date format string with locale encoding "%s".replacez-Error decoding "%s"with locale encoding "%s".)rr-r rrTrr;rzsys version_infoencoderrGr1timestrftimedecodeUnicodeDecodeErrorrrV)r\Z format_strrbrererfr[s0     zDate.runNrrerererfrsrc@s.eZdZdZdZdZdejiZdZ ddZ dS) TestDirectivez3This directive is useful only for testing purposes.rToptioncCsl|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:rzGDirective processed. Type="%s", arguments=%r, options=%r, content: None) rzr;r2rinforr8r?rrPr3)r\rbrrererfr[ s   zTestDirective.runN) rgrhrirjrlrmr rorqrr[rerererfrs  r)'rjZ __docformat__ros.pathr4rrZdocutilsrrrrZdocutils.utils.error_reportingrrrZdocutils.parsers.rstr r r r r Z$docutils.parsers.rst.directives.bodyrrZdocutils.parsers.rst.rolesrZdocutils.transformsrrrsrrrrrrrrrerererfs0   Z ,&= .