o
    NEgY                     @   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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dlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ dd	l,m-Z- dd
l.m/Z/ ddl0Z0ddl1Z1ddl2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z? dZ@ejAdkZBejAdkZCejAdkZDeCsddlEZEeEF  zddlmGZG W n eHy   ddl5mGZG Y nw 	dde$ejI de&d fddZJeCr	eKedZJe)dZLe)dZMeN ZOePe	jQRdZSeKejTdd p1ejTjU o1ePe	jQRd!ZVd"d# eWdd$D ZXd%d# eWdd&D eYd'hB ZZd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9eYd:hZ[eXeZA e[A Z\G d;d< d<Z]G d=d> d>ed>g d?Z^d@e8de'e8e$e^ f fdAdBZ_de$ej fdCdDZ`e1jadEdEdEdFG dGdH dHZbdeecebf fdIdJZd	dde$ejI ddKfdLdMZe	dde$ejI dejIfdNdOZfdPedePfdQdRZge1jadEdEdEdFG dSdT dTZhejidUdVdWecdehfdXdYZjddPedZe$ec de$ec fd[d\Zk	Edd]ecd^ePd_ecdecfd`daZlG dbdc dce6ZmG ddde deeeL ZnenZozddflpmnZq eSs2eqZnW n
 eHy=   Y nw dgZrdhZseterZuejtesejvdiZweterxdjZyejtesxdjejvdiZzdke%ec dle%e{ dme$e*ece{f  dePfdndoZ|e}e|eueyZ~e}e|ewezZdme$e*ece{eef  dePfdpdqZdejfdrdsZdadtadecfdudvZdwdx Zdydz Zd{d| ZG d}d~ d~ZG dd deGd ZG dd deZG dd deZG dd de0jZG dd dZdddeLddfddZdddeddfddZG dd de#ecef ZdS )zVarious helper functions    N)
namedtuple)suppress)ceil)Path)TracebackType)AnyCallableDict	GeneratorGenericIterableIteratorListMappingOptionalPatternSetTupleTypeTypeVarUnioncast)quote)
getproxies)	MultiDictMultiDictProxy)ProtocolURL   )hdrs)client_loggerinternal_logger)PathLike)	BasicAuthChainMapProxy)      )r&      )r&      )ContextManagerloopreturnzasyncio.Task[Any]c                 C   s   t tj| }dd |D S )Nc                 S   s   h | ]}|  s|qS  )done).0tr-   r-   i/var/www/eduai.edurigo.com/doc_train/edurigo_ai/Puru/venv/lib/python3.10/site-packages/aiohttp/helpers.py	<setcomp>L   s    zall_tasks.<locals>.<setcomp>)listasyncioTask	all_tasks)r+   tasksr-   r-   r1   r6   H   s   r6   _T_SAIOHTTP_NO_EXTENSIONSdev_modeFPYTHONASYNCIODEBUGc                 C      h | ]}t |qS r-   chrr/   ir-   r-   r1   r2   a       r2      c                 C   r=   r-   r>   r@   r-   r-   r1   r2   b   rB          ()<>@,;:\"/[]?={} 	   c                   @   s   e Zd Zded fddZdS )noopr,   )NNNc                 c   s    d V  d S Nr-   selfr-   r-   r1   	__await__~   s   
znoop.__await__N)__name__
__module____qualname__r
   r]   r-   r-   r-   r1   rY   }   s    rY   c                	       s   e Zd ZdZ	ddedededd f fdd	Zedd
ededd fddZedddedede	d  fddZ
defddZ  ZS )r$   z!Http basic authentication helper. latin1loginpasswordencodingr,   c                    sB   |d u rt d|d u rt dd|v rt dt | |||S )Nz"None is not allowed as login valuez%None is not allowed as password valuerM   z5A ":" is not allowed in login (RFC 1945#section-11.1))
ValueErrorsuper__new__)clsrc   rd   re   	__class__r-   r1   rh      s   zBasicAuth.__new__auth_headerc                 C   s   z
| dd\}}W n ty   tdw | dkr"td| ztj|ddd|}W n tjy=   td	w z
| d
d\}}W n tyS   tdw | |||dS )z<Create a BasicAuth object from an Authorization HTTP header.rW   r   z%Could not parse authorization header.basiczUnknown authorization method %sasciiT)validatezInvalid base64 encoding.rM   zInvalid credentials.re   )	splitrf   lowerbase64	b64decodeencodedecodebinasciiError)ri   rl   re   	auth_typeencoded_credentialsdecodedusernamerd   r-   r-   r1   rv      s,   
zBasicAuth.decoderp   urlc                C   s6   t |ts	td|jdu rdS | |j|jpd|dS )zCreate BasicAuth from url.zurl should be yarl.URL instanceNra   rp   )
isinstancer   	TypeErroruserrd   )ri   r}   re   r-   r-   r1   from_url   s
   

zBasicAuth.from_urlc                 C   s0   | j  d| j | j}dt|| j S )zEncode credentials.rM   zBasic %s)rc   rd   ru   re   rs   	b64encoderv   )r\   credsr-   r-   r1   ru      s   zBasicAuth.encode)ra   rb   )rb   )r^   r_   r`   __doc__strrh   classmethodrv   r   r   r   ru   __classcell__r-   r-   rj   r1   r$      s"    "r$   )rc   rd   re   r}   c                 C   s(   t | }|d u r| d fS | d |fS rZ   )r$   r   	with_user)r}   authr-   r-   r1   strip_auth_from_url   s   
r   c               
   C   s  t jd} | durt| }n,zt }W n ty. } ztd| W Y d}~dS d}~ww |t	 dkr8dnd }zt

t|W S  t
jy] } ztd| W Y d}~dS d}~w ty } z| sj| rwtd| W Y d}~dS W Y d}~dS d}~ww )	zAttempt to load the netrc file from the path specified by the env-var
    NETRC or in the default location in the user's home directory.

    Returns None if it couldn't be found or fails to parse.
    NETRCNzHCould not resolve home directory when trying to look for .netrc file: %sWindows_netrcz.netrczCould not parse .netrc file: %szCould not read .netrc file: %s)osenvirongetr   homeRuntimeErrorr!   debugplatformsystemnetrcr   NetrcParseErrorwarningOSErroris_file)	netrc_env
netrc_pathhome_direr-   r-   r1   netrc_from_env   s<   
	
r   T)auto_attribsfrozenslotsc                   @   s"   e Zd ZU eed< ee ed< dS )	ProxyInfoproxy
proxy_authN)r^   r_   r`   r   __annotations__r   r$   r-   r-   r-   r1   r      s   
 r   c                  C   s   dd t   D } t }dd |  D }i }| D ]N\}}|\}}|jdkr0td| q|rc|d u rcd }|jd urC||j}|d urc|^ }	}
|	d rT|	d n|	d }tt	t
|t	t
|
}t||||< q|S )Nc                 S   s"   i | ]\}}|d v r|t |qS ))httphttpsr   r/   kvr-   r-   r1   
<dictcomp>   s   " z$proxies_from_env.<locals>.<dictcomp>c                 S   s   i | ]	\}}|t |qS r-   )r   r   r-   r-   r1   r      s    r   z,HTTPS proxies %s are not supported, ignoringr   )r   itemsr   schemer!   r   hostauthenticatorsr$   r   r   r   )
proxy_urls	netrc_objstrippedretprotovalr   r   auth_from_netrcloginsrd   rc   r-   r-   r1   proxies_from_env   s&   


r   zOptional[asyncio.Task[Any]]c                 C   s   t rtj| dS tjj| dS )Nr+   )PY_37r4   current_taskr5   r   r-   r-   r1   r     s   r   c                 C   sB   | d u rt  } |  stjdtdd |  rtjddd | S )Nz5The object should be created within an async functionr&   )
stacklevelT)
stack_info)	r4   get_event_loop
is_runningwarningswarnDeprecationWarning	get_debugr"   r   r   r-   r-   r1   get_running_loop  s   r   objc                 C   s    t tdd }|d ur|| S dS )NisasyncgenfunctionF)getattrinspect)r   funcr-   r-   r1   r   )  s   r   c                   @   s.   e Zd ZU eed< eed< eed< ded< dS )MimeTypetypesubtypesuffixzMultiDictProxy[str]
parametersN)r^   r_   r`   r   r   r-   r-   r-   r1   r   1  s
   
 r   8   )maxsizemimetypec           
      C   s  | st dddtt dS | d}t }|dd D ])}|s qttttf d|v r0|ddn|df\}}|| 	 |	d q|d 	  }|d	krSd
}d|v rdttttf |ddn|df\}}d|v r{ttttf |ddn|df\}}	t |||	t|dS )a  Parses a MIME type into its components.

    mimetype is a MIME type string.

    Returns a MimeType object.

    Example:

    >>> parse_mimetype('text/html; charset=utf-8')
    MimeType(type='text', subtype='html', suffix='',
             parameters={'charset': 'utf-8'})

    ra   )r   r   r   r   rL   r   NrT   z "r   *z*/*rP   +)
r   r   r   rq   r   r   r   addrr   strip)
r   partsparamsitemkeyvaluefulltypemtypestyper   r-   r-   r1   parse_mimetype9  s2   
$(r   defaultc                 C   s@   t | dd }|rt|tr|d dkr|d dkrt|jS |S )Nnamer   rH   r   rI   )r   r~   r   r   r   )r   r   r   r-   r-   r1   guess_filenamei  s   &
r   disptypequote_fieldsr   c           	      K   s   | rt t| kstd| | }|r^g }| D ]3\}}|r%t t|ks-td|||r4t|dn|}||d| f |dkrL|dd| f qdd	d
 |D }d||f}|S )zSets ``Content-Disposition`` header.

    disptype is a disposition type: inline, attachment, form-data.
    Should be valid extension token (see RFC 2183)

    params is a dict with disposition params.
    z!bad content disposition type {!r}z+bad content disposition parameter {!r}={!r}ra   z"%s"filenamez	filename*zutf-8''z; c                 s   s    | ]}d  |V  qdS )rT   N)join)r/   pairr-   r-   r1   	<genexpr>  s    z-content_disposition_header.<locals>.<genexpr>)TOKENsetrf   formatr   r   appendr   )	r   r   r   r   lparamsr   r   qvalsparamsr-   r-   r1   content_disposition_headerp  s$   

r   c                   @   s   e Zd ZU eeef ed< dS )_TSelf_cacheN)r^   r_   r`   r	   r   r   r   r-   r-   r-   r1   r     s   
 r   c                   @   s`   e Zd ZdZdedef ddfddZdded	ee	e
  defd
dZdededdfddZdS )reifyaR  Use as a class method decorator.  It operates almost exactly like
    the Python `@property` decorator, but it puts the result of the
    method it decorates into the instance dict after the first call,
    effectively replacing the function it decorates with an instance
    variable.  It is, in Python parlance, a data descriptor.

    wrapped.r,   Nc                 C   s   || _ |j| _|j| _d S rZ   )r   r   r^   r   )r\   r   r-   r-   r1   __init__  s   zreify.__init__instownerc                 C   sb   z z|j | j W W S  ty    | |}||j | j< | Y W S w  ty0   |d u r/|  Y S  w rZ   )r   r   KeyErrorr   AttributeError)r\   r   r   r   r-   r-   r1   __get__  s   

zreify.__get__r   c                 C   s   t d)Nzreified property is read-only)r   )r\   r   r   r-   r-   r1   __set__  s   zreify.__set__rZ   )r^   r_   r`   r   r   r8   r   r   r   r   r   r   r   r-   r-   r-   r1   r     s
     r   )r   z[^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$a  ^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}$)(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:)|::(?:[A-F0-9]{1,4}:){5})(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}$)(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:)|(?:[A-F0-9]{1,4}:){7}:|:(:[A-F0-9]{1,4}){7})$)flagsrn   regexregexbr   c                 C   sV   |d u rdS t |trt| |S t |tttfr!t||S td|t	|)NFz{} [{}] is not a str or bytes)
r~   r   boolmatchbytes	bytearray
memoryviewr   r   r   )r   r   r   r-   r-   r1   _is_ip_address  s   
r  c                 C   s   t | pt| S rZ   )is_ipv4_addressis_ipv6_address)r   r-   r-   r1   is_ip_address  s   r  c                   C   s$   t j t jjjddt jdd S )z8Return current time rounded up to the next whole second.r   )microsecond)seconds)datetimenowtimezoneutcreplace	timedeltar-   r-   r-   r1   next_whole_second  s
   
r  ra   c                  C   s\   t t } | tkr,d}d}t| ^}}}}}}}	}
d||	 ||| ||||f a| atS )N)MonTueWedThuFriSatSun)ra   JanFebMarAprMayJunJulAugSepOctNovDecz#%s, %02d %3s %4d %02d:%02d:%02d GMT)inttime_cached_current_datetimegmtime_cached_formatted_datetime)r  _weekdayname
_monthnameyearmonthdayhhmmsswdtailr-   r-   r1   rfc822_formatted_time  s    	r4  c                 C   sT   | \}}| }|d ur(t t t||  W d    d S 1 s!w   Y  d S d S rZ   )r   	Exceptionr   )inforefr   obr-   r-   r1   _weakref_handle  s   
"r9  c                 C   sL   |d ur"|dkr$|  | }|dkrt|}||tt| |fS d S d S Nr      )r&  r   call_atr9  weakrefr7  )r8  r   timeoutr+   whenr-   r-   r1   weakref_handle  s   r@  c                 C   s@   |d ur|dkr|  | }|dkrt|}||| S d S d S r:  )r&  r   r<  )cbr>  r+   r?  r-   r-   r1   
call_later(  s   rB  c                   @   s|   e Zd ZdZdejdee ddfddZde	d	 d
e
de
ddfddZdddZdeej fddZdddZdddZdS )TimeoutHandlez Timeout handle r+   r>  r,   Nc                 C   s   || _ || _g | _d S rZ   )_timeout_loop
_callbacks)r\   r+   r>  r-   r-   r1   r   3  s   zTimeoutHandle.__init__callback).Nargskwargsc                 O   s   | j |||f d S rZ   )rF  r   )r\   rG  rH  rI  r-   r-   r1   register<  s   zTimeoutHandle.registerc                 C   s   | j   d S rZ   )rF  clearr[   r-   r-   r1   closeA     zTimeoutHandle.closec                 C   sH   | j }|d ur"|dkr"| j | }|dkrt|}| j|| jS d S r:  )rD  rE  r&  r   r<  __call__)r\   r>  r?  r-   r-   r1   startD  s   zTimeoutHandle.startBaseTimerContextc                 C   s4   | j d ur| j dkrt| j}| |j |S t S )Nr   )rD  TimerContextrE  rJ  r>  	TimerNoop)r\   timerr-   r-   r1   rS  N  s
   
zTimeoutHandle.timerc              	   C   sV   | j D ] \}}}tt ||i | W d    n1 sw   Y  q| j   d S rZ   )rF  r   r5  rK  )r\   rA  rH  rI  r-   r-   r1   rN  V  s   
zTimeoutHandle.__call__r,   N)r,   rP  )r^   r_   r`   r   r4   AbstractEventLoopr   floatr   r   r   rJ  rL  HandlerO  rS  rN  r-   r-   r-   r1   rC  0  s,    
	



rC  c                   @   s   e Zd ZdS )rP  N)r^   r_   r`   r-   r-   r-   r1   rP  ^  s    rP  c                   @   sD   e Zd ZdefddZdeee  dee dee ddfdd	Z	dS )
rR  r,   c                 C   s   | S rZ   r-   r[   r-   r-   r1   	__enter__c  s   zTimerNoop.__enter__exc_typeexc_valexc_tbNc                 C   s   d S rZ   r-   r\   rY  rZ  r[  r-   r-   r1   __exit__f  s   zTimerNoop.__exit__)
r^   r_   r`   rP  rX  r   r   BaseExceptionr   r]  r-   r-   r-   r1   rR  b  s    
rR  c                	   @   sj   e Zd ZdZdejddfddZdefddZd	e	e
e  d
e	e de	e de	e fddZdddZdS )rQ  z( Low resolution timeout context manager r+   r,   Nc                 C   s   || _ g | _d| _d S )NF)rE  _tasks
_cancelled)r\   r+   r-   r-   r1   r   r  s   
zTimerContext.__init__c                 C   sB   t | jd}|d u rtd| jr|  tjd | j| | S )Nr   4Timeout context manager should be used inside a task)	r   rE  r   r`  cancelr4   TimeoutErrorr_  r   r\   taskr-   r-   r1   rX  w  s   zTimerContext.__enter__rY  rZ  r[  c                 C   s,   | j r| j   |tju r| jrtjd d S rZ   )r_  popr4   CancelledErrorr`  rc  r\  r-   r-   r1   r]    s
   
zTimerContext.__exit__c                 C   s,   | j st| jD ]}|  qd| _ d S d S )NT)r`  r   r_  rb  rd  r-   r-   r1   r>    s
   

zTimerContext.timeoutrT  )r^   r_   r`   r   r4   rU  r   rP  rX  r   r   r^  r   r   r]  r>  r-   r-   r-   r1   rQ  o  s    

rQ  c                   @   s   e Zd ZdejfddZdS )CeilTimeoutr,   c                 C   sh   | j d ur2t| jd| _| jd u rtd| j }| j }|| }|dkr)t|}| j|| j| _	| S )Nr   ra  r;  )
rD  r   rE  _taskr   r&  r   r<  _cancel_task_cancel_handler)r\   r  delayr?  r-   r-   r1   rX    s   


zCeilTimeout.__enter__N)r^   r_   r`   async_timeoutr>  rX  r-   r-   r-   r1   rh    s    rh  c                   @   st   e Zd Zeg dZdZdZeZde	ddfddZ
ede	fddZedee	 fd	d
Zedee fddZdS )HeadersMixin)_content_type_content_dict_stored_content_typeNrawr,   c                 C   s4   || _ |d u rd| _i | _d S t|\| _| _d S )Nzapplication/octet-stream)rq  ro  rp  cgiparse_headerr\   rr  r-   r-   r1   _parse_content_type  s
   
z HeadersMixin._parse_content_typec                 C   s(   | j tj}| j|kr| | | jS )z7The value of content part for Content-Type HTTP header.)_headersr   r    CONTENT_TYPErq  rv  ro  ru  r-   r-   r1   content_type  s   

zHeadersMixin.content_typec                 C   s.   | j tj}| j|kr| | | jdS )z7The value of charset part for Content-Type HTTP header.charset)rw  r   r    rx  rq  rv  rp  ru  r-   r-   r1   rz    s   

zHeadersMixin.charsetc                 C   s"   | j tj}|durt|S dS )z(The value of Content-Length HTTP header.N)rw  r   r    CONTENT_LENGTHr%  )r\   content_lengthr-   r-   r1   r|    s   zHeadersMixin.content_length)r^   r_   r`   	frozensetATTRSro  rp  sentinelrq  r   rv  propertyry  r   rz  r%  r|  r-   r-   r-   r1   rn    s    	rn  futzasyncio.Future[_T]resultc                 C      |   s| | d S d S rZ   )r.   
set_result)r  r  r-   r-   r1   r       r  excc                 C   r  rZ   )r.   set_exception)r  r  r-   r-   r1   r    r  r  c                   @   s   e Zd ZdZdeeeef  ddfddZdddZ	d	edefd
dZ
dd	ededefddZdefddZdee fddZd	edefddZdefddZdefddZdS )r%   )_mapsmapsr,   Nc                 C   s   t || _d S rZ   )tupler  )r\   r  r-   r-   r1   r     rM  zChainMapProxy.__init__c                 C   s   t d| j)Nz4Inheritance class {} from ChainMapProxy is forbidden)r   r   r^   )ri   r-   r-   r1   __init_subclass__  s   zChainMapProxy.__init_subclass__r   c              	   C   s4   | j D ]}z|| W   S  ty   Y qw t|rZ   )r  r   )r\   r   mappingr-   r-   r1   __getitem__  s   
zChainMapProxy.__getitem__r   c                 C   s   || v r| | S |S rZ   r-   )r\   r   r   r-   r-   r1   r     s   zChainMapProxy.getc                 C   s   t t j| j S rZ   )lenr   unionr  r[   r-   r-   r1   __len__  s   zChainMapProxy.__len__c                 C   s&   i }t | jD ]}|| qt|S rZ   )reversedr  updateiter)r\   dr  r-   r-   r1   __iter__  s   zChainMapProxy.__iter__c                    s   t  fdd| jD S )Nc                 3   s    | ]} |v V  qd S rZ   r-   )r/   mr   r-   r1   r     s    z-ChainMapProxy.__contains__.<locals>.<genexpr>anyr  )r\   r   r-   r  r1   __contains__  s   zChainMapProxy.__contains__c                 C   s
   t | jS rZ   r  r[   r-   r-   r1   __bool__  s   
zChainMapProxy.__bool__c                 C   s   d tt| j}d| dS )Nz, zChainMapProxy(rG   )r   mapreprr  )r\   contentr-   r-   r1   __repr__
  s   zChainMapProxy.__repr__rT  rZ   )r^   r_   r`   	__slots__r   r   r   r   r   r  r  r   r%  r  r   r  objectr   r  r  r  r-   r-   r-   r1   r%     s    
r%   rZ   )T)r   r4   rs   rw   rs  r  	functoolsr   r   r   r   resysr&  r   r=  collectionsr   
contextlibr   mathr   pathlibr   typesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   urllib.parser   urllib.requestr   rm  attr	multidictr   r   typing_extensionsr   yarlr   ra   r    logr!   r"   typedefsr#   __all__version_infoPY_36r   PY_38idna_sslpatch_match_hostnamer*   ImportErrorrU  r6   r   r8   r9   r  r  r   r   r   NO_EXTENSIONSr   ignore_environmentDEBUGrangeCHARr?   CTL
SEPARATORSr   rY   r$   r   r   sr   r   r   r   r   r   r   	lru_cacher   r   r   r   r   reify_py_helpersreify_c_ipv4_pattern_ipv6_patterncompile_ipv4_regex
IGNORECASE_ipv6_regexru   _ipv4_regexb_ipv6_regexbr  r  partialr  r  r  r  r  r  r'  r)  r4  r9  r@  rB  rC  rP  rR  rQ  r>  rh  rn  r  r^  r  r%   r-   r-   r-   r1   <module>   sL   L




=(



 /



"(	.,,