B
    `*                 @   s  d 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 i Zdd ZeeZdd Zejoeeejd	d Zerdd
lmZ ddlmZ dd Zeddd  ejreddd  dd ZneZeZdd Zdd Z dd Z!dd Z"dd Z#dd Z$d d! Z%d"d# Z&d>d$d%Z'd&d' Z(G d(d) d)e)Z*d*d+ Z+G d,d- d-e)Z,d.d/ Z-G d0d1 d1e.Z/G d2d3 d3e/Z0G d4d5 d5e0Z1G d6d7 d7e1Z2G d8d9 d9e0Z3G d:d; d;e0Z4G d<d= d=e/Z5dS )?z$Miscellaneous stuff for coverage.py.    N)env)to_bytesunicode_classc             C   s`   | t krXt| j}|t | < x:t| D ].}t| |}t|tjrHt|}t||| q&W t |  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.
    )	ISOLATED_MODULEStypes
ModuleType__name__dirgetattr
isinstanceisolate_modulesetattr)modnew_modnamevalue r   U/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/coverage/misc.pyr      s    
r   c              O   s   dd }|S )z9Dummy no-op implementation of a decorator with arguments.c             S   s   | S )Nr   )funcr   r   r   
_decorator/   s    z-dummy_decorator_with_args.<locals>._decoratorr   )args_unusedkwargs_unusedr   r   r   r   dummy_decorator_with_args-   s    r   ZCOVERAGE_NO_CONTRACTS)contract)new_contractc              O   s(   yt | | W n tk
r"   Y nX dS )zEA proxy for contracts.new_contract that doesn't mind happening twice.N)raw_new_contract
ValueError)argskwargsr   r   r   r   ?   s    r   bytesc             C   s
   t | tS )N)r   r   )vr   r   r   <lambda>I       r!   unicodec             C   s
   t | tS )N)r   r   )r    r   r   r   r!   K   r"   c                s    fdd}|S )z1Ensure that only one of the argnames is non-None.c                s&   dd  dD   fdd}|S )Nc             S   s   h | ]}|  qS r   )strip).0r   r   r   r   	<setcomp>P   s    z-one_of.<locals>._decorator.<locals>.<setcomp>,c                 s6    fddD }t dd |D dks,t|  S )Nc                s   g | ]}  |qS r   )get)r%   r   )r   r   r   
<listcomp>R   s    z@one_of.<locals>._decorator.<locals>._wrapper.<locals>.<listcomp>c             s   s   | ]}|d k	V  qd S )Nr   )r%   valr   r   r   	<genexpr>S   s    z?one_of.<locals>._decorator.<locals>._wrapper.<locals>.<genexpr>   )sumAssertionError)r   r   vals)
argnamesetr   )r   r   _wrapperQ   s    z,one_of.<locals>._decorator.<locals>._wrapper)split)r   r1   )argnames)r0   r   r   r   O   s    zone_of.<locals>._decoratorr   )r3   r   r   )r3   r   one_ofM   s    r4   c              O   s   dS )z-Dummy no-op implementation of `new_contract`.Nr   )r   r   r   r   r   r   ]   s    c             C   s(   | \}}||krd| S d||f S d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-%dNr   )pairstartendr   r   r   	nice_pairb   s    r8   c                s*   t jr"dj   fdd}|S S dS )zA decorator to indicate that a method shouldn't be called more than once.

    Normally, this does nothing.  During testing, this raises an exception if
    called more than once.

    Z_once_c                s,   t |  rtdj t|  d | S )Nz'Shouldn't have called %s more than onceT)hasattrr.   r   r   )self)attrfnr   r   r1   z   s    
zexpensive.<locals>._wrapperN)r   TESTINGr   )r<   r1   r   )r;   r<   r   	expensivep   s
    
r>   c             C   s   | dkrdS t | S dS )z"Return bool(b), but preserve None.N)bool)br   r   r   bool_or_none   s    rA   c             C   s   d dd | D S )z<Combine a list of regexes into one that matches any of them.|c             s   s   | ]}d | V  qdS )z(?:%s)Nr   )r%   rr   r   r   r+      s    zjoin_regex.<locals>.<genexpr>)join)Zregexesr   r   r   
join_regex   s    rE   c          
   C   sD   yt |  W n0 tk
r> } z|jtjkr. W dd}~X Y nX dS )z9Remove a file, and don't get annoyed if it doesn't exist.N)osremoveOSErrorerrnoENOENT)pather   r   r   file_be_gone   s
    rM   c             C   s   | rt j| st |  dS )zVMake sure the directory exists.

    If `directory` is None or empty, do nothing.
    N)rF   rK   isdirmakedirs)	directoryr   r   r   
ensure_dir   s    rQ   c             C   s   t tj|  dS )z,Make sure the directory for the path exists.N)rQ   rF   rK   dirname)rK   r   r   r   ensure_dir_for_file   s    rS   c             C   s4   | dkrt j} t| ddp.tt jddp.t }|S )zHDetermine the encoding to use for output written to `outfile` or stdout.Nencoding)sysstdoutr
   
__stdout__localegetpreferredencoding)outfilerT   r   r   r   output_encoding   s    r[   c             C   s:   | dkr6t tddd}dt t |f } | S )zCompute a filename suffix for a data file.

    If `suffix` is a string or None, simply return it. If `suffix` is True,
    then build a suffix incorporating the hostname, process id, and a random
    number.

    Returns a string or None.

    T   r   i?B z
%s.%s.%06d)randomRandomrF   urandomrandintsocketgethostnamegetpid)suffixZdicer   r   r   filename_suffix   s    
re   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	HasherzHashes Python data into md5.c             C   s   t  | _d S )N)hashlibmd5)r:   r   r   r   __init__   s    zHasher.__init__c             C   s<  | j ttt| t|tr6| j |d nt|trN| j | n|dkrXnt|t	t
fr|| j tt| nt|ttfrx|D ]}| | qW nt|tr| }xtt|D ]}| | | ||  qW nJxHt|D ]<}|drqt||}t|rq| | | | qW | j d dS )z+Add `v` to the hash, recursively if needed.utf8N__   .)rh   updater   strtyper   r   encoder   intfloattuplelistdictkeyssortedr	   
startswithr
   inspect	isroutine)r:   r    rL   rv   kar   r   r   rm      s4    







zHasher.updatec             C   s
   | j  S )z$Retrieve the hex digest of the hash.)rh   	hexdigest)r:   r   r   r   r}      s    zHasher.hexdigestN)r   
__module____qualname____doc__ri   rm   r}   r   r   r   r   rf      s   rf   c             C   sD   t | drd}| j}nd}| j}dj|d}tdj|||ddS )	z7Helper to raise NotImplementedError in interface stubs._coverage_plugin_nameZPluginZClassz#{klass.__module__}.{klass.__name__})klassz1{thing} {name!r} needs to implement {func_name}())thingr   	func_nameN)r9   r   	__class__formatNotImplementedError)thatr   r   r   r   r   r   r   _needs_to_implement   s    
r   c               @   s    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.

    c             C   s
   || _ d S )N)
display_as)r:   r   r   r   r   ri     s    zDefaultValue.__init__c             C   s   | j S )N)r   )r:   r   r   r   __repr__  s    zDefaultValue.__repr__N)r   r~   r   r   ri   r   r   r   r   r   r     s   r   c                s$   d} fdd}t ||   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.

    a5  (?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,
                (?:
                    (?P<strict>\?) |        # with a strict marker
                    -(?P<defval>[^}]*)      # or a default value
                )?                      # maybe.
            }
        )
        c                sf   t dd | dddD }|dkr(dS |kr8| S | drXd| }t|n
| d	S d
S )zCalled for each $replacement.c             s   s   | ]}|r|V  qd S )Nr   )r%   gr   r   r   r+   1  s    z?substitute_variables.<locals>.dollar_replace.<locals>.<genexpr>dollarZword1Zword2$strictzVariable {} is undefined: {!r}ZdefvalN)nextgroupr   CoverageException)matchwordmsg)text	variablesr   r   dollar_replace.  s    

z,substitute_variables.<locals>.dollar_replace)resub)r   r   Zdollar_patternr   r   )r   r   r   substitute_variables  s    r   c               @   s   e Zd ZdZdS )BaseCoverageExceptionz$The base of all Coverage exceptions.N)r   r~   r   r   r   r   r   r   r   @  s   r   c               @   s   e Zd ZdZdS )r   z.An exception raised by a coverage.py function.N)r   r~   r   r   r   r   r   r   r   E  s   r   c               @   s   e Zd ZdZdS )NoSourcez)We couldn't find the source for a module.N)r   r~   r   r   r   r   r   r   r   J  s   r   c               @   s   e Zd ZdZdS )NoCodez!We couldn't find any code at all.N)r   r~   r   r   r   r   r   r   r   O  s   r   c               @   s   e Zd ZdZdS )	NotPythonz3A source file turned out not to be parsable Python.N)r   r~   r   r   r   r   r   r   r   T  s   r   c               @   s   e Zd ZdZdS )ExceptionDuringRunzAn exception happened while running customer code.

    Construct it with three arguments, the values from `sys.exc_info`.

    N)r   r~   r   r   r   r   r   r   r   Y  s   r   c               @   s   e Zd ZdZdS )StopEverythingzAn exception that means everything should stop.

    The CoverageTest class converts these to SkipTest, so that when running
    tests, raising this exception will automatically skip the test.

    N)r   r~   r   r   r   r   r   r   r   b  s   r   )N)6r   rI   rg   ry   rX   rF   os.pathr]   r   ra   rU   r   Zcoverager   Zcoverage.backwardr   r   r   r   r   r=   r?   rq   environr(   ZUSE_CONTRACTSZ	contractsr   r   r   PY3r4   r8   r>   rA   rE   rM   rQ   rS   r[   re   objectrf   r   r   r   	Exceptionr   r   r   r   r   r   r   r   r   r   r   <module>   sb   


		
(1	