o f'had@sTdZdZddlZddlZddlZddlZddlZddlmZm 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.reStructuredTextN)ionodes statemachineutils) SafeString ErrorString)locale_encoding) Directiveconvert_directive_function) directivesrolesstates) CodeBlock NumberLines) set_classes)miscc @sjeZdZdZdZdZdZejej ej ej e e e ej ej ej ejej d ZejeejdZddZd 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) literalcodeencodingparser tab-width start-lineend-line start-after end-before number-linesclassnameincludec sfjjjjsdjjjj jj d}t j t j |}t jd}|drD|drDt j j|dd}t j t j ||}td|}t|}jdjjjj}jjjj}jd jjjj}zjjjj |t!j"|||d }Wn/t#y}z $d jt%|fd}~wt&y}z $d jt'|fd}~wwjd d} jdd} z| s| dur|(} d| | | } n|)} Wnt*y}z $djt'|fd}~wwjdd} | r | +| }|dkr$dj| |t,| d} jdd}|rB| +|}|dkr<$dj| d|} t-j.| |ddt/D]\}}t,|jjjj0krhd||dfqNdjvr|dkr{| 1|}n| }tj2| |jdgd}d|_34|djvrz t5jdpd} Wn t6y7dw| t,} |dr|dd}t8g|fg| | }|D]\}}|r|tj9|||d7}q|t:|7}q|gS|t:|7}|gSdjvr(|jd <|dkr | ;t<jj=dgjj j>j?jj }|@Sd!jvrIjd!}tA|jjj}|Bd||jCStd|}| | || f}jjjD}|sf|d"tEjFd#fg}fd$d%|D}||fd&d%|Dvrd'jd(|gd)d%|dddDfjG||H||j ffd*d%|Djj_DgS)+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)convert_whitespacez,"%s": line %d exceeds the line-length-limit.rr)sourceclassesrz+:number-lines: with non-integer start value )r.rr-r)NNNNcsg|] }|djkr|qSr0)lineno).0entryselfF/usr/lib/python3/dist-packages/docutils/parsers/rst/directives/misc.py szInclude.run..cSsg|] \}}}||fqSr7r7r3pthopter7r7r8r9s z(circular inclusion in "%s" directive: %sz < cSsg|]\}}}|qSr7r7r:r7r7r8r9scs(g|]\}}}|||tdfqSr1)lenr:) include_linesr7r8r9s)Istatedocumentsettingsfile_insertion_enabledwarningr state_machine input_linesr-r2 input_offsetospathdirnameabspathr arguments startswithendswithjoinstandard_include_pathnormpathr relative_pathr reprunicodeoptionsgetinput_encodinginput_encoding_error_handler tab_widthrecord_dependenciesaddr FileInputUnicodeEncodeErrorsevererIOErrorr readlinesread UnicodeErrorfindr>r string2lines enumerateline_length_limit expandtabs literal_blocklineadd_nameint ValueErrorerrorrinlineText splitlinesrpopcontent_offset block_textrun new_documentparsechildren include_logsysmaxsize insert_inputappend)r6r- source_dirrIr e_handlerrX include_filerl startlineendlinelinesrawtext after_text after_index before_text before_indexirhtextrgtokensr.value codeblockrrA clip_optionsrwr7)r?r6r8rs7s                                             z Include.runN)__name__ __module__ __qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer flag unchangedr parser_namerjunchanged_required class_option option_specrHrIrOdocutils_datadirr__file__rPrsr7r7r7r8rs,  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|jjjjsd|jvsd|jvr|d|jdd|j d i}|j d|jjjj }|jjjj}|jrZd|jvsJd|jvrR|d|jd |j}nd|jvrd|jvrl|d |jtjtj|jjj}tjtj||jd}td|}ztj|||d }|jjjj|Wnty}z |d |jt|fd}~wwz| }Wnt!y}z |d |jt|fd}~ww||d<nd|jvrY|jd} t"j#dkrddl$m%} ddl&m'} nddl(m%} m'} z| |  } Wn | tt)fy*}z|d|j|jdt|fd}~wwtj*| | ||d}z| }Wnt!yS}z |d |jt|fd}~ww| |d<n|+t,j-d|fi|} |j./|j0\| _1| _2| gS)Nrrr"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.r&r)r+r-r)urlopen)URLError)rrz*Problems with "%s" directive URL "%s": %s.)r-r'rr(r*)3r@rArB raw_enabledrCrTrDr rOrLlowersplitrUrVrWcontentrlrHrIrJrKcurrent_sourcerQrrRrr[rYrZr^r]rr`rarx version_infourllib.requestr urllib.errorrurllib2OSError StringInputassert_has_contentrrawrEget_source_and_liner2r-rh)r6 attributesrr}rr|rIraw_filerlr-rrraw_textraw_noder7r7r8rss                     zRaw.runN)rrrrrrrr rIurirr has_contentrsr7r7r7r8rs  rc@eZdZdZddZdS)ReplaceTcCst|jtjs|d|j|d|j}t |}|j |j|j |d}g}|D],}|s;t|t j r;|}q.t|t jrKg|d<||q.|jjjd|j|jdgS|rb||jS|S)NVInvalid context: the "%s" directive can only be used within a substitution definition.r/backrefsz=Error in "%s" directive: may contain a single paragraph only.rh) isinstancer@rSubstitutionDefrlr rrOrrElement nested_parserq paragraphsystem_messager{rEreporterr2rv)r6relementnodemessageselemr7r7r8rs.s<     z Replace.runNrrrrrsr7r7r7r8r* rc@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|jvr"d|j d<d|j d<d|jvr,d|j d<d|jvr6d|j d<|j |j dd }t }|D](}zt|}Wntyi}z |d|t|fd}~ww|t |7}qI|jS)NrrrrrrzInvalid character code: %s %s)rr@rrrlr rErrTrcomment_patternrrLrrr unicode_coderkrrnrv)r6substitution_definitioncodesrrdecodedrlr7r7r8rs]s6        z Unicode.runN)rrrrrrrr rrrecompilerrsr7r7r7r8rJs  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 Csz t|jd}Wnty|d|j|jdfwg}|jrFt}|j |j|j ||D] }|d |q4| |j |Sttj||jd|j}|jj||||S)Nrz7Invalid class attribute value for "%s" directive: "%s".r.)r directive)r rrLrkrlr rrrr@rrqextendrvpendingrClassAttributerrrErA note_pendingr{)r6 class_value node_list containerrrr7r7r8rss6    z Class.runN) rrrrrrrrrsr7r7r7r8rvs rc@s0eZdZdZedejjfdZ ddZ dS)RoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$r0c Cs|j|jks |js|d|j|jd}|j|}|s(|d|j|f|d}|d}g}|rbt ||j j |j|j j \}}|dura|j j jd|t|j|j|jd}||gSntj}t|d rsJd |j|fzt|}|j j|jdd|j|id \} } } } Wn.tjy} z!|j j jd |j| ft|j|j|jd}||gWYd} ~ Sd} ~ wwd | vrz t|| d <Wn/ty} z#|j j jd|jt| ft|j|j|jd}||gWYd} ~ Sd} ~ wwt||| | }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".rrN#Unknown interpreted text role "%s".rrLz[Supplemental directive arguments for "%s" directive not supported (specified by "%r" role).)option_presetszError in "%s" directive: %s.rz(Invalid argument for "%s" directive: %s.)rqr2rrlr argument_patternmatchgroupr rolerElanguager@rrrgrrgeneric_custom_rolehasattrr parse_directive_blockr MarkupErrorr rrkr CustomRoleregister_local_role)r6argsr new_role_namebase_role_namer base_rolerlconverted_rolerLrTrrqdetailrr7r7r8rss          zRole.runN) rrrrrrrInliner simplenamerrsr7r7r7r8rs   rc@ eZdZdZdZdZddZdS) DefaultRolez&Set the default interpreted text role.rFcCs|jsdtjvr tjd=gS|jd}t||jj|j|jj\}}|dur>|jjj d|t |j |j |jd}||gS|tjd<|S)Nr*rrr) rLr _rolesrrErr2r@rrlrrgrr)r6 role_namerrrlr7r7r8rss"      zDefaultRole.runN)rrrrrrrsr7r7r7r8rs  rc@r)TitlerrTcCs|jd|jjd<gS)Nrtitle)rLrErAr5r7r7r8rssz Title.runN)rrrrrrrsr7r7r7r8rs  rc@r)DateTcCst|jtjs|d|jd|jpd}tj dkr4z | t p"d}Wnt y3| dt wt|}tj dkr`z |t pDd}Wnty_|t pSdd}| d|t fwt|gS) Nrr/z%Y-%m-%drzutf-8z;Cannot encode date format string with locale encoding "%s".replacez-Error decoding "%s"with locale encoding "%s".)rr@rrrlr rOrrxrencoder r\rDtimestrftimedecodeUnicodeDecodeErrorrrn)r6 format_strrr7r7r8rss4      zDate.runNrr7r7r7r8rrrc@s.eZdZdZdZdZdejiZdZ ddZ dS) TestDirectivez3This directive is useful only for testing purposes.rToptioncCsp|jr#d|j}|jjjd|j|j|jft |||j d}|gS|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) rrOrErinfor rLrTrrgr2)r6rrr7r7r8rs3s   zTestDirective.runN) rrrrrrr rrrrsr7r7r7r8r*s  r)'r __docformat__rxos.pathrHrrrrrrrdocutils.utils.error_reportingrrr docutils.parsers.rstr r r r r$docutils.parsers.rst.directives.bodyrrdocutils.parsers.rst.rolesrdocutils.transformsrrrrrrrrrrrr7r7r7r8s4   6^ ,&= ,