File: //proc/self/root/lib/python3/dist-packages/twisted/protocols/__pycache__/policies.cpython-38.pyc
U
W[OS � @ s> d Z ddlmZmZ ddlZddlmZmZ ddlm Z m
Z
mZ ddlm
Z
ddlmZ ddlmZ d d
� ZG dd� de
�ZG d
d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de �ZG dd� de�ZG dd� de�ZG dd � d e�ZG d!d"� d"e�ZG d#d$� d$�ZdS )%z]
Resource limiting policies.
@seealso: See also L{twisted.protocols.htb} for rate limiting.
� )�division�absolute_importN)�directlyProvides�
providedBy)�
ServerFactory�Protocol�
ClientFactory)�error)�ILoggingContext)�logc C s, t �|�r|�� }n|jj}d|| jjf S )zY
Compute a log prefix for a wrapper and the object it wraps.
@rtype: C{str}
z%s (%s))r
r � logPrefix� __class__�__name__)�wrapper�wrappedr � r �</usr/lib/python3/dist-packages/twisted/protocols/policies.py�_wrappedLogPrefix s
r c @ s� e Zd ZdZdZdd� Zdd� Zdd� Zd d
� Zdd� Z d
d� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� ZdS ) �ProtocolWrappera�
Wraps protocol instances and acts as their transport as well.
@ivar wrappedProtocol: An L{IProtocol<twisted.internet.interfaces.IProtocol>}
provider to which L{IProtocol<twisted.internet.interfaces.IProtocol>}
method calls onto this L{ProtocolWrapper} will be proxied.
@ivar factory: The L{WrappingFactory} which created this
L{ProtocolWrapper}.
r c C s || _ || _d S �N)�wrappedProtocol�factory)�selfr r r r r �__init__5 s zProtocolWrapper.__init__c C s t | | j�S )zo
Use a customized log prefix mentioning both the wrapped protocol and
the current one.
)r r �r r r r r : s zProtocolWrapper.logPrefixc C s6 t | t|�� t�| |� | j�| � | j�| � dS )z�
When a connection is made, register this wrapper with its factory,
save the real transport, and connect the wrapped protocol to this
L{ProtocolWrapper} to intercept any transport calls it makes.
N)r r r �makeConnectionr �registerProtocolr )r � transportr r r r B s zProtocolWrapper.makeConnectionc C s | j �|� d S r )r �write�r �datar r r r P s zProtocolWrapper.writec C s | j �|� d S r )r �
writeSequencer r r r r! T s zProtocolWrapper.writeSequencec C s d| _ | j�� d S �N� )�
disconnectingr �loseConnectionr r r r r% X s zProtocolWrapper.loseConnectionc C s
| j �� S r )r �getPeerr r r r r&