3 E\\@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 ZejjejjejdZddZd 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) literalcodeencodingz tab-widthz start-linezend-linez start-afterz end-beforez number-linesclassnameincludec.Cs@|jjjjs|jd|j|jjj|j |jj d}t j j t j j|}tj |jd}|jdr|jdrt j j|j|dd}t j jt j j||}tjd|}tj|}|jjd|jjjj}|jjjj}|jjd|jjjj}y&|jjjjj |t!j"|||d }Wnvt#k rN}z|j$d |jt%|fWYdd}~Xn<t&k r}z|j$d |jt'|fWYdd}~XnX|jjd d} |jjd d} y8| s| dk r|j(} dj| | | } n|j)} Wn<t*k r}z|j$d|jt'|fWYdd}~XnX|jjdd} | rh| j+| }|dkrT|j$d|j| |t,| d} |jjdd}|r| j+|}|dkr|j$d|j| d|} t-j.| |dd}d|jkr|dkr| j/|}n| }tj0| ||jjdgd}d|_1|j2|d|jkryt3|jdp*d} Wn t4k rP|j5dYnX| t,|} |jdrv|dd }t6g|fg| | }xP|D]6\}}|r|tj7|||d7}n|tj8||7}qWn|tj8||7}|gSd|jkr.||jd<t9|j|jj:dg|j||j |j;|j<|j|j }|j=S|jj>||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-linezProblem 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)sourceclassesz number-linesz+:number-lines: with non-integer start value )r rrr")?statedocumentsettingsfile_insertion_enabledwarningr state_machineZ input_linesrlinenoZ input_offsetospathdirnameabspathr arguments startswithendswithjoinstandard_include_pathnormpathr relative_pathrZ reprunicodeoptionsgetinput_encodinginput_encoding_error_handler tab_widthrecord_dependenciesaddr FileInputUnicodeEncodeErrorsevererIOErrorr readlinesread UnicodeErrorfindlenrZ string2lines expandtabs literal_blocklineZadd_nameint ValueErrorerrorrinlineTextrpopcontent_offset block_textrunZ insert_input)selfr source_dirr+r e_handlerr9Z include_filerJ startlineendlinelinesZrawtextZ after_textZ after_indexZ before_textZ before_indexZ include_linestextrFtokensr valueZ codeblockrZ~/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/parsers/rst/directives/misc.pyrP5s     "$ $                    z Include.runN)__name__ __module__ __qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer flagZ unchangedrrHunchanged_required class_option option_specr*r+r1r,r __file__r2rPrZrZrZr[rs$  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|jjjj s0|jjjj r@d|jks0d|jkr@|jd|jddj|j dj j i}|jj d|jjjj }|jjjj}|jrd|jksd|jkr|jd|jd j|j}n"d|jkrd|jkr|jd |jtjjtjj|jjj}tjjtjj||jd}tjd|}y&tj|||d }|jjjjj|Wn<tk r}z|jd |jt|fWYdd}~XnXy |j }Wn<t!k r}z|jd |jt|fWYdd}~XnX||d<nd|jkr|jd} ddl"} ddl#} ddl$} y| j%j&| j } WnN| jj'tt(fk rj}z&|jd|j|jdt|fWYdd}~XnXtj)| | ||d}y |j }Wn<t!k r}z|jd |jt|fWYdd}~XnX| |d<n|j*t+j,d|f|} |j-j.|j/\| _0| _1| gS)Nrirjz"%s" directive disabled.format rrzF"%s" directive may not both specify an external file and have content.r!zXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.)rrrz&Problems with "%s" directive path: %s.zProblem with "%s" directive: %srz*Problems with "%s" directive URL "%s": %s.)rrrrr)2r#r$r%Z raw_enabledr&r5r'rr1r.lowersplitr6r7r8contentrJr*r+r,r-Zcurrent_sourcer3rr4rr<r:r;r?r>rrArBurllib.request urllib.error urllib.parserequesturlopenURLErrorOSErrorZ StringInputassert_has_contentrrawr(Zget_source_and_liner)rrG) rQ attributesrrSrWrRr+Zraw_filerJrurllibZraw_textZraw_noderZrZr[rPsx        $ $   , $ zRaw.runN)r\r]r^r_r`rarbr r+urirrf has_contentrPrZrZrZr[rhs  rhc@seZdZdZddZdS)ReplaceTcCst|jtjs|jd|j|jdj|j}t j |}|jj |j|j |d}g}x`|D]X}| rzt|t j rz|}q^t|t jrg|d<|j|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 SubstitutionDefrJrrwr1rorElement nested_parserNZ paragraphZsystem_messageappendr(reporterr)children)rQrWelementnodemessageselemrZrZr[rPs.       z Replace.runN)r\r]r^r|rPrZrZrZr[r}sr}c@s@eZdZdZdZdZdZejejejdZ e j 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|^)\.\. cCst|jtjs|jd|j|jj}d|jkrDd|j d<d|j d<d|jkrXd|j d<d|jkrld|j d<|j j |j ddj }t j}xb|D]Z}ytj|}Wn8tk r}z|jd|t|fWYdd}~XnX|t j|7}qW|jS)NzVInvalid context: the "%s" directive can only be used within a substitution definition.rrrrrzInvalid character code: %s %s)r~r#r rrJrr(rr5rycomment_patternrnr.rrr Z unicode_coderIrrLr)rQZsubstitution_definitioncodesrrdecodedrJrZrZr[rP.s,         "z Unicode.runN)r\r]r^r_r`rarbr rcrfrecompilerrPrZrZrZr[rs  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 Csytj|jd}Wn.tk rB|jd|j|jdfYnXg}|jrtj}|j j |j|j |x|D]}|dj |qpW|j |j n2tjtj||jd|j}|jjj||j||S)Nrz7Invalid class attribute value for "%s" directive: "%s".r )r directive)r rer.rIrJrrorrr#rrNextendrpendingrZClassAttributerOr(r$Z note_pendingr)rQZ class_valueZ node_list containerrrrZrZr[rPTs*   z Class.runN) r\r]r^r_r`rarbr|rPrZrZrZr[rGs rc@s0eZdZdZejdejjfdZ ddZ dS)RoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$c!Cs |j|jks|j r$|jd|j|jd}|jj|}|sR|jd|j|f|jd}|jd}g}|rtj ||j j |j|j j \}}|dkr|j j jd|tj|j|j|jd}||gSntj}t|d  std |j|fy4t|}|j j|jdd|j|id \} } } } WnVtjk rt} z6|j j jd |j| ftj|j|j|jd}||gSd} ~ XnXd | krytj|| d <WnXtk r} z:|j j jd|jt| ftj|j|j|jd}||gSd} ~ XnXtj||| | }tj|||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".rNz#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)rorJrargument_patternmatchgroupr roler(languager#rrrFrOZgeneric_custom_rolehasattrAssertionErrorr Zparse_directive_blockr Z MarkupErrorr rerIrZ CustomRoleZregister_local_role)rQargsrZ new_role_nameZbase_role_namerZ base_rolerJZconverted_roler.r5rorNZdetailrrZrZr[rPts`            zRole.runN) r\r]r^r|rrr ZInlinerZ simplenamerrPrZrZrZr[rmsrc@s eZdZdZdZdZddZdS) DefaultRolez&Set the default interpreted text role.rFcCs|jsdtjkrtjd=gS|jd}tj||jj|j|jj\}}|dkr||jjj d|t j |j |j |jd}||gS|tjd<|S)Nrrz#Unknown interpreted text role "%s".)rG) r.r Z_rolesrr(rr)r#rrJrrFrO)rQZ role_namerrrJrZrZr[rPs      zDefaultRole.runN)r\r]r^r_rarbrPrZrZrZr[rsrc@s eZdZdZdZdZddZdS)TitlerrTcCs|jd|jjd<gS)Nrtitle)r.r(r$)rQrZrZr[rPsz Title.runN)r\r]r^r`rarbrPrZrZrZr[rsrc@seZdZdZddZdS)DateTcCst|jtjs|jd|jdj|jp,d}tj d krny|j t pDd}Wn"t k rl|j dt YnXtj|}tj d kry|jt pd}Wn6tk r|jt pdd}|j d |t fYnXtj|gS) NzVInvalid context: the "%s" directive can only be used within a substitution definition.r!z%Y-%m-%drrzutf-8z;Cannot encode date format string with locale encoding "%s".replacez-Error decoding "%s"with locale encoding "%s".)rr)rr)r~r#r rrJrr1rosys version_infoencoderr=r'timestrftimedecodeUnicodeDecodeErrorrrL)rQZ format_strrWrZrZr[rPs(    zDate.runN)r\r]r^r|rPrZrZrZr[rsrc@s.eZdZdZdZdZdejiZdZ ddZ dS) TestDirectivez3This directive is useful only for testing purposes.rToptioncCsl|jrBdj|j}|jjjd|j|j|jftj |||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(rinforr.r5rrFr))rQrWrrZrZr[rPs  zTestDirective.runN) r\r]r^r_rarbr rdrfr|rPrZrZrZr[rs  r)'r_Z __docformat__ros.pathr*rrZdocutilsrrrrZdocutils.utils.error_reportingrrrZdocutils.parsers.rstr r r r r Z$docutils.parsers.rst.directives.bodyrrZdocutils.parsers.rst.rolesrZdocutils.transformsrrrhr}rrrrrrrrZrZrZr[s0    Z ,&= .