jfr8dZdZddlZddlZddlZddlmZmZddlZddl Z ddl Z ddl Z ddl m Z mZmZddl mZmZddlmZGdd e ZGd d e ZGd d ZGddeZGddeZGddeZGddeZdZdZdZGddeZdZdZ dZ!d:dZ"dZ#d Z$d:d!Z%d"Z&d#Z'd$Z(d%Z)d&Z*d'Z+d(Z,d)Z-d*Z.d+d+d,d,d,d,d-Z/ d.Z0d/Z1d0Z2d:d1Z3Gd2d3Z4d4d5d6d7d8Z5d:d9Z6dS);z: Miscellaneous utilities for the documentation utilities. reStructuredTextN)PurePathPath)ApplicationError DataError__version_info__)ionodes)unescapeceZdZdZdS) SystemMessagecnt||||_dSN) Exception__init__astextlevel)selfsystem_messagers w/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/__init__.pyrzSystemMessage.__init__s/4!6!6!8!8999 N)__name__ __module__ __qualname__rrrr r s#rr ceZdZdS)SystemMessagePropagationNrrrrrrrr!sDrrceZdZdZdZ ed\ZZZ Z Z ddZ ddZ d Zd Zd Zd Zd ZdZdZdZdZdS)Reporteraq Info/warning/error reporter and ``system_message`` element generator. Five levels of system messages are defined, along with corresponding methods: `debug()`, `info()`, `warning()`, `error()`, and `severe()`. There is typically one Reporter object per process. A Reporter object is instantiated with thresholds for reporting (generating warnings) and halting processing (raising exceptions), a switch to turn debug output on or off, and an I/O stream for warnings. These are stored as instance attributes. When a system message is generated, its level is compared to the stored thresholds, and a warning or error is generated as appropriate. Debug messages are produced if the stored debug switch is on, independently of other thresholds. Message output is sent to the stored warning stream if not set to ''. The Reporter class also employs a modified form of the "Observer" pattern [GoF95]_ to track system messages generated. The `attach_observer` method should be called before parsing, with a bound method or function which accepts system messages. The observer can be removed with `detach_observer`, and another added in its place. .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, 1995. zDEBUG INFO WARNING ERROR SEVERENFbackslashreplacec||_ ||_ ||_ ||_ ||_ t |t jst j|||}||_ |pt|dd|_ g|_ d|_ dS)a7 :Parameters: - `source`: The path to or description of the source data. - `report_level`: The level at or above which warning output will be sent to `stream`. - `halt_level`: The level at or above which `SystemMessage` exceptions will be raised, halting execution. - `debug`: Show debug (level=0) system messages? - `stream`: Where warning output is sent. Can be file-like (has a ``.write`` method), a string (file name, opened for writing), '' (empty string) or `False` (for discarding all stream messages) or `None` (implies `sys.stderr`; default). - `encoding`: The output encoding. - `error_handler`: The error handler for stderr output encoding. encodingasciiN) source error_handler debug_flag report_level halt_level isinstancer ErrorOutputstreamgetattrr$ observers max_level)rr'r*r+r.debugr$r(s rrzReporter.__init__Ns$ <*33( % .&".11 E^FHmDDF + HGFJ$H$H , @@rctjdtd||_||_t |t js t j||j|j }||_ ||_ dS)Nzdocutils.utils.Reporter.set_conditions() deprecated; Will be removed in Docutils 0.21 or later. Set attributes via configuration settings or directly. stacklevel) warningswarnDeprecationWarningr*r+r,r r-r$r(r.r))rcategoryr*r+r.r2s rset_conditionszReporter.set_conditionssx O)Q 8 8 8 8)$&".11 O^FDM4;MNNF rc:|j|dS)z The `observer` parameter is a function or bound method which takes one argument, a `nodes.system_message` instance. N)r0appendrobservers rattach_observerzReporter.attach_observers h'''''rc:|j|dSr)r0remover>s rdetach_observerzReporter.detach_observers h'''''rc0|jD] }||dSr)r0)rmessager?s rnotify_observerszReporter.notify_observerss0  H HW      rct|trt|}|}d|vrKt |d\}}|d=||d|||d|d|vrP ||d\}}n#t$rd\}}YnwxYw|||d<|||d<|d|j tj |g|R||j |d|}|j rW||jks|jr ||jks ||jkr/|j |dz||jkrt)||||jks|jr||t-||j|_|S)zs Return a system_message object. Raise an exception or generate a warning if appropriate. base_nodeNr'lineNN)rtype )r,rstrcopyget_source_line setdefaultget_source_and_linegetAttributeErrorr'r rlevelsr.r*r) DEBUG_LEVELr+writerr rFmaxr1) rrrEchildrenkwargs attributesr'rImsgs rrzReporter.system_messages$ gy ) ) #'llG[[]] & *6++>??LFD;'!%%h777%%fd333 : % % *#77 v8N8NOO ! * * *)  *!'- 8$%) 6" h 444"7<$,<<%(, E(:<<0:<< ; 3ET%666#738D>DD$ii!mmQ99T!W""Q EJ77#$:<@ABB B71:$$&&DD$<(((( rc 4i}|D]\}}||}|t|||vrtd|z ||||<D#ttf$r;}|d|d|dd|jd}~wwxYw|S)aa Return a mapping of option names to values. :Parameters: - `option_list`: A list of (name, value) pairs (the output of `extract_options()`). - `options_spec`: Dictionary mapping known option names to a conversion function such as `int` or `float`. :Exceptions: - `KeyError` for unknown option names. - `DuplicateOptionError` for duplicate options. - `ValueError` for invalid option values (raised by conversion function). - `TypeError` for invalid option value types (raised by conversion function). Nzduplicate option "%s"z (option: "z "; value: z)  )KeyErrorrv ValueError TypeError __class__joinr^)r|r{optionsrvalue convertordetails rryry4s$G" K K e &  4.. 7??&'>'EFF F K%Ie,,GDMMI& K K K"""&*ddEEE388FK3H3H3H$JKK K K NsA  B6BBceZdZdS)NameValueErrorNrrrrrrUrprrcbt|tr|S |tjd}nn#t $r|sYdSt d|t$rA |dd}n&#t$r|dd}YnwxYwYnwxYw|S)z Ensure `path` is Unicode. Return `str` instance. Decode file/path string in a failsafe manner if not already done. strictz/`path` value must be a String or ``None``, not utf-8r%replace)r,rMdecodesysgetfilesystemencodingrSrUnicodeDecodeError)paths r decode_pathrXs$  3{{3466AA *** 22) $))** * 333 3;;w11DD! 3 3 3;;w 22DDD 33 Ks;'A B,B,,BB, B&#B,%B&&B,+B,cg}|r|d}|dkrtd|d|}|dks|std||dzd}|std|z|dd vr||dd}|dkrtd |d |dd t ||dzkr9||dzrtd |d |dd|d|}||dzd}nI|d}|dkr|}d}n)|d|}||dzd}|||f||S)z Return a list of (name, value) from a line of the form "name=value ...". :Exception: `NameValueError` for invalid input (missing name, missing data, bad quotes, etc.). =r&z missing "="Nrz!missing attribute name before "="rzmissing value after "%s="z'"z attribute "z" missing end quote ()z " end quote (z) not followed by whitespacerr)findrstriplstriprr=r)rIattlistequalsattnameendquoterspaces rextract_name_valuerpsG  03 R<< // /ww-%%'' Q;;g; 577 7F1HII%%'' 9 -799 9 7e  yya!,,H2~~$n $q'''+,,,4yy8a<''DA,>,D,D,F,F'$n&-ggtAwww8999( #D $++--DDIIcNNE{{FUF|E!GHH~,,.. .///A  0B Nrc nt||j|j|j|j|j|j}|S)z Return a new Reporter object. :Parameters: `source` : string The path to or description of the source text of the document. `settings` : optparse.Values object Runtime settings. )r.r2r$r()r r*r+warning_streamr2error_encodingerror_encoding_error_handler) source_pathsettingsreporters r new_reporterrsBX*H,?&hn(; ===H Orcddlm}||}t|}t ||}t j|||}||d|S)a Return a new empty document object. :Parameters: `source_path` : string The path to or description of the source text of the document. `settings` : optparse.Values object Runtime settings. If none are provided, a default core set will be used. If you will use the document object with any Docutils components, you must provide their default settings as well. For example, if parsing rST, at least provide the rst-parser settings, obtainable as follows: Defaults for parser component:: settings = docutils.frontend.get_default_settings( docutils.parsers.rst.Parser) Defaults and configuration file customizations:: settings = docutils.core.Publisher( parser=docutils.parsers.rst.Parser).get_settings() r)frontendN)r'r&)docutilsrget_default_settingsrrr document note_source)rrrrrs r new_documentrsz6"!!!!!0022k**KK22H~hEEEH b))) Orct|dkrut|dtjrW|d}|D]N\}}||}|r.tj||||d<dSKdSdSdS)Nrr)rr,r rsearchsub)rkeyword_substitutionstextnodepattern substitutionmatchs rclean_rcs_keywordsrs 9~~z)A, CCQ<%:   !G\NN8,,E $z'++lH*M*MNN !     rctj|pt|dtj}tj|tj}|dd|ddkrd|S|||rR|rP|d|dkr>|||r|r|d|dk>|dgt|dz z|z}d|S)a Build and return a path to `target`, relative to `source` (both files). Differences to `os.relpath()`: * Inverse argument order. * `source` expects path to a FILE (while os.relpath expects a dir)! (Add a "dummy" file name if `source` points to a directory.) * Always use Posix path separator ("/") for the output. * Use `os.sep` for parsing the input (ignored by `os.relpath()`). * If there is no common prefix, return the absolute path to `target`. dummy_fileNr4/r&z..r) osrabspathrKrlseprreversepopr)r'target source_parts target_partspartss r relative_pathrsh7??6#G\T&\\,-G-G%%%*U26]]7??6**0088LBQB<+++xx %%% LB<#333 LB<#333 Fc,''!+ ,| ;E 88E??rctjdtd|jr/|jr Jd||j}t ||jS|jS)z Retrieve a stylesheet reference from the settings object. Deprecated. Use get_stylesheet_list() instead to enable specification of multiple stylesheets as a comma-separated list. zqutils.get_stylesheet_reference() is obsoleted by utils.get_stylesheet_list() and will be removed in Docutils 2.0.r4r56stylesheet and stylesheet_path are mutually exclusive.)r7r8r9stylesheet_path stylesheet _destinationr)r relative_tos rget_stylesheet_referencers M:%4444#& F F D F F&  "/K[(*BCCC""rcjrjr Jdjpjpg}t|tsd|dD}jrfd|D}|S)zJ Retrieve list of stylesheet references from the settings object. rc6g|]}|Sr)r).0rs r z'get_stylesheet_list..)s GGGtzz||GGGr,c:g|]}t|jSr)find_file_in_dirsstylesheet_dirs)rrrs rrz'get_stylesheet_list..,s6000)x/GHH000r)rrr,listrl)r stylesheetss` rget_stylesheet_listr s#F(@FF DFF A*Gh.AGRK k4 ( (HGG 0A0A#0F0FGGG 00000#.000 rc>t|}|r|S|D]P}t||z }|r|cSQ|S)z} Search for `path` in the list of directories `dirs`. Return the first expansion that matches an existing file. )r is_absoluteas_posix expanduserexists)rdirsdfs rrr1s ::D }}    GG   4 ' 88:: ::<<    ==??rcf|ddt|dddkS|jS)z Return whether or not to trim footnote space. If trim_footnote_reference_space is not None, return it. If trim_footnote_reference_space is None, return False unless the footnote reference style is 'superscript'. trim_footnote_reference_spaceNfootnote_references superscript)rPr/r)rs rget_trim_footnote_ref_spacerAs<:DAAIx!6==NN55rcT|r%|js|jr|j|jfS|j}|%dS)zk Return the "source" and "line" attributes from the `node` given or from its closest ancestor. rJ)r'rIparent)nodes rrOrOPsF  ; *$) *; ) ){  :rc:g}d} |d|}|dkr2|||dd|S|||||d||dz|d zz|d z}) z;Return a string with escape-backslashes converted to nulls.rT\r&Nrrr4)rr=r)textrstartfounds r escape2nullr\s E E $&& B;; LLeff & & &775>> ! T%+&''' Vd5757?33444 rcz|d}d|D}ttj|S)zh Split `text` on escaped whitespace (null+space or null+newline). Return a list of strings. z c8g|]}|dS)z )rl)rstrings rrz,split_escaped_whitespace..ps$<<<&v||H%%<<z(strip_combining_chars..vs2CC+*?*B*BC1CCCCCCr)rrs rstrip_combining_charsr us# 77CCdCCC C CCrc4dt|DS)uReturn indices of all combining chars in Unicode string `text`. >>> from docutils.utils import find_combining_chars >>> find_combining_chars('A t̆ab̆lĕ') [3, 6, 9] c@g|]\}}tj||Srr)rirs rrz(find_combining_chars..s, F F F$!Q[-B1-E-E FA F F Fr) enumerater s rfind_combining_charsrys G F)D// F F FFrcttt|}t|D]}d||<d|DS)uIndices of Unicode string `text` when skipping combining characters. >>> from docutils.utils import column_indices >>> column_indices('A t̆ab̆lĕ') [0, 1, 2, 4, 5, 7, 8] Ncg|]}||Srr)rr s rrz"column_indices..s 7 7 7!Ar)rrmrr)rstring_indicesindexs rcolumn_indicesrsW%D **++N%d++%% $u 7 7~ 7 7 77rr4r)WFNaHNAcvtd|D}|tt|z}|S)zqReturn the column width of text. Correct ``len(text)`` for wide East Asian and combining Unicode chars. c3TK|]#}ttj|V$dSr)east_asian_widthsreast_asian_widthrs rrzcolumn_width..sF"+">q"A"ABr)sumrr)rwidths r column_widthr!sQ   E S%d++ , ,,E LrcFg}|D]}||vr|||Sr)r=)Lritems runiqr&s4 A q== HHTNNN Hrc|dd}tjdd|}d|dD}|df}g}t t|ddD]E}tj ||D]-}| d ||z.F||z }|S)aWReturn a list of normalized combinations for a `BCP 47` language tag. Example: >>> from docutils.utils import normalize_language_tag >>> normalize_language_tag('de_AT-1901') ['de-at-1901', 'de-at', 'de-1901', 'de'] >>> normalize_language_tag('de-CH-x_altquot') ['de-ch-x-altquot', 'de-ch', 'de-x-altquot', 'de'] -_z_([a-zA-Z0-9])_z_\1-cg|]}|Srr)rsubtags rrz*normalize_language_tag..s333&v333rrr&) rrrerrlrrmrr combinationsr=r)tagsubtagsbase_tagtaglistntagss rnormalize_language_tagr4s ))++  c3 ' 'C &#Wc 2 2C33CIIcNN333G A HG 3w<<B ' '44*7A66 4 4D NN388HTM22 3 3 3 3 4 xG NrcT|r|dkrd|d}nd}d|dS)z{Return an XML text declaration. Include an encoding declaration, if `encoding` is not 'unicode', '', or None. unicodez encoding=""rz )r)r$encoding_declarations rxml_declarationr9sL "HNN$$ 118X888! ;!5 ; ; ;;rc2eZdZdZd dZdZdZdZdZdS) DependencyListz List of dependencies, with file recording support. Note that the output file is not automatically closed. You have to explicitly call the close() method. Nrcdg|_d|_|r|||j|dS)z Initialize the dependency list, automatically setting the output file to `output_file` (see `set_output()`) and adding all supplied dependencies. If output_file is None, no file output is done when calling add(). N)rfile set_outputadd)r output_file dependenciess rrzDependencyList.__init__sA   ) OOK ( ( (,rcn|r2|dkrtj|_dSt|dd|_dSdS)a Set the output file and clear the list of already added dependencies. `output_file` must be a string. The specified file is immediately overwritten. If output_file is '-', the output will be written to stdout. r(wr)r$N)rstdoutr=openrr@s rr>zDependencyList.set_outputsK  Ec!!J  cGDDD  E Erc|D]r}t|tr|}||jvr>|j||j|j|dzsdS)z Append `path` to `self.list` unless it is already there. Also append to `self.file` unless it is already there or `self.file is `None`. NrL)r,rrrr=r=rV)rpathsrs rr?zDependencyList.adds / /D$)) '}}49$$   &&&9(IOODI...  / /rcl|jtjur|jd|_dS)z( Close the output file. N)r=rrDclose)rs rrJzDependencyList.closes0 9CJ & & IOO    rcv |jj}n#t$rd}YnwxYw|jjd|d|jdS)N(z, r)r=rrSrrrrFs r__repr__zDependencyList.__repr__sX ).KK   KKK #~666 TYYYOOs  )Nr) rrrrkrr>r?rJrMrrrr;r;sv     EEE / / /PPPPPrr;abrcr)alphabeta candidatefinalc|t}|jr d|jz}nd}t|j}|jr|j}nd}|jrd}nd}|jd|j||||}|S)a4 Return a version identifier string built from `version_info`, a `docutils.VersionInfo` namedtuple instance or compatible tuple. If `version_info` is not provided, by default return a version identifier string based on `docutils.__version_info__` (i.e. the current Docutils version). Nz.%srz.dev.)rmicrorelease_level_abbreviations releaselevelserialreleasemajorminor) version_inforWrYrZdevversions rversion_identifierra(s'  **.|/HIL$     G Nrr)7rk __docformat__rros.pathpathlibrrr,rr7rrrrrr r docutils.nodesr r rr rorrrtrvr}rxryrrrrrrrrrrrrOrrr rrrr!r&r4r9r;rXrarrrrfs # """""""" BBBBBBBBBB######$     /   JGJGJGJGJGJGJGJGZ,++++9+++00000)00044444-44466666/666;;;2   FB&%%%%Y%%%0***Z$""""JD####@"    6 6 6      +++DDDGGG 8 8 8        6 < < < <CPCPCPCPCPCPCPCPN         r