
    L-Ph+                    <   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Zddl
Z
ddlZddlZddlZddlZddlZddlmZ ddlmZmZmZ ddlmZmZmZmZ ddlmZ ddlmZ dd	lT i Zd
ed<   dQdZ  e e          Z G d d          Z!ej"        dRd            Z#dSdZ$dTdZ%dUdZ&dVd!Z'dWd$Z(dXd&Z)dWd'Z* G d( d)          Z+dYd-Z, G d. d/          Z-dZd3Z.d[d6Z/d\d]d9Z0ej1        d^d<            Z2d_d?Z3 ed@ee         A          Z4	 d`dadHZ5dbdcdNZ6dddPZ7dS )ez$Miscellaneous stuff for coverage.py.    )annotationsN)
ModuleType)AnyNoReturnTypeVar)IterableIteratorMappingSequence)CoverageException)TArc)*zdict[ModuleType, ModuleType]ISOLATED_MODULESmodr   returnc                ,   | t           vrt          j        | j                  }|t           | <   t	          |           D ]L}t          | |          }t          |t          j                  rt          |          }t          |||           Mt           |          S )aJ  Copy a module so that we are isolated from aggressive mocking.

    If a test suite mocks os.path.exists (for example), and then we need to use
    it during the test, everything will get tangled up if we use their mock.
    Making a copy of the module when we import it will isolate coverage.py from
    those complications.
    )	r   typesr   __name__dirgetattr
isinstanceisolate_modulesetattr)r   new_modnamevalues       M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/misc.pyr   r   '   s     """"3<00 'HH 	* 	*DC&&E%!122 .&u--GT5))))C      c                  "    e Zd ZdZddZddZdS )SysModuleSaverzASaves the contents of sys.modules, and removes new modules later.r   Nonec                B    t          t          j                  | _        d S Nsetsysmodulesold_modulesselfs    r   __init__zSysModuleSaver.__init__>   s    s{++r   c                l    t          t          j                  | j        z
  }|D ]}t          j        |= dS )z6Remove any modules imported since this object started.Nr$   )r*   new_modulesms      r   restorezSysModuleSaver.restoreA   s=    #+&&)99 	 	AA	 	r   Nr   r!   )r   
__module____qualname____doc__r+   r/    r   r   r    r    <   sB        KK, , , ,     r   r    Iterator[None]c               #     K   t                      } 	 dV  |                                  dS # |                                  w xY w)z@A context manager to remove any modules imported during a block.N)r    r/   )savers    r   sys_modules_savedr8   H   sD       Es	   , Amodnamestrtuple[ModuleType, bool]c                    t                      5  	 t          j        |           dfcddd           S # t          $ r t          dfcY cddd           S w xY w# 1 swxY w Y   dS )a  Import a third-party module we need, but might not be installed.

    This also cleans out the module after the import, so that coverage won't
    appear to have imported it.  This lets the third party use coverage for
    their own tests.

    Arguments:
        modname (str): the name of the module to import.

    Returns:
        The imported module, and a boolean indicating if the module could be imported.

    If the boolean is False, the module returned is not the one you want: don't use it.

    TNF)r8   	importlibimport_moduleImportErrorr&   )r9   s    r   import_third_partyr@   R   s      
		  	*733T9         	 	 	:	       	         s,   A3AAAAAApairr   c                0    | \  }}||k    rd|z  S d||fz  S )zMake a nice string representation of a pair of numbers.

    If the numbers are equal, just return the number, otherwise return the pair
    with a dash between them, indicating the range.

    z%dz%d-%dr4   )rA   startends      r   	nice_pairrE   i   s/     JE3||e|%%%r   br   bool | Nonec                (    | dS t          |           S )z"Return bool(b), but preserve None.N)bool)rF   s    r   bool_or_nonerJ   w   s    ytAwwr   regexesIterable[str]c                    t          |           } t          |           dk    r| d         S d                    d | D                       S )zDCombine a series of regex strings into one that matches any of them.   r   |c              3  "   K   | ]
}d | dV  dS )z(?:)Nr4   ).0rs     r   	<genexpr>zjoin_regex.<locals>.<genexpr>   s*      44q
a


444444r   )listlenjoin)rK   s    r   
join_regexrX      sI    7mmG
7||qqzxx44G444444r   pathr!   c                    	 t          j        |            dS # t          $ r!}|j        t          j        k    r Y d}~dS d}~ww xY w)z9Remove a file, and don't get annoyed if it doesn't exist.N)osremoveOSErrorerrnoENOENT)rY   es     r   file_be_gonera      s]    
	$   7el"" #"""""s    
A>A	directoryc                :    | rt          j        | d           dS dS )zVMake sure the directory exists.

    If `directory` is None or empty, do nothing.
    T)exist_okN)r[   makedirs)rb   s    r   
ensure_dirrf      s1    
  .
I------. .r   c                ^    t          t          j                            |                      dS )z,Make sure the directory for the path exists.N)rf   r[   rY   dirname)rY   s    r   ensure_dir_for_fileri      s$    rwt$$%%%%%r   c                  *    e Zd ZdZddZddZdd	Zd
S )Hasherz&Hashes Python data for fingerprinting.r   r!   c                <    t          j        dd          | _        d S )Nsha3_256F)usedforsecurity)hashlibnewhashr)   s    r   r+   zHasher.__init__   s    K
EBBB			r   vr   c                   | j                             t          t          |                                        d                     t          |t                    r/| j                             |                    d                     nt          |t                    r| j                             |           nv|nrt          |t          t          f          r<| j                             t          |                              d                     nt          |t          t          f          r|D ]}|                     |           nt          |t                    rW|                                }t          |          D ]2}|                     |           |                     ||                    3nwt          |          D ]g}|                    d          rt!          ||          }t#          j        |          r=|                     |           |                     |           h| j                             d           dS )z+Add `v` to the hash, recursively if needed.zutf-8N__   .)rq   updater:   typeencoder   bytesintfloattuplerU   dictkeyssortedr   
startswithr   inspect	isroutine)r*   rr   r`   r~   kas         r   rv   zHasher.update   s   	T!WW,,W55666a 	IQXXg..////5!! 	IQYC<(( 	ISVV]]7334444E4=)) 	  A4   	6688DD\\ " "AAaD!!!!" VV  <<%% AqMM$Q'' AA	r   r:   c                D    | j                                         dd         S )z$Retrieve the hex digest of the hash.N    )rq   	hexdigestr)   s    r   r   zHasher.hexdigest   s    y""$$SbS))r   Nr0   )rr   r   r   r!   r   r:   )r   r1   r2   r3   r+   rv   r   r4   r   r   rk   rk      sZ        00C C C C   <* * * * * *r   rk   that	func_namer   c                    t          | d          r
d}| j        }nd}| j        }|j         d|j         }t          | d|d| d          )z7Helper to raise NotImplementedError in interface stubs._coverage_plugin_namePluginClass. z needs to implement z())hasattrr   	__class__r1   r   NotImplementedError)r   r   thingr   klasss        r   _needs_to_implementr      sv    t,-- 6)"55U^55
<<4<<y<<<  r   c                  "    e Zd ZdZd	dZd
dZdS )DefaultValuezA sentinel object to use for unusual default-value needs.

    Construct with a string that will be used as the repr, for display in help
    and Sphinx output.

    
display_asr:   r   r!   c                    || _         d S r#   r   )r*   r   s     r   r+   zDefaultValue.__init__   s    $r   c                    | j         S r#   r   r)   s    r   __repr__zDefaultValue.__repr__   s
    r   N)r   r:   r   r!   r   )r   r1   r2   r3   r+   r   r4   r   r   r   r      sF         % % % %     r   r   text	variablesMapping[str, str]c                P     d}dd fd}t          j        ||             S )	a  Substitute ``${VAR}`` variables in `text` with their values.

    Variables in the text can take a number of shell-inspired forms::

        $VAR
        ${VAR}
        ${VAR?}             strict: an error if VAR isn't defined.
        ${VAR-missing}      defaulted: "missing" if VAR isn't defined.
        $$                  just a dollar sign.

    `variables` is a dictionary of variable values.

    Returns the resulting text with values substituted.

    aV  (?x)   # Use extended regex syntax
        \$                      # A dollar sign,
        (?:                     # then
            (?P<dollar> \$ ) |      # a dollar sign, or
            (?P<word1> \w+ ) |      # a plain word, or
            \{                      # a {-wrapped
                (?P<word2> \w+ )        # word,
                (?:                         # either
                    (?P<strict> \? ) |      # with a strict marker
                    -(?P<defval> [^}]* )    # or a default value
                )?                      # maybe.
            }
        )
        )dollarword1word2matchre.Match[str]r   r:   c                    t          d  | j         D                       }|dk    rdS |v r|         S | d         rd| d}t          |          | d         S )zCalled for each $replacement.c              3     K   | ]}||V  	d S r#   r4   )rR   gs     r   rT   z?substitute_variables.<locals>.dollar_replace.<locals>.<genexpr>  s'      @@!a@A@@@@@@r   $strictz	Variable z is undefined: defval)nextgroupr   )r   wordmsgdollar_groupsr   r   s      r   dollar_replacez,substitute_variables.<locals>.dollar_replace  s     @@{u{M:@@@@@3;;3YT?"8_ 	#;d;;4;;C#C(((?"r   )r   r   r   r:   )resub)r   r   dollar_patternr   r   s   ``  @r   substitute_variablesr      sU     N 1M# # # # # # # # 6..$77DKr   dtdatetime.datetimec                P    |                                                      d          S )z?Return a string with local timezone representing the date.
    z%Y-%m-%d %H:%M %z)
astimezonestrftime)r   s    r   format_local_datetimer     s!     ==??##$7888r   modfile
str | Nonec                    || dz   }t           j                            | |          }|J t           j                            |          }|t          j        | <   |j        J |j                            |           |S )zImport a local file as a module.

    Opens a file in the current directory named `modname`.py, imports it
    as `modname`, and returns the module object.  `modfile` is the file to
    import if it isn't in the current directory.

    Nz.py)r=   utilspec_from_file_locationmodule_from_specr&   r'   loaderexec_module)r9   r   specr   s       r   import_local_filer     s     E/>11'7CCD
.
)
)$
/
/CCK;"""KC   Jr   stuple[list[str | int], str]c                R    ddfdt          j        d|           D             | fS )	zTurn a string into a list of string and number chunks.

    "z23a" -> (["z", 23, "a"], "z23a")

    The original string is appended as a last value to ensure the
    key is unique enough so that "x1y" and "x001y" can be distinguished.
    r   r:   r   	str | intc                F    	 t          |           S # t          $ r | cY S w xY w)z6If `s` is a number, return an int, else `s` unchanged.)rz   
ValueError)r   s    r   tryintz_human_key.<locals>.tryint:  s6    	q66M 	 	 	HHH	s      c                &    g | ]} |          S r4   r4   )rR   cr   s     r   
<listcomp>z_human_key.<locals>.<listcomp>A  s!    6661VVAYY666r   z(\d+))r   r:   r   r   )r   split)r   r   s    @r   
_human_keyr   1  sD        76661 5 5666::r   strings	list[str]c                .    t          | t                    S )zSort the given iterable of strings the way that humans expect.

    Numeric components in the strings are sorted as numbers.

    Returns the sorted list.

    )key)r   r   )r   s    r   human_sortedr   C  s     'z****r   SortableItem)boundFitemsIterable[SortableItem]reverserI   list[SortableItem]c                (    t          | d |          S )zSort (string, ...) items the way humans expect.

    The elements of `items` can be any tuple/list. They'll be sorted by the
    first element (a string), with ties broken by the remaining elements.

    Returns the sorted list of items.
    c                D    t          | d                   g| dd          R S )Nr   rN   )r   )items    r   <lambda>z$human_sorted_items.<locals>.<lambda>Z  s%    :d1g+>+>*Jabb*J*J r   )r   r   )r   )r   r   s     r   human_sorted_itemsr   O  s     %JJT[\\\\r    nrz   r   thingsc                     | dk    r|S |p|dz   S )zZPluralize a word.

    If n is 1, return thing.  Otherwise return things, or thing+s.
    rN   r   r4   )r   r   r   s      r   pluralr   ]  s!    
 	Avv&%#+&r   urlc                    t          t          j        d          r't          j                                        r	d| d|  dS | S )zFormat text+url as a clickable link for stdout.

    If attached to a terminal, use escape sequences. Otherwise, just return
    the text.
    isattyz]8;;z]8;;)r   r&   stdoutr   )r   r   s     r   stdout_linkr   h  sK     sz8$$ ):):)<)< 1#111111r   )r   r   r   r   )r   r5   )r9   r:   r   r;   )rA   r   r   r:   )rF   r   r   rG   )rK   rL   r   r:   )rY   r:   r   r!   )rb   r:   r   r!   )r   r   r   r:   r   r   )r   r:   r   r   r   r:   )r   r   r   r:   r#   )r9   r:   r   r   r   r   )r   r:   r   r   )r   rL   r   r   )F)r   r   r   rI   r   r   )r   r   )r   rz   r   r:   r   r:   r   r:   )r   r:   r   r:   r   r:   )8r3   
__future__r   
contextlibdatetimer^   	functoolsro   r=   importlib.utilr   r[   os.pathr   r&   r   r   typingr   r   r   collections.abcr   r	   r
   r   coverage.exceptionsr   coverage.typesr   r   __annotations__r   r    contextmanagerr8   r@   rE   rJ   rX   ra   rf   ri   rk   r   r   r   r   r   cacher   r   r   r   r   r   r4   r   r   <module>r      s   + * * " " " " " "                     				  				 



                 B A A A A A A A A A A A 1 1 1 1 1 1      
 " ! ! !13  3 3 3 3! ! ! !$ ^B	 	 	 	 	 	 	 	       .& & & &   5 5 5 5   . . . .& & & &
%* %* %* %* %* %* %* %*P          0 0 0 0f9 9 9 9    ( ; ; ; ;"+ + + + w~Xc];;; ] ] ] ] ]' ' ' ' '	 	 	 	 	 	r   