관리-도구
편집 파일: __init__.cpython-37.pyc
B iI�a? � @ s d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm Z ej dkrXd dlmZ nd dlmZ dZ dZee dd �d d�Zee dd�d d�ZG dd� dej�ZeG dd� d��Zej dkr�e jdd�dd�Zne jdd�dd�Zej dk�re jd�dd�Zne jd�dd�ZdS )� N)� TracebackType)�Any�Optional�Type)� � )�finalz4.0.2)�timeout� timeout_at�Timeoutr )�delay�returnc C s* t � }| dk r|�� | }nd}t||�S )ar timeout context manager. Useful in cases when you want to apply timeout logic around block of code or in cases when asyncio.wait_for is not suitable. For example: >>> async with timeout(0.001): ... async with aiohttp.get('https://github.com') as r: ... await r.text() delay - value in seconds or None to disable timeout logic N)�_get_running_loop�timer )r �loop�deadline� r �G/opt/alt/python37/lib/python3.7/site-packages/async_timeout/__init__.pyr s r )r r c C s t � }t| |�S )a� Schedule the timeout at absolute time. deadline argument points on the time in the same clock system as loop.time(). Please note: it is not POSIX time but a time with undefined starting base, e.g. the time of the system power on. >>> async with timeout_at(loop.time() + 10): ... async with aiohttp.get('https://github.com') as r: ... await r.text() )r r )r r r r r r * s r c @ s e Zd ZdZdZdZdZdS )�_State�INIT�ENTER�TIMEOUT�EXITN)�__name__� __module__�__qualname__r r r r r r r r r = s r c @ s< e Zd ZdZee ejdd�dd�Zd d�dd�Z ee e ee ee ee d �d d�Zd d�dd �Zee e ee ee ee d �dd�Zee d�dd��Zeee d�dd��Zdd�dd�Zdd�dd�Zedd�dd�Zedd�dd�Zdd�dd�Zdd�d d!�Zee e dd"�d#d$�Zd%dd&�d'd(�ZdS ))r )� _deadline�_loop�_state�_timeout_handlerN)r r r c C s2 || _ tj| _d | _|d kr$d | _n | �|� d S )N)r r r r r r �update)�selfr r r r r �__init__Y s zTimeout.__init__)r c C s t jdtdd� | �� | S )Nz>with timeout() is deprecated, use async with timeout() instead� )� stacklevel)�warnings�warn�DeprecationWarning� _do_enter)r! r r r � __enter__e s zTimeout.__enter__)�exc_type�exc_val�exc_tbr c C s | � |� d S )N)�_do_exit)r! r* r+ r, r r r �__exit__n s zTimeout.__exit__c � s | � � | S )N)r( )r! r r r � __aenter__w s zTimeout.__aenter__c � s | � |� d S )N)r- )r! r* r+ r, r r r � __aexit__{ s zTimeout.__aexit__c C s | j tjkS )z$Is timeout expired during execution?)r r r )r! r r r �expired� s zTimeout.expiredc C s | j S )N)r )r! r r r r � s zTimeout.deadlinec C s0 | j tjtjfkr$td| j j� ���| �� dS )z Reject scheduled timeout if any.zinvalid state N)r r r r �RuntimeError�value�_reject)r! r r r �reject� s zTimeout.rejectc C s | j d k r| j �� d | _ d S )N)r �cancel)r! r r r r4 � s zTimeout._reject)r r c C s( | j }|dkrtd��| �|| � dS )z�Advance timeout on delay seconds. The delay can be negative. Raise RuntimeError if shift is called when deadline is not scheduled Nz1cannot shift timeout if deadline is not scheduled)r r2 r )r! r r r r r �shift� s z Timeout.shift)r r c C sZ | j tjkrtd��| j tjkr(td��| jdk r<| j�� || _| j tjkrV| � � dS )aU Set deadline to absolute value. deadline argument points on the time in the same clock system as loop.time(). If new deadline is in the past the timeout is raised immediatelly. Please note: it is not POSIX time but a time with undefined starting base, e.g. the time of the system power on. z1cannot reschedule after exit from context managerz!cannot reschedule expired timeoutN) r r r r2 r r r6 r r �_reschedule)r! r r r r r � s zTimeout.updatec C s~ | j tjkst�| j}|d kr"d S | j�� }| jd k r@| j�� t | j�}||krf| j� | j|�| _n| j�|| j|�| _d S )N) r r r �AssertionErrorr r r r r6 � _current_taskZ call_soon�_on_timeoutZcall_at)r! r �now�taskr r r r8 � s zTimeout._reschedulec C s2 | j tjkrtd| j j� ���tj| _ | �� d S )Nzinvalid state )r r r r2 r3 r r8 )r! r r r r( � s zTimeout._do_enter)r* r c C s6 |t jkr"| jtjkr"d | _t j�tj| _| �� d S )N) �asyncio�CancelledErrorr r r r �TimeoutErrorr r4 )r! r* r r r r- � s zTimeout._do_exitzasyncio.Task[None])r= r c C s |� � tj| _d | _d S )N)r6 r r r r )r! r= r r r r; � s zTimeout._on_timeout)r r r � __slots__r �floatr>