o
    tPfJ                     @   sb  d dl mZmZ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mZ ddlmZ d dlmZ d dlmZ d dlmZ d	Zeejd
dZG dd de
jZi ddddddddddddddddddddddddd dd!d"d#dd$dd%d&d'dd(dd)Zg d*Zd d d+d,d-d.d.d/d0d1d2d2d2d3Zd4d5 Zd6d7 Zdfd8d9Zd:d; Z d<d Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%h dEZ&h dFZ'dgdGdHZ(dhdIdJZ)G dKdL dLe*Z+dMdN Z,e	- Z.dOdP Z/dQdR Z0G dSdT dTe1Z2dUdV Z3didXdYZ4dZd[ Z5d\d] Z6d^d_ Z7G d`da dae*Z8G dbdc dce8ej9Z:G ddde dee	j;Z<dS )j    )print_functionabsolute_importdivisionN)sleep   )six)validate_bool)perf_counter)get_originalFGEVENTTEST_QUIET0c                   @   s$   e Zd ZdZdZdd Zdd ZdS )Popenz
    Depending on when we're imported and if the process has been monkey-patched,
    this could use cooperative or native Popen.
    Nc                 C   s   | S N selfr   r   T/var/www/html/humari/django-venv/lib/python3.10/site-packages/gevent/testing/util.py	__enter__   s   zPopen.__enter__c                 G   s   t |  d S r   )kill)r   argsr   r   r   __exit__"      zPopen.__exit__)__name__
__module____qualname____doc__timerr   r   r   r   r   r   r      s
    r   normaldefaultzactual-outputredzcharacter-diffsmagentadebugcyanz
diff-chunkerror	brightredzerror-number	exceptionzexpected-outputgreenzfailed-examplefilename	lightblueinfolinenolightrednumberz	ok-numberskippedbrightyellowbrightmagenta	lightcyan)	slow-testsuboptimal-behaviourtestnamewarning))darkz0;)light1;)brightr7   )boldr7             !   "   #   $   %   )r   r   blackr   r&   brownyellowbluer    r"   greygraywhitec                 C   sH   d}t D ]\}}| |r| t|d  } |} nqt|  }d||f S )N z[%s%sm)	_prefixes
startswithlen_colorcodes)colorprefix_codeprefixcode
color_coder   r   r   _color_codeW   s   
rS   c                 C   s   t t|  S r   )rS   _colorscheme)whatr   r   r   _colora   r   rV   c                 C   s   t | | t | S r   )rV   )rU   messager   r   r   r   	_colorized   s   rX   c                 O   sb   | dd}|r| | }n| }t||}t tj|d  W d   dS 1 s*w   Y  dS )zV
    Log a *message*

    :keyword str color: One of the values from _colorscheme
    rN   r   
N)poprX   output_locksysstderrwrite)rW   r   kwargsrN   stringr   r   r   logg   s   

"ra   c                 O   s.   t s|dd t| g|R i | dS dS )z<
    Log the *message* only if we're not in quiet mode.
    rN   r!   N)QUIET
setdefaultra   )rW   r   r_   r   r   r   r!   x   s   c              
   C   s   t tdsd S zt| dW S  ty7 } z|jdkr,td| t|j| W Y d }~d S W Y d }~d S d }~w tyS } ztd| t|j| W Y d }~d S d }~ww )Nkillpg	      zkillpg(%r, 9) failed: %s: %s)	hasattrosrd   OSErrorerrnora   typer   	Exception)pidexr   r   r   rd      s   

""rd   c                 C   sL   d|  }t d|  tjd d }|r"| |dfvr$td| d S d S d S )Nz"ERROR: The process "%s" not found.ztaskkill /F /PID %s /T)r]   r   rI   z%r)r   
subprocessPIPEcommunicatestripra   )rm   
ignore_msgerrr   r   r   kill_processtree   s
   ru   c              
   C   s   t | dr2z|   W d S  ty1 } z|jdkr W Y d }~d S |jdkr,W Y d }~d S  d }~ww z
t| jd W d S  tyF   Y d S w )Nr   rf      re   )rg   r   ri   rj   rh   rm   EnvironmentError)popenrn   r   r   r   _kill   s    


ry   c                 C   s   | j d ur| j   d | _ |  d urd S d| _zt| dd r%t| j ntj	dr0t
| j W n ty>   t  Y nw zt|  W n tyR   t  Y nw z|   W d S  tyh   t  Y d S w )NTsetpgrp_enabledwin)r   cancelpoll
was_killedgetattrrd   rm   r\   platformrK   ru   rl   	traceback	print_excry   waitrx   r   r   r   r      s2   


r   >   GEVENT_DEBUGr   GEVENTSETUP_EMBEDGEVENTSETUP_EV_VERIFY>   GEVENT_RESOLVERthreadGEVENTTEST_USE_RESOURCESallGEVENT_RESOLVER_NAMESERVERSz8.8.8.8c                 C   s   g }|pt j }||pi  t| D ]\}}|ds q|tv r%q||ftv r,q|	d||f  qt
| tjrB|	|  n||  d|S )NGEVENTz%s=%s )rh   environcopyupdatesorteditemsrK   IGNORED_GEVENT_ENV_KEYSIGNORED_GEVENT_ENV_ITEMSappend
isinstancer   string_typesextendjoin)commandenvsetenvresultkeyvaluer   r   r   getname   s   


r   c           
      K   s   | dd }d }tjdsttdd }| dd }| dd p!i }t| ||d}|d ur1d|d< |rC|r9| ntj }|| |sJtd| t	| f||d	|}||_
|d u|_d
|_|d ur|tdd|t|fd}	|	|_d|	_|	  |	|_|S )NtimeoutDO_NOT_SETPGRPsetpgrpr   r   )r   r   1z+ %s)
preexec_fnr   F	threadingTimer)r   T)rZ   rh   r   getr   r   r   r   ra   r   namerz   r~   r
   r   r   daemonstart)
r   quietr_   r   r   r   r   r   rx   tr   r   r   r      s2   


r   c                   @   sL   e Zd ZdZ					dddZedd Zdd	 ZeZd
d Z	dd Z
dS )	RunResultz
    The results of running an external command.

    If the command was successful, this has a boolean
    value of True; otherwise, a boolean value of false.

    The integer value of this object is the command's exit code.
    Nr   c
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   )	r   
run_kwargsrQ   outputr#   r   	run_countskipped_countrun_duration)
r   r   r   rQ   r   r#   r   r   r   r   r   r   r   __init__	  s   

zRunResult.__init__c                 C   s
   | j  S r   )r   
splitlinesr   r   r   r   output_lines  s   
zRunResult.output_linesc                 C   s   t | j S r   )boolrQ   r   r   r   r   __bool__!  r   zRunResult.__bool__c                 C   s   | j S r   )rQ   r   r   r   r   __int__&  s   zRunResult.__int__c                 C   s   d| j | j| j| j| jf S )NzLRunResult of: %r
Code: %s
kwargs: %r
Output:
----
%s----
Error:
----
%s----
)r   rQ   r   r   r#   r   r   r   r   __repr__)  s   zRunResult.__repr__)NNNr   r   r   )r   r   r   r   r   propertyr   r   __nonzero__r   r   r   r   r   r   r      s    

r   c                 C   sd   d| v r.|  dd} |  dd} |  dd} |  dd} |  dd} |  dd} |  d	d} d| v S )
NWarningzWarning -- reap_childrenNADAzWarning -- threading_cleanupz/DeprecationWarning: Using or importing the ABCsz UserWarning: libuv only supportsz&ImportWarning: Not importing directoryz*DeprecationWarning: 'U' mode is deprecatedz#DeprecationWarning: dns.hash module)replace)outr   r   r   _should_show_warning_output?  s   r   c                 C   s   d}d}d}d}|rSt d|}|r0|| |  }|d|}t||d|d }t d|}|rStd|| |  }t||d|d }|| |f }| d	krbtd
|}|||fS )Nz[took %.1fs%s]rI   r   zRan (\d+) tests intookr   z \(skipped=(\d+)\)$r-   
   r1   )researchr   endr   intrX   )r   r   statusr-   r   r   mr   r   r   r   _find_test_statusX  s$   

r   c                 K   s  | dt}| dt}| }| dd}| dd}|r3d|vr%d|vs)J |tj|d< tj|d< t| fd|i|}|j}z+t }	|	 \}
}t |	 }|j
sX| d	u r[d
}n| }W t| |jd	u skJ nt| |jd	u swJ w t|o||v}|
r|
 }
t|
tr|
n|
dd}
|
r|s|st|
rd|
dd }
|
 }
|
d7 }
td||
 t||
\}}}|rtd||||rdndd n|std|| t| |||v rdn||
|||||d	S )zv
    Execute *command*, returning a `RunResult`.

    This blocks until *command* finishes or until it times out.
    buffer_outputr   nestedFallowed_return_codesr   stdoutr]   NTIMEOUTzutf-8ignorez  rY   z
  z| %s
%sz! %s [code %s] %sr#   r2   )rN   z- %s %sr   )r   r#   r   r   r   r   )rZ   BUFFER_OUTPUTrb   ro   STDOUTrp   r   r   r	   rq   r~   r}   r   r   r   rr   r   strdecoder   r   rstripra   r   r   )r   r_   r   r   verboser   r   rx   r   
time_startr   rt   durationr   failedr   r   r   r   r   r   runn  s`   




r   c                   @   s   e Zd ZdZdS )NoSetupPyFoundzRaised by find_setup_py_aboveN)r   r   r   r   r   r   r   r   r     s    r   c                 C   sl   t jt j| }t jt j|ds4|t j|}}||kr)td| f t jt j|dr|S )zAReturn the directory containing setup.py somewhere above *a_file*zsetup.pyz#could not find my setup.py above %r)rh   pathdirnameabspathexistsr   r   )a_filerootprevr   r   r   find_setup_py_above  s   r   Tc                 C   s   | d urzt | W S  ty   Y nw |d ur+z
t tj|j jW S  ty*   Y nw |d urBz	t tj| jW S  tyA   Y nw |rHt dS tdt f )Nz./dnezAfter checking %r)r   r   r\   modulesr   __file__locals)r   a_module_namea_class	climb_cwdr   r   r   search_for_setup_py  s*   
r   c                  C   sF   dt jd d  } dt jd d  }tt dr| d7 } |d7 }| |fS )N%s.%s   %s.%s.%srf   pypy_version_infopypy)r\   version_inforg   )	directoryfull_directoryr   r   r   _version_dir_components  s   
r   c                  C   s   t td} tj| dd}t \}}dtjdd  }dtjdd  }ttd	r1|d
7 }|d
7 }tj||}tj||}||fS )z
    Return a sequence of directories that could contain
    stdlib tests for the running version of Python.

    The most specific tests are at the end of the sequence.

    No checks are performed on existence of the directories.
    )r   src	greentestr   Nr   r   rf   r   r   )	r   r   rh   r   r   r   r\   r   rg   )setup_pyr   r   r   r   r   r   find_stdlib_tests  s   
	

r   c                  C   s>   dt jvrdS t jd } dd | t jjD } t jj| S )z
    Return the PYTHONPATH environment variable (if set) with each
    entry being an absolute path. If not set, returns None.
    
PYTHONPATHNc                 S   s   g | ]}t j|qS r   )rh   r   r   ).0pr   r   r   
<listcomp>  s    z'absolute_pythonpath.<locals>.<listcomp>)rh   r   splitr   pathsepr   )r   r   r   r   absolute_pythonpath  s
   

r  c                   @   s\   e Zd ZdZg ZdZdZdZdZdd Z	e
dd Ze
d	d
 Zdd Zdd Zdd ZdS )ExampleMixinz
    Something that uses the ``examples/`` directory
    from the root of the gevent distribution.

    The `cwd` property is set to the root of the gevent distribution.
    rf   g      ?Nc                 C   s   t tt| dS )z(Return the directory containing setup.py)r   r   )r   r   rk   r   r   r   r   find_setup_py  s   zExampleMixin.find_setup_pyc              
   C   sD   z|   }W n ty } ztd|f d }~ww tj|dS )N$Unable to locate file/dir to run: %sexamples)r  r   unittestSkipTestrh   r   r   )r   r   er   r   r   cwd  s   zExampleMixin.cwdc                 C   s   t  }|r	d|iS dS )a"  
        Returns a dictionary of environment variables to set for the
        child in addition to (or replacing) the ones already in the
        environment.

        Since the child is run in `cwd`, relative paths in ``PYTHONPATH``
        need to be converted to absolute paths.
        r   N)r  )r   abs_pythonpathr   r   r   r     s   
zExampleMixin.setenvc              
   C   s   t | dd rtd| | jt | dd rtd| | jz| j}| j}W n ty6 } ztd|f d }~ww | j	p;i }| j
}|rQd|v rM|d | n||d< |tjddd|g| j fd	|i|S )
Nr   zInvalid testserverr  r   z-Wr   z-ur
  )r   AssertionErrorr   r  exampler
  r   r  r  start_kwargsr   r   r\   
executableexample_args)r   methr  
server_dirr	  r_   r   r   r   r   _start,  s0   

zExampleMixin._startc                 C      | j tdS N)r  )r  r   r   r   r   r   start_exampleF  r   zExampleMixin.start_examplec                 C   r  r  )r  r   r   r   r   r   run_exampleI  r   zExampleMixin.run_example)r   r   r   r   r  before_delayafter_delayr  r  r  r   r
  r   r  r  r  r   r   r   r   r     s    

r  c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
TestServerNc                    s"   ddl m} | fdd}| S )Nr   )contextmanagerc                  3   sL       } |  _   d V     W d    d S 1 sw   Y  d S r   )r  rx   beforeafterr   r   r   r   running_serverT  s   

"z1TestServer.running_server.<locals>.running_server)
contextlibr  )r   r  r  r   r   r   r  Q  s   zTestServer.running_serverc                 C   s6   |    |   W d    d S 1 sw   Y  d S r   )r  _run_all_testsr   r   r   r   test]  s   

"zTestServer.testc                 C   :   | j d ur
t| j  | | j d| j| j f  d S Nz%s died with code %s)r  r   assertIsNonerx   r}   r  r   r   r   r   r  a     

zTestServer.beforec                 C   r#  r$  )r  r   r%  rx   r}   r  r   r   r   r   r  i  r&  zTestServer.afterc                 C   sH   d}t t| D ]}|drt| |}t|r|  d}q|s"J d S )NF_testT)r   dirrK   r   callable)r   ranmethodfunctionr   r   r   r!  q  s   

zTestServer._run_all_tests)	r   r   r   rx   r  r"  r  r  r!  r   r   r   r   r  M  s    r  c                   @   s   e Zd Zdd Zdd ZdS )alarmc                 C   s$   t j|  d| _|| _|   d S )NT)r   Threadr   r   r   r   )r   r   r   r   r   r     s   zalarm.__init__c                 C   s$   t | j tjd td d S )Nz	Timeout.
   )r   r   r\   r]   r^   rh   _exitr   r   r   r   r     s   
z	alarm.runN)r   r   r   r   r   r   r   r   r   r-  |  s    r-  )r   )NN)F)NNNT)=
__future__r   r   r   r   r\   rh   r   r  r   ro   timer   rI   r   gevent._configr   gevent._compatr	   gevent.monkeyr
   r   r   r   rb   r   rT   rJ   rM   rS   rV   rX   ra   r!   rd   ru   ry   r   r   r   r   r   objectr   r   Lockr[   r   r   rl   r   r   r   r   r   r  r  TestCaser  r.  r-  r   r   r   r   <module>   s    	


	

@>

	M/