
    -Phv                     8   d Z dZddlZddlZddlZddlmZmZ ddlZddl	Z	ddl
Z
ddlZddlmZmZmZ ddlmZmZ ddlmZ  G d d	e          Z G d
 de          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Zd Zd Zd Z G d de          Zd Zd Z d Z!d:dZ"d Z#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/ Z1d0 Z2d:d1Z3 G d2 d3          Z4d4d5d6d7d8Z5d:d9Z6dS );z:
Miscellaneous utilities for the documentation utilities.
reStructuredText    N)PurePathPath)ApplicationError	DataError__version_info__)ionodes)unescapec                       e Zd Zd ZdS )SystemMessagec                 n    t                               | |                                           || _        d S N)	Exception__init__astextlevel)selfsystem_messager   s      W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/utils/__init__.pyr   zSystemMessage.__init__   s/    4!6!6!8!8999


    N)__name__
__module____qualname__r    r   r   r   r      s#            r   r   c                       e Zd ZdS )SystemMessagePropagationNr   r   r   r   r   r   r   r   !   s        Dr   r   c                       e Zd ZdZd                                Z	  ed          \  ZZZ	Z
Z	 	 ddZ	 ddZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZdS )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.
    zDEBUG INFO WARNING ERROR SEVERE   NFbackslashreplacec                    || _         	 || _        	 || _        	 || _        	 || _        	 t          |t          j                  st          j        |||          }|| _        	 |pt          |dd          | _
        	 g | _        	 d| _        dS )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.
        encodingasciiN)sourceerror_handler
debug_flagreport_level
halt_level
isinstancer	   ErrorOutputstreamgetattrr$   	observers	max_level)r   r'   r*   r+   r.   debugr$   r(   s           r   r   zReporter.__init__N   s    $ <*33(	 %	. &".11 	E^FHmDDF+ HGFJ$H$H,	 @@r   c                     t          j        dt          d           || _        || _        t          |t          j                  s t          j        || j        | j	                  }|| _
        || _        d S )Nzdocutils.utils.Reporter.set_conditions() deprecated; Will be removed in Docutils 0.21 or later. Set attributes via configuration settings or directly.   
stacklevel)warningswarnDeprecationWarningr*   r+   r,   r	   r-   r$   r(   r.   r)   )r   categoryr*   r+   r.   r2   s         r   set_conditionszReporter.set_conditions   sx     O )Q	8 	8 	8 	8 )$&".11 	O^FDM4;MNNFr   c                 :    | j                             |           dS )z
        The `observer` parameter is a function or bound method which takes one
        argument, a `nodes.system_message` instance.
        N)r0   appendr   observers     r   attach_observerzReporter.attach_observer   s     
 	h'''''r   c                 :    | j                             |           d S r   )r0   remover>   s     r   detach_observerzReporter.detach_observer   s    h'''''r   c                 0    | j         D ]} ||           d S r   )r0   )r   messager?   s      r   notify_observerszReporter.notify_observers   s0     	 	HHW	 	r   c                    t          |t                    rt          |          }|                                }d|v rKt	          |d                   \  }}|d= ||                    d|           ||                    d|           d|vrP	 |                     |                    d                    \  }}n# t          $ r d\  }}Y nw xY w|||d<   |||d<   |                    d| j	                   t          j        |g|R || j        |         d|}| j        rW|| j        k    s| j        r|| j        k    s|| j        k    r/| j                            |                                dz              || j        k    rt)          ||          || j        k    s| j        r|                     |           t-          || j                  | _        |S )zs
        Return a system_message object.

        Raise an exception or generate a warning if appropriate.
        	base_nodeNr'   lineNN)r   type
)r,   r   strcopyget_source_line
setdefaultget_source_and_linegetAttributeErrorr'   r
   r   levelsr.   r*   r)   DEBUG_LEVELr+   writer   r   rF   maxr1   )	r   r   rE   childrenkwargs
attributesr'   rI   msgs	            r   r   zReporter.system_message   s$    gy)) 	#'llG[[]]
&  *6++>??LFD;'!%%h777%%fd333:%%*#77
v8N8NOO! * * *)*!'-
8$%)
6" 	h444"7 <$,< <%(,E(:< <0:< < ; 	3ET%666# 738D<L3L3L$77KcjjllT1222DO##U+++4###t#!!#&&&UDN33
s   +B9 9C
Cc                 @    | j         r | j        | j        g|R i |S dS )z
        Level-0, "DEBUG": an internal reporting issue. Typically, there is no
        effect on the processing. Level-0 system messages are handled
        separately from the others.
        N)r)   r   rU   r   argsrY   s      r   r2   zReporter.debug   sA     ? 	J&4&t'7I$III&III	J 	Jr   c                 .     | j         | j        g|R i |S )z
        Level-1, "INFO": a minor issue that can be ignored. Typically there is
        no effect on processing, and level-1 system messages are not reported.
        )r   
INFO_LEVELr]   s      r   infozReporter.info   s)    
 #t"4?DTDDDVDDDr   c                 .     | j         | j        g|R i |S )z
        Level-2, "WARNING": an issue that should be addressed. If ignored,
        there may be unpredictable problems with the output.
        )r   WARNING_LEVELr]   s      r   warningzReporter.warning   s*    
 #t"4#5GGGGGGGr   c                 .     | j         | j        g|R i |S )zz
        Level-3, "ERROR": an error that should be addressed. If ignored, the
        output will contain errors.
        )r   ERROR_LEVELr]   s      r   errorzReporter.error   s*    
 #t"4#3EdEEEfEEEr   c                 .     | j         | j        g|R i |S )z
        Level-4, "SEVERE": a severe error that must be addressed. If ignored,
        the output will contain severe errors. Typically level-4 system
        messages are turned into exceptions which halt processing.
        )r   SEVERE_LEVELr]   s      r   severezReporter.severe   s*     #t"4#4FtFFFvFFFr   )NFNr"   )NF)r   r   r   __doc__splitrT   rangerU   r`   rc   rf   ri   r   r;   r@   rC   rF   r   r2   ra   rd   rg   rj   r   r   r   r    r    %   s%        : /4466FD U1XX	[@D;M1A 1A 1A 1Ah +0       ( ( (( ( (  - - -^J J JE E EH H HF F FG G G G Gr   r    c                       e Zd ZdS )ExtensionOptionErrorNr   r   r   r   ro   ro                r   ro   c                       e Zd ZdS )BadOptionErrorNr   r   r   r   rr   rr      rp   r   rr   c                       e Zd ZdS )BadOptionDataErrorNr   r   r   r   rt   rt      rp   r   rt   c                       e Zd ZdS )DuplicateOptionErrorNr   r   r   r   rv   rv      rp   r   rv   c                 @    t          |           }t          ||          S )aC  
    Return a dictionary mapping extension option names to converted values.

    :Parameters:
        - `field_list`: A flat field list without field arguments, where each
          field body consists of a single paragraph only.
        - `options_spec`: Dictionary mapping known option names to a
          conversion function such as `int` or `float`.

    :Exceptions:
        - `KeyError` for unknown option names.
        - `ValueError` for invalid option values (raised by the conversion
           function).
        - `TypeError` for invalid option value types (raised by conversion
           function).
        - `DuplicateOptionError` for duplicate options.
        - `BadOptionError` for invalid fields.
        - `BadOptionDataError` for invalid option data (missing name,
          missing data, bad quotes, etc.).
    )extract_optionsassemble_option_dict)
field_listoptions_specoption_lists      r   extract_extension_optionsr}      s!    * "*--K\:::r   c                    g }| D ]a}t          |d                                                                                   dk    rt          d          t	          |d                                                                                   }|d         }t          |          dk    rd}nt          |          dk    s_t          |d         t          j                  r?t          |d                   dk    s&t          |d         d         t          j	                  st          d|z            |d         d                                         }|                    ||f           c|S )a  
    Return a list of option (name, value) pairs from field names & bodies.

    :Parameter:
        `field_list`: A flat field list, where each field name is a single
        word and each field body consists of a single paragraph only.

    :Exceptions:
        - `BadOptionError` for invalid fields.
        - `BadOptionDataError` for invalid option data (missing name,
          missing data, bad quotes, etc.).
    r      z:extension option field name may not contain multiple wordsNzMextension option field body may contain
a single paragraph only (option "%s"))lenr   rl   rr   rM   lowerr,   r
   	paragraphTextrt   r=   )rz   r|   fieldnamebodydatas         r   rx   rx     sZ    K ) )uQx  &&(())Q.. LN N N58??$$**,,--Qxt99>>DD$ii!mmQ99 T!W""Q
EJ77 #$:<@AB B B 71:$$&&DD$<((((r   c                 4   i }| D ]\  }}||         }|t          |          ||v rt          d|z            	  ||          ||<   D# t          t          f$ r;}|                    d|d|dd                    |j                            d}~ww xY w|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).
    Nzduplicate option "%s"z
(option: "z
"; value: z)
 )KeyErrorrv   
ValueError	TypeError	__class__joinr^   )r|   r{   optionsr   value	convertordetails          r   ry   ry   4  s    $ G" 
K 
Ke &	4.. 7??&'>'EFFF	K%Ie,,GDMMI& 	K 	K 	K"""&*ddEEE388FK3H3H3H$J K K K	K Ns   A		B6BBc                       e Zd ZdS )NameValueErrorNr   r   r   r   r   r   U  rp   r   r   c                 b   t          | t                    r| S 	 |                     t          j                    d          } nn# t
          $ r | sY dS t          d|           t          $ rA 	 |                     dd          } n&# t          $ r |                     dd          } Y nw xY wY nw xY w| S )z
    Ensure `path` is Unicode. Return `str` instance.

    Decode file/path string in a failsafe manner if not already done.
    strict z/`path` value must be a String or ``None``, not utf-8r%   replace)r,   rM   decodesysgetfilesystemencodingrS   r   UnicodeDecodeError)paths    r   decode_pathr   X  s     $ 3{{3466AA * * * 	22 ) $) ) * * 	* 3 3 3	3;;w11DD! 	3 	3 	3;;w	22DDD	33
 Ks;   'A B,B,,BB, B&#B,%B&&B,+B,c                    g }| r|                      d          }|dk    rt          d          | d|                                         }|dk    s|st          d          | |dz   d                                         } | st          d|z            | d         d	v r|                      | d         d          }|dk    rt          d
|d| d         d          t	          |           |dz   k    r9| |dz                                            rt          d
|d| d         d          | d|         }| |dz   d                                         } nI|                      d          }|dk    r| }d} n)| d|         }| |dz   d                                         } |                    |                                |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 "="Nr   z!missing attribute name before "="r   zmissing value after "%s="z'"zattribute "z" missing end quote ()z" end quote (z) not followed by whitespacer   r   )findr   striplstripr   r=   r   )rI   attlistequalsattnameendquoter   spaces          r   extract_name_valuer   p  s    G
  03R<< ///ww-%%''Q;;g; 57 7 7F1HII%%'' 	9 -79 9 97eyya!,,H2~~$n $q'''+, , , 4yy8a<''DA,>,D,D,F,F'$n&-ggtAwww89 9 9 (
#D
$++--DDIIcNNE{{FUF|E!GHH~,,...///A   0B Nr   c           	      n    t          | |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.   r2   r$   r(   )r    r*   r+   warning_streamr2   error_encodingerror_encoding_error_handler)source_pathsettingsreporters      r   new_reporterr     sB     X*H,?&hn(;	= = =H
 Or   c                     ddl m} ||                                }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&   )docutilsr   get_default_settingsr   r   r
   documentnote_source)r   r   r   r   r   s        r   new_documentr     sz    6 "!!!!!0022k**KK22H~hEEEHb)))Or   c                    t          |           dk    rut          | d         t          j                  rW| d         }|D ]N\  }}|                    |          }|r.t          j        |                    ||                    | d<    d S Kd S d S d S )Nr   r   )r   r,   r
   r   searchsub)r   keyword_substitutionstextnodepatternsubstitutionmatchs         r   clean_rcs_keywordsr     s    
9~~z)A,
CCQ<%: 	 	!G\NN8,,E $z'++lH*M*MNN	!	 	 	r   c                    t           j                            | p t          |          d                                        t           j                  }t           j                            |                              t           j                  }|dd         |dd         k    rd                    |          S |                                 |                                 |rR|rP|d         |d         k    r>|                                 |                                 |r|r|d         |d         k    >|                                 dgt          |          dz
  z  |z   }d                    |          S )a  
    Build and return a path to `target`, relative to `source` (both files).

    The return value is a `str` suitable to be included in `source`
    as a reference to `target`.

    :Parameters:
        `source` : path-like object or None
            Path of a file in the start directory for the relative path
            (the file does not need to exist).
            The value ``None`` is replaced with "<cwd>/dummy_file".
        `target` : path-like object
            End point of the returned relative path.

    Differences to `os.path.relpath()`:

    * Inverse argument order.
    * `source` is assumed to be a FILE in the start directory (add a "dummy"
      file name to obtain the path relative from a directory)
      while `os.path.relpath()` expects a DIRECTORY as `start` argument.
    * Always use Posix path separator ("/") for the output.
    * Use `os.sep` for parsing the input
      (changing the value of `os.sep` is ignored by `os.relpath()`).
    * If there is no common prefix, return the absolute path to `target`.

    Differences to `pathlib.PurePath.relative_to(other)`:

    * pathlib offers an object oriented interface.
    * `source` expects path to a FILE while `other` expects a DIRECTORY.
    * `target` defaults to the cwd, no default value for `other`.
    * `relative_path()` always returns a path (relative or absolute),
      while `PurePath.relative_to()` raises a ValueError
      if `target` is not a subpath of `other` (no ".." inserted).
    
dummy_fileNr4   /r&   z..r   )
osr   abspathrK   rl   sepr   reversepopr   )r'   targetsource_partstarget_partspartss        r   relative_pathr     si   F 7??6#G\T&\\,-G-G % %%*U26]] 7??6**0088LBQB<+++ xx%%% L B<#333	  L B<#333 Fc,''!+,|;E88E??r   c                     t          j        dt          d           | j        r/| j        r
J d            || j        }t          || j                  S | j        S )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.r4   r5   6stylesheet and stylesheet_path are mutually exclusive.)r7   r8   r9   stylesheet_path
stylesheet_destinationr   )r   relative_tos     r   get_stylesheet_referencer     s     M : %4 4 4 4  #& 	F 	FD	F 	F 	F"/K[(*BCCC""r   c                       j         r j        r
J d             j        p j         pg }t          |t                    sd |                    d          D             } j        r fd|D             }|S )zJ
    Retrieve list of stylesheet references from the settings object.
    r   c                 6    g | ]}|                                 S r   )r   ).0r   s     r   
<listcomp>z'get_stylesheet_list.<locals>.<listcomp>>  s     GGGtzz||GGGr   ,c                 :    g | ]}t          |j                  S r   )find_file_in_dirsstylesheet_dirs)r   r   r   s     r   r   z'get_stylesheet_list.<locals>.<listcomp>A  s6     0 0 0 )x/GHH 0 0 0r   )r   r   r,   listrl   )r   stylesheetss   ` r   get_stylesheet_listr   5  s     # F(@ F FDF F F*Gh.AGRKk4(( HGG0A0A#0F0FGGG 00 0 0 0#.0 0 0r   c                 >   t          |           } |                                 r|                                 S |D ]P}t          |                                          | z  }|                                r|                                c S Q|                                 S )z}
    Search for `path` in the list of directories `dirs`.

    Return the first expansion that matches an existing file.
    )r   is_absoluteas_posix
expanduserexists)r   dirsdfs       r   r   r   F  s     ::D }}    GG  4'88:: 	 ::<<	 ==??r   c                 f    |                      dd          t          | dd          dk    S | j        S )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_spaceNfootnote_referencessuperscript)rP   r/   r   )r   s    r   get_trim_footnote_ref_spacer   V  s<     :DAAIx!6==NN55r   c                 T    | r%| j         s| j        r| j         | j        fS | j        } | %dS )zk
    Return the "source" and "line" attributes from the `node` given or from
    its closest ancestor.
    rJ   )r'   rI   parent)nodes    r   rO   rO   e  sF    
  ; 	*$) 	*;	)){   :r   c                 :   g }d}	 |                      d|          }|dk    r2|                    | |d                    d                    |          S |                    | ||                    |                    d| |dz   |d	z            z              |d	z   })
z;Return a string with escape-backslashes converted to nulls.r   T\r&   Nr    r   r4   )r   r=   r   )textr   startfounds       r   escape2nullr   q  s    EE		$&&B;;LLeff&&&775>>!T%+&'''Vd5757?33444	r   c                 z    |                      d          }d |D             }t          t          j        |           S )zh
    Split `text` on escaped whitespace (null+space or null+newline).
    Return a list of strings.
    z  c                 8    g | ]}|                     d           S )z 
)rl   )r   strings     r   r   z,split_escaped_whitespace.<locals>.<listcomp>  s$    <<<&v||H%%<<<r   )rl   r   	itertoolschain)r   stringss     r   split_escaped_whitespacer     s=    
 jj!!G<<G<<<G	)***r   c                 @    d                     d | D                       S )Nr   c              3   B   K   | ]}t          j        |          |V  d S r   unicodedata	combiningr   cs     r   	<genexpr>z(strip_combining_chars.<locals>.<genexpr>  s2      CC+*?*B*BC1CCCCCCr   )r   r   s    r   strip_combining_charsr
    s#    77CCdCCCCCCr   c                 4    d t          |           D             S )u   Return indices of all combining chars in  Unicode string `text`.

    >>> from docutils.utils import find_combining_chars
    >>> find_combining_chars('A t̆ab̆lĕ')
    [3, 6, 9]

    c                 @    g | ]\  }}t          j        |          |S r   r  )r   ir  s      r   r   z(find_combining_chars.<locals>.<listcomp>  s,    FFF$!Q[-B1-E-EFAFFFr   )	enumerater	  s    r   find_combining_charsr    s     GF)D//FFFFr   c                     t          t          t          |                               }t          |           D ]}d||<   d |D             S )u   Indices of Unicode string `text` when skipping combining characters.

    >>> from docutils.utils import column_indices
    >>> column_indices('A t̆ab̆lĕ')
    [0, 1, 2, 4, 5, 7, 8]

    Nc                     g | ]}||S r   r   )r   r  s     r   r   z"column_indices.<locals>.<listcomp>  s    777!Ar   )r   rm   r   r  )r   string_indicesindexs      r   column_indicesr    sW     %D		**++N%d++ % % $u77~7777r   r4   r   )WFNaHNAc                 v    t          d | D                       }|t          t          |                     z  }|S )zqReturn the column width of text.

    Correct ``len(text)`` for wide East Asian and combining Unicode chars.
    c              3   T   K   | ]#}t           t          j        |                   V  $d S r   )east_asian_widthsr  east_asian_widthr  s     r   r  zcolumn_width.<locals>.<genexpr>  sF         "+">q"A"AB      r   )sumr   r  )r   widths     r   column_widthr!    sQ    
       E 
S%d++,,,ELr   c                 F    g }| D ]}||vr|                     |           |S r   )r=   )Lritems      r   uniqr&    s4    
A  q==HHTNNNHr   c                    |                                                      dd          } t          j        dd|           } d |                     d          D             }|                    d          f}g }t          t          |          dd          D ]E}t          j	        ||          D ]-}|
                    d                    ||z                        .F||z  }|S )aW  Return 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-c                     g | ]}|S r   r   )r   subtags     r   r   z*normalize_language_tag.<locals>.<listcomp>  s    333&v333r   r   r&   )r   r   rer   rl   r   rm   r   r   combinationsr=   r   )tagsubtagsbase_tagtaglistntagss         r   normalize_language_tagr4    s     ))++

c3
'
'C
&#Wc
2
2C33CIIcNN333GA HG3w<<B'' 4 4*7A66 	4 	4DNN388HTM223333	4xGNr   c                 T    | r|                                  dk    rd|  d}nd}d| dS )z{Return an XML text declaration.

    Include an encoding declaration, if `encoding`
    is not 'unicode', '', or None.
    unicodez encoding=""r   z<?xml version="1.0"z?>
)r   )r$   encoding_declarations     r   xml_declarationr9    sL      "HNN$$	118X888!;!5;;;;r   c                   2    e Zd ZdZd	dZd Zd Zd Zd ZdS )
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.
    Nr   c                 d    g | _         d| _        |r|                     |            | j        |  dS )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)r   file
set_outputadd)r   output_filedependenciess      r   r   zDependencyList.__init__  sA     		 	)OOK(((,r   c                 n    |r2|dk    rt           j        | _        dS t          |dd          | _        dS dS )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)r   stdoutr=  openr   r@  s     r   r>  zDependencyList.set_output  sK      	Ec!!J			 cGDDD					E 	Er   c                     |D ]r}t          |t                    r|                                }|| j        vr>| j                            |           | j        | j                            |dz              sdS )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,   r   r   r   r=   r=  rV   )r   pathsr   s      r   r?  zDependencyList.add  s      	/ 	/D$)) '}}49$$	  &&&9(IOODI...	/ 	/r   c                 l    | j         t          j        ur| j                                          d| _         dS )z(
        Close the output file.
        N)r=  r   rD  close)r   s    r   rJ  zDependencyList.close&  s0     9CJ&&IOO			r   c                 v    	 | j         j        }n# t          $ r d }Y nw xY w| j        j        d|d| j        dS )N(z, r   )r=  r   rS   r   r   r   rF  s     r   __repr__zDependencyList.__repr__.  sX    	).KK 	 	 	KKK	#~666TYYYOOs    )Nr   )	r   r   r   rk   r   r>  r?  rJ  rM  r   r   r   r;  r;    sv                E E E / / /  P P P P Pr   r;  abrcr   )alphabeta	candidatefinalc                     | t           } | j        rd| j        z  }nd}t          | j                 }| j        r| j        }nd}| j        rd}nd}| j        d| 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.%sr   z.dev.)r   microrelease_level_abbreviationsreleaselevelserialreleasemajorminor)version_inforW  rY  rZ  devversions         r   version_identifierra  =  s     ' ** .|/HIL $  G Nr   r   )7rk   __docformat__r   r   os.pathpathlibr   r   r,  r   r7   r  r   r   r   r   r	   r
   docutils.nodesr   r   r   r    ro   rr   rt   rv   r}   rx   ry   r   r   r   r   r   r   r   r   r   r   r   rO   r   r   r
  r  r  r  r!  r&  r4  r9  r;  rX  ra  r   r   r   <module>rf     s  
  # 



 				  " " " " " " " " 				          B B B B B B B B B B         # # # # # #    $   	 	 	 	 	/ 	 	 	JG JG JG JG JG JG JG JGZ , + + + +9 + + + 0 0 0 0 0) 0 0 0 4 4 4 4 4- 4 4 4 6 6 6 6 6/ 6 6 6; ; ;2     F  B & % % % %Y % % %  0* * *Z  $" " " "J  4 4 4n# # # #@  "   6 6 6	 	 	  + + +D D DG G G8 8 8    	 	 	    6
< 
< 
< 
<CP CP CP CP CP CP CP CPN 	             r   