← Back
Editing: testing.cpython-38.pyc
U W[�C � @ s d Z ddlZddlZddlmZmZmZmZmZm Z m Z mZ ddlm Z ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZmZmZmZ ddlm Z d Z!dd� Z"dZ#dd� Z$dd� Z%dd� Z&G dd� de'�Z(dd� Z)ee�G dd� de'��Z*G dd� de'�Z+dS )zD Tools for automated testing of L{twisted.pair}-based applications. � N)�EPERM�EAGAIN�EWOULDBLOCK�ENOSYS�EBADF�EINVAL�EINTR�ENOBUFS)�deque��wraps)�implementer)�DatagramProtocol)�EthernetProtocol)�RawUDPProtocol)� IPProtocol)� _IFNAMSIZ� _TUNSETIFF�_IInputOutputSystem�TunnelFlags)�nativeString� c C s t �d| �S )z� Pack an integer into a network-order two-byte string. @param n: The integer to pack. Only values that fit into 16 bits are supported. @return: The packed representation of the integer. @rtype: L{bytes} z>H)�struct�pack)�n� r �6/usr/lib/python3/dist-packages/twisted/pair/testing.py�_H! s r � c C s || t |� | S )a� Construct an ethernet frame. @param src: The source ethernet address, encoded. @type src: L{bytes} @param dst: The destination ethernet address, encoded. @type dst: L{bytes} @param protocol: The protocol number of the payload of this datagram. @type protocol: L{int} @param payload: The content of the ethernet frame (such as an IP datagram). @type payload: L{bytes} @return: The full ethernet frame. @rtype: L{bytes} )r ��src�dstZprotocol�payloadr r r � _ethernet1 s r# c C s� dt dt|� � d t d� t�tjt| �� t�tjt|�� }tt�d|��}|d? }|d@ | }|dA }|dd � t� d |� |dd� }|| S )a� Construct an IP datagram with the given source, destination, and application payload. @param src: The source IPv4 address as a dotted-quad string. @type src: L{bytes} @param dst: The destination IPv4 address as a dotted-quad string. @type dst: L{bytes} @param payload: The content of the IP datagram (such as a UDP datagram). @type payload: L{bytes} @return: An IP datagram header and payload. @rtype: L{bytes} s E � s @r z!10H� i�� N� z!H� ) r �len�socketZ inet_ptonZAF_INETr �sumr �unpackr )r r! r"