o
    NK&hv                     @   s  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mZ d dlmZ d dlmZ d dlmZ eeed	 ed
 ed f ZejdkZe dkZdZzd dlZdZW n	 eyl   Y nw ejdk r|G dd dee
Znd dl	mZ G dd deZedefddZ dd Z!d-ddZ"d-ddZ#G d d! d!eZ$ej%d  &d"od#ej%v Z'e'rd dl(Z(deej) fd$d%Z*e(j+Z,e-e j.e(j/gZ0n!ere"  ere#  d d&l1m2Z3 d d'l4m5Z* d.d)d*Z,e-e j.gZ0d+d, Z6dS )/    N)	Awaitable)contextmanager)Enum)LiteralUnion)CIMultiDict)Default)error_loggerfork
forkserverspawnntPyPyFT)      r   c                   @   s   e Zd ZdS )StrEnumN)__name__
__module____qualname__ r   r   ?/var/www/html/venv/lib/python3.10/site-packages/sanic/compat.pyr   $   s    r   )r   c                       sN   e Zd ZdZdd Zdedef fddZdefdd	Z	de
fd
dZ  ZS )UpperStrEnumz6Base class for string enums that are case insensitive.c                 C   s   |   S N)upper)namestartcountlast_valuesr   r   r   _generate_next_value_.   s   z"UpperStrEnum._generate_next_value_valuereturnc                    s   t | }t |S r   )strr   super__eq__)selfr   	__class__r   r   r#   1   s   zUpperStrEnum.__eq__c                 C   s
   t | jS r   )hashr   r$   r   r   r   __hash__5   s   
zUpperStrEnum.__hash__c                 C   s   | j S r   )r   r(   r   r   r   __str__8   s   zUpperStrEnum.__str__)r   r   r   __doc__r   objectboolr#   intr)   r!   r*   __classcell__r   r   r%   r   r   +   s    r   methodc                 c   s*    ddl m} |j}| |_d V  ||_d S )Nr   )Sanic)sanicr1   start_method)r0   r1   origr   r   r   use_context<   s   
r5   c                  C   s&   dd l } | jj}||dd d S )Nr   i   )ctypeswindllkernel32SetConsoleModeGetStdHandle)r7   kernelr   r   r   enable_windows_color_supportF   s   r=   r    c                  C   s0   t tdrtd dS tjd } tjj| _dS )z
    The PyPy os module is missing the 'readlink' function, which causes issues
    withaiofiles. This workaround replaces the missing 'readlink' function
    with 'os.path.realpath', which serves the same purpose.
    readlinkz^PyPy: Skipping patching of the os module as it appears the 'readlink' function has been added.Nos)	hasattrr?   r	   warningsysmodulespathrealpathr>   )moduler   r   r   pypy_os_module_patchM   s   

rG   c                  C   s>   ddl m}  | j }|dkr| jd | jd dS dS )a  
    A patch function for PyPy on Windows that sets the console code page to
    UTF-8 encodingto allow for proper handling of non-ASCII characters. This
    function uses ctypes to call the Windows API functions SetConsoleCP and
    SetConsoleOutputCP to set the code page.
    r   )r8   i  N)r7   r8   r9   GetConsoleOutputCPSetConsoleCPSetConsoleOutputCP)r8   coder   r   r   !pypy_windows_set_console_cp_patch^   s   
rL   c                   @   s0   e Zd ZdZdedefddZdefddZdS )	Headera  Container used for both request and response headers.
    It is a subclass of  [CIMultiDict](https://multidict.readthedocs.io/en/stable/multidict.html#cimultidictproxy)

    It allows for multiple values for a single key in keeping with the HTTP
    spec. Also, all keys are *case in-sensitive*.

    Please checkout [the MultiDict documentation](https://multidict.readthedocs.io/en/stable/multidict.html#multidict)
    for more details about how to use the object. In general, it should work
    very similar to a regular dictionary.
    keyr    c                 C   s8   | dr
| |S |ddd}d| |g S )N_-,)
startswith__getattribute__rstripreplacejoingetallr$   rN   r   r   r   __getattr__y   s   

zHeader.__getattr__c                 C   s   |  |g S )z*Convenience method mapped to ``getall()``.)rW   rX   r   r   r   get_all   s   zHeader.get_allN)r   r   r   r+   r!   rY   rZ   r   r   r   r   rM   m   s    rM   	hypercorntrioc                 C   s   t |  S r   )r\   Pathstat)rD   r   r   r   
stat_async   s   r_   )open)r^   rc                    s   t | |fi |S r   )aio_open)filemodekwargsr   r   r   
open_async   s   rf   c                    s8    fdd} fdd}d t  t j| | | d S )Nc                    s2    s| j jr	dS tdI dH   r|   dS )z3Asyncio wakeups to allow receiving SIGINT in PythonNg?)stateis_stoppingasynciosleepstop)appdier   r   stay_active   s   z1ctrlc_workaround_for_windows.<locals>.stay_activec                    s    rt dd d S )NzNon-graceful Ctrl+CT)KeyboardInterrupt)sigframerm   r   r   ctrlc_handler   s   z3ctrlc_workaround_for_windows.<locals>.ctrlc_handlerF)signalSIGINTadd_task)rl   ro   rs   r   rm   r   ctrlc_workaround_for_windows   s
   rw   )r    N)ra   )7ri   r?   platformrt   rB   collections.abcr   
contextlibr   enumr   typingr   r   	multidictr   sanic.helpersr   	sanic.logr	   StartMethodr   OS_IS_WINDOWSpython_implementationPYPY_IMPLEMENTATIONUVLOOP_INSTALLEDuvloopImportErrorversion_infor!   r   r   r5   r=   rG   rL   rM   argvendswithuse_trior\   stat_resultr_   	open_filerf   tupleCancelledError	CancelledCancelledErrorsaiofilesr`   rb   aiofiles.osr^   rw   r   r   r   r   <module>   sb    

	


