/
usr
/
lib
/
python3.9
/
site-packages
/
__pycache__
/
Upload File
HOME
a ��e3/ � @ s� d dl mZ d dlmZmZ d dlmZ d dlmZmZm Z d dl mZmZ d dl mZ d dlmZmZ eefZdZd Zd Zdd� Zd d� ZG dd� de�ZG dd� de�ZG dd� de�Zdddddefdd�ZdS )� )�iscoroutinefunction)�datetime� timedelta)�wraps)�isgeneratorfunction�isasyncgenfunction�isclass)�ceil�floor)� monotonic)�AnyStr�Iterable�closed�openZ half_openc s � fdd�}|S )zOBuild a predicate function that checks if an exception is a subtype from a listc s t | � �S �N)� issubclass)Zthrown_type�_�� exc_types� �2/usr/lib/python3.9/site-packages/circuitbreaker.py� matches_types s z(in_exception_list.<locals>.matches_typesr )r r r r r �in_exception_list s r c C sv t | �rt| t�rt| �}nVz&t| � t| t�r8td��t| � }W n. typ t | �r`t | �rhtd��| }Y n0 |S )az Build a failure predicate_function. The returned function has the signature (Type[Exception], Exception) -> bool. Return value True indicates a failure in the underlying function. :param expected_exception: either an type of Exception, iterable of Exception types, or a predicate function. If an Exception type or iterable of Exception types, the failure predicate will return True when a thrown exception type matches one of the provided types. If a predicate function, it will just be returned as is. :return: callable (Type[Exception], Exception) -> bool z9expected_exception cannot be a string. Did you mean name?z1expected_exception does not look like a predicate) r r � Exceptionr �iter� isinstance�STRING_TYPES� ValueError� TypeError�callable)�expected_exceptionZfailure_predicater r r �build_failure_predicate s r! c @ s� e Zd ZdZdZeZdZd2dd�Zdd� Z dd � Z d d� Zdd � Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zedd� �Zed d!� �Zed"d#� �Zed$d%� �Zed&d'� �Zed(d)� �Zed*d+� �Zed,d-� �Zed.d/� �Zd0d1� ZdS )3�CircuitBreaker� � Nc C s� d| _ d| _|p| j| _|p | j| _|sTzt| �jd }W n tyR t j }Y n0 t|�| _|pf| j | _|| _t| _t� | _dS )a� Construct a circuit breaker. :param failure_threshold: break open after this many failures :param recovery_timeout: close after this many seconds :param expected_exception: either an type of Exception, iterable of Exception types, or a predicate function. :param name: name for this circuitbreaker :param fallback_function: called when the circuit is opened :return: Circuitbreaker instance :rtype: Circuitbreaker Nr �EXPECTED_EXCEPTION)� _last_failure�_failure_count�FAILURE_THRESHOLD�_failure_threshold�RECOVERY_TIMEOUT�_recovery_timeout�type�__dict__�KeyErrorr"