Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/socket.cpython-37.pyc

B

� fMk�@spdZddlZddlTddlZddlZddlZddlZddlmZmZyddl	Z	Wne
k
rhdZ	YnXee	dd�Zee	dd�Z
ee	d	d�Zd
ddd
dgZe�e�e��e�d
edd��e�dedd��e�dedd��e�dedd��dZdZdd�ZeZej���d��r�iZded<ded<ded <d!ed"<d#ed$<d%ed&<d'ed(<d)ed*<d+ed,<d-ed.<d/ed0<d1ed2<d3ed4<d5ed6<d7ed8<e�d9�Gd:d;�d;e�ZGd<d=�d=ej�ZdMd>d
�Z e!ejd?��r�d@dA�Z"e�dA�e!edB��r
de#dfdCdB�Z$ne%e#dfdDdB�Z$e�dB�dEe$_e
ehZ&GdFdG�dGej'�Z(dNdId�Z)e*�Z+e+dfdJd�Z,dOdKdL�Z-dS)Pa0This module provides socket operations and some related functions.
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
On other systems, it only supports IP. Functions specific for a
socket are available as methods of the socket object.

Functions:

socket() -- create a new socket object
socketpair() -- create a pair of new socket objects [*]
fromfd() -- create a socket object from an open file descriptor [*]
fromshare() -- create a socket object from data received from socket.share() [*]
gethostname() -- return the current hostname
gethostbyname() -- map a hostname to its IP number
gethostbyaddr() -- map an IP number or hostname to DNS info
getservbyname() -- map a service name and a protocol name to a port number
getprotobyname() -- map a protocol name (e.g. 'tcp') to a number
ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
htons(), htonl() -- convert 16, 32 bit int from host to network byte order
inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
socket.getdefaulttimeout() -- get the default timeout value
socket.setdefaulttimeout() -- set the default timeout value
create_connection() -- connects to an address, with an optional timeout and
                       optional source address.

 [*] not available on all platforms!

Special objects:

SocketType -- type object for socket objects
error -- exception raised for I/O errors
has_ipv6 -- boolean value indicating if IPv6 is supported

IntEnum constants:

AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)

Integer constants:

Many other constants may be defined; these may be used in calls to
the setsockopt() and getsockopt() methods.
�N)�*)�IntEnum�IntFlag�EBADF�	�EAGAIN��EWOULDBLOCK�fromfd�getfqdn�create_connection�
AddressFamily�
SocketKindcCs|��o|�d�S)NZAF_)�isupper�
startswith)�C�r�+/opt/alt/python37/lib64/python3.7/socket.py�<lambda>L�rcCs|��o|�d�S)NZSOCK_)rr)rrrrrQrZMsgFlagcCs|��o|�d�S)NZMSG_)rr)rrrrrVrZAddressInfocCs|��o|�d�S)NZAI_)rr)rrrrr[rz	127.0.0.1z::1cCs"y||�Stk
r|SXdS)z{Convert a numeric family value to an IntEnum member.

    If it's not a known member, return the numeric value itself.
    N)�
ValueError)�valueZ
enum_klassrrr�_intenum_converterasr�winzThe operation was interrupted.i'zA bad file handle was passed.i'zPermission denied.i'z!A fault occurred on the network??i'z#An invalid operation was attempted.i&'z The socket operation would blocki3'z,A blocking operation is already in progress.i4'zThe network address is in use.i@'zThe connection has been reset.iF'zThe network has been shut down.iJ'zThe operation timed out.iL'zConnection refused.iM'zThe name is too long.iO'zThe host is down.iP'zThe host is unreachable.iQ'�errorTabc@seZdZdS)�_GiveupOnSendfileN)�__name__�
__module__�__qualname__rrrrr�srcs,eZdZdZdddgZd9dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zd:dddd�dd�Ze
ed�rzd;dd�Zn
d<dd�Zd=dd�Zd d!�Zd>d"d#�Zd$d%�Zejfd&d'�Zd(d)�Z�fd*d+�Ze�fd,d-��Ze�fd.d/��Zejd0k�rd1d2�Zd3d4�Znd5d2�Zd6d4�Zd7e_d8e_�ZS)?�socketz:A subclass of _socket.socket adding the makefile() method.�__weakref__�_io_refs�_closed���NcCsP|dkr,|dkrt}|dkr t}|dkr,d}tj�|||||�d|_d|_dS)Nr#rF)�AF_INET�SOCK_STREAM�_socketr�__init__r!r")�self�family�type�proto�filenorrrr'�szsocket.__init__cCs|S)Nr)r(rrr�	__enter__�szsocket.__enter__cGs|js|��dS)N)r"�close)r(�argsrrr�__exit__�szsocket.__exit__cCs�t|dd�}d|jj|jj|r"dnd|��|j|j|jf}|s�y |��}|r^|dt	|�7}Wnt
k
rtYnXy |��}|r�|dt	|�7}Wnt
k
r�YnX|d7}|S)	zVWrap __repr__() to reveal the real class name and socket
        address(es).
        r"Fz,<%s.%s%s fd=%i, family=%s, type=%s, proto=%iz	 [closed]�z
, laddr=%sz
, raddr=%s�>)�getattr�	__class__rrr,r)r*r+�getsockname�str�errorZgetpeername)r(�closed�sZladdrZraddrrrr�__repr__�s0

zsocket.__repr__cCstd��dS)NzCannot serialize socket object)�	TypeError)r(rrr�__getstate__�szsocket.__getstate__cCs6t|���}|j|j|j|j|d�}|�|���|S)z�dup() -> socket object

        Duplicate the socket. Return a new socket object connected to the same
        system resource. The new socket is non-inheritable.
        )r,)�dupr,r4r)r*r+�
settimeout�
gettimeout)r(�fd�sockrrrr=�sz
socket.dupcCsF|��\}}t|j|j|j|d�}t�dkr>|��r>|�d�||fS)z�accept() -> (socket object, address info)

        Wait for an incoming connection.  Return a new socket
        representing the connection, and the address of the client.
        For IP sockets, the address info is a pair (hostaddr, port).
        )r,NT)Z_acceptrr)r*r+Zgetdefaulttimeoutr?�setblocking)r(r@�addrrArrr�accept�s

z
socket.accept�r)�encoding�errors�newlinec
Cst|�dddhks td|f��d|k}d|kp4|}|sB|sBt�d|k}d}	|rZ|	d7}	|rf|	d7}	t||	�}
|jd7_|dkr�d}|d	kr�tj}|d	kr�|s�td
��|
S|r�|r�t�|
|
|�}n&|r�t�|
|�}n|s�t�t�	|
|�}|r�|St�
||||�}||_|S)z�makefile(...) -> an I/O stream connected to the socket

        The arguments are as for io.open() after the filename, except the only
        supported mode values are 'r' (default), 'w' and 'b'.
        rE�w�bz&invalid mode %r (only r, w, b allowed)r1�Nr#rz!unbuffered streams must be binary)�setr�AssertionError�SocketIOr!�io�DEFAULT_BUFFER_SIZE�BufferedRWPair�BufferedReader�BufferedWriter�
TextIOWrapper�mode)
r(rU�	bufferingrFrGrHZwritingZreadingZbinaryZrawmode�raw�buffer�textrrr�makefile�s@
zsocket.makefile�sendfilerc
Cs�|�|||�|��}y|��}Wn0ttjfk
rR}zt|��Wdd}~XYnXyt�|�j}Wn*t	k
r�}zt|��Wdd}~XYnX|s�dS|s�|n|}|�
�}	|	dkr�td��tt
d�r�t
��}
nt
��}
|
�|t
j�d}|
j}tj}
z�x�|	�r||	��st�d��|�r.||}|dk�r.Py|
||||�}Wn^tk
�rd|	�s^|�w�Yq�t	k
�r�}z|dk�r�t|��|d�Wdd}~XYq�X|dk�r�P||7}||7}q�W|S|dk�r�t|d��r�|�|�XdS)Nrz&non-blocking sockets are not supported�PollSelectorz	timed out�seek)�_check_sendfile_paramsr,�AttributeErrorrO�UnsupportedOperationr�os�fstat�st_size�OSErrorr?r�hasattr�	selectorsr\ZSelectSelector�registerZEVENT_WRITEZselectr[r&�timeout�BlockingIOErrorr])r(�file�offset�countZsocknor,�errZfsize�	blocksizerhZselector�
total_sentZselector_selectZos_sendfile�sentrrr�_sendfile_use_sendfile	s`





zsocket._sendfile_use_sendfilecCstd��dS)Nz,os.sendfile() not available on this platform)r)r(rjrkrlrrrrqJsc

Cs|�|||�|��dkr"td��|r0|�|�|r>t|d�nd}d}|j}|j}z�x�|rrt|||�}|dkrrPt||��}|s�PxLy||�}	Wntk
r�w�Yq�X||	7}|	t	|�kr�||	d�}q�Pq�WqVW|S|dkr�t
|d�r�|�||�XdS)Nrz&non-blocking sockets are not supportedi r])r^r?rr]�min�read�send�
memoryviewri�lenre)
r(rjrkrlrnroZ	file_readZ	sock_send�datarprrr�_sendfile_use_sendNs<

zsocket._sendfile_use_sendcCsddt|dd�krtd��|jt@s*td��|dk	r`t|t�sJtd�|���|dkr`td�|���dS)NrJrUz$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})r)r3rr*r%�
isinstance�intr;�format)r(rjrkrlrrrr^rs

zsocket._check_sendfile_paramscCs2y|�|||�Stk
r,|�|||�SXdS)a_sendfile(file[, offset[, count]]) -> sent

        Send a file until EOF is reached by using high-performance
        os.sendfile() and return the total number of bytes which
        were sent.
        *file* must be a regular file object opened in binary mode.
        If os.sendfile() is not available (e.g. Windows) or file is
        not a regular file socket.send() will be used instead.
        *offset* tells from where to start reading the file.
        If specified, *count* is the total number of bytes to transmit
        as opposed to sending the file until EOF is reached.
        File position is updated on return or also in case of error in
        which case file.tell() can be used to figure out the number of
        bytes which were sent.
        The socket must be of SOCK_STREAM type.
        Non-blocking sockets are not supported.
        N)rqrrx)r(rjrkrlrrrr[szsocket.sendfilecCs*|jdkr|jd8_|jr&|��dS)NrrK)r!r"r.)r(rrr�_decref_socketios�s
zsocket._decref_socketioscCs|�|�dS)N)r.)r(Z_ssrrr�_real_close�szsocket._real_closecCsd|_|jdkr|��dS)NTr)r"r!r})r(rrrr.�s
zsocket.closecsd|_t���S)adetach() -> file descriptor

        Close the socket object without closing the underlying file descriptor.
        The object cannot be used after this call, but the file descriptor
        can be reused for other purposes.  The file descriptor is returned.
        T)r"�super�detach)r()r4rrr�sz
socket.detachcstt�jt�S)z@Read-only access to the address family for this socket.
        )rr~r)r
)r()r4rrr)�sz
socket.familycstt�jt�S)z-Read-only access to the socket type.
        )rr~r*r)r()r4rrr*�szsocket.type�ntcCst�|���S)N)raZget_handle_inheritabler,)r(rrr�get_inheritable�szsocket.get_inheritablecCst�|��|�dS)N)raZset_handle_inheritabler,)r(�inheritablerrr�set_inheritable�szsocket.set_inheritablecCst�|���S)N)rar�r,)r(rrrr��scCst�|��|�dS)N)rar�r,)r(r�rrrr��sz&Get the inheritable flag of the socketz&Set the inheritable flag of the socket)r#r#r#N)rEN)rN)rN)rN)rN) rrr�__doc__�	__slots__r'r-r0r:r<r=rDrZrerarqrxr^r[r|r&rr}r.r�propertyr)r*�namer�r��
__classcell__rr)r4rr�s<

)
A

$


rcCst|�}t||||�S)z� fromfd(fd, family, type[, proto]) -> socket object

    Create a socket object from a duplicate of the given file
    descriptor.  The remaining arguments are the same as for socket().
    )r=r)r@r)r*r+Znfdrrrr
�sZsharecCstddd|�S)z� fromshare(info) -> socket object

        Create a socket object from the bytes object returned by
        socket.share(pid).
        r)r)�inforrr�	fromshare�sr��
socketpaircCsh|dkr*yt}Wntk
r(t}YnXt�|||�\}}t||||���}t||||���}||fS)aasocketpair([family[, type[, proto]]]) -> (socket object, socket object)

        Create a pair of socket objects from the sockets returned by the platform
        socketpair() function.
        The arguments are the same as for socket() except the default family is
        AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
        N)ZAF_UNIX�	NameErrorr$r&r�rr)r)r*r+�arJrrrr��s
c
	Cs|tkrt}n|tkrt}ntd��|tkr4td��|dkrDtd��t|||�}z�|�|df�|��|�	�dd�\}}t|||�}yP|�
d�y|�||f�Wntt
fk
r�YnX|�
d�|��\}}	Wn|���YnXWd|��X||fS)Nz?Only AF_INET and AF_INET6 socket address families are supportedz)Only SOCK_STREAM socket type is supportedrzOnly protocol zero is supported�FT)r$�
_LOCALHOSTZAF_INET6�
_LOCALHOST_V6rr%r�bindZlistenr5rB�connectri�InterruptedErrorrDr.)
r)r*r+�hostZlsockrC�portZcsockZssock�_rrrr��s8


a8socketpair([family[, type[, proto]]]) -> (socket object, socket object)
Create a pair of socket objects from the sockets returned by the platform
socketpair() function.
The arguments are the same as for socket() except the default family is AF_UNIX
if defined on the platform; otherwise, the default is AF_INET.
cspeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Z�fdd
�Z	dd�Z
edd��Zedd��Z
dd�Z�ZS)rNz�Raw I/O implementation for stream sockets.

    This class supports the makefile() method on sockets.  It provides
    the raw I/O interface on top of a socket object.
    cCsZ|dkrtd|��tj�|�||_d|kr6|d7}||_d|k|_d|k|_d|_dS)N)rErIZrw�rb�wbZrwbzinvalid mode: %rrJrErIF)	rrO�	RawIOBaser'�_sock�_mode�_reading�_writing�_timeout_occurred)r(rArUrrrr'3s

zSocketIO.__init__c
Cs�|��|��|jrtd��xby|j�|�Stk
rHd|_�Yq tk
r|}z|jdt	krjdS�Wdd}~XYq Xq WdS)a3Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.

        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        z!cannot read from timed out objectTrN)
�_checkClosed�_checkReadabler�rdr�Z	recv_intorhr7r/�_blocking_errnos)r(rJ�errr�readinto?szSocketIO.readintoc
CsX|��|��y|j�|�Stk
rR}z|jdtkr@dS�Wdd}~XYnXdS)aWrite the given bytes or bytearray object *b* to the socket
        and return the number of bytes written.  This can be less than
        len(b) if not all data could be written.  If the socket is
        non-blocking and no bytes could be written None is returned.
        rN)r��_checkWritabler�rtr7r/r�)r(rJr�rrr�writeVszSocketIO.writecCs|jrtd��|jS)z2True if the SocketIO is open for reading.
        zI/O operation on closed socket.)r8rr�)r(rrr�readablefszSocketIO.readablecCs|jrtd��|jS)z2True if the SocketIO is open for writing.
        zI/O operation on closed socket.)r8rr�)r(rrr�writablemszSocketIO.writablecs|jrtd��t���S)z2True if the SocketIO is open for seeking.
        zI/O operation on closed socket.)r8rr~�seekable)r()r4rrr�tszSocketIO.seekablecCs|��|j��S)z=Return the file descriptor of the underlying socket.
        )r�r�r,)r(rrrr,{szSocketIO.filenocCs|js|��SdSdS)Nr#)r8r,)r(rrrr��sz
SocketIO.namecCs|jS)N)r�)r(rrrrU�sz
SocketIO.modecCs*|jr
dStj�|�|j��d|_dS)z�Close the SocketIO object.  This doesn't close the underlying
        socket, except if all references to it have disappeared.
        N)r8rOr�r.r�r|)r(rrrr.�s

zSocketIO.close)rrrr�r'r�r�r�r�r�r,r�r�rUr.r�rr)r4rrN"srNr1cCsn|��}|r|dkrt�}yt|�\}}}Wntk
r@Yn*X|�d|�x|D]}d|krTPqTW|}|S)aGet fully qualified domain name from name.

    An empty argument is interpreted as meaning the local host.

    First the hostname returned by gethostbyaddr() is checked, then
    possibly existing aliases. In case no FQDN is available, hostname
    from gethostname() is returned.
    z0.0.0.0r�.)�stripZgethostnameZ
gethostbyaddrr7�insert)r�Zhostname�aliasesZipaddrsrrrr�s	
cCs�|\}}d}x�t||dt�D]�}|\}}}	}
}d}y>t|||	�}|tk	rR|�|�|r`|�|�|�|�d}|Stk
r�}
z|
}|dk	r�|��Wdd}
~
XYqXqW|dk	r�z|�Wdd}Xntd��dS)acConnect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    A host of '' or port 0 tells the OS to use the default.
    Nrz!getaddrinfo returns an empty list)	�getaddrinfor%r�_GLOBAL_DEFAULT_TIMEOUTr>r�r�r7r.)ZaddressrhZsource_addressr�r�rm�res�af�socktyper+�	canonname�sarAr�rrrr�s.


cCsTg}xJt�||||||�D]2}|\}}	}}
}|�t|t�t|	t�||
|f�qW|S)a�Resolve host and port into list of address info entries.

    Translate the host/port argument into a sequence of 5-tuples that contain
    all the necessary arguments for creating a socket connected to that service.
    host is a domain name, a string representation of an IPv4/v6 address or
    None. port is a string service name such as 'http', a numeric port number or
    None. By passing None as the value of host and port, you can pass NULL to
    the underlying C API.

    The family, type and proto arguments can be optionally specified in order to
    narrow the list of addresses returned. Passing zero as a value for each of
    these arguments selects the full range of results.
    )r&r��appendrr
r)r�r�r)r*r+�flagsZaddrlistr�r�r�r�r�rrrr��sr�)r)r1)rrrr).r�r&ra�sysrOrf�enumrr�errno�ImportErrorr3rrr	�__all__�extend�_get_exports_list�_convertrr�r�rrZ_realsocket�platform�lowerrrr��	Exceptionrr
rer�r%r�r$r�r�rNr�objectr�rr�rrrr�<module>/s� 






F
	
$
u
+

Hacked By AnonymousFox1.0, Coded By AnonymousFox