Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib/python3.7/site-packages/future/backports/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/future/backports/__pycache__/socket.cpython-37.pyc

B

�A�[/=�@s�dZddlmZddlmZddlmZddlmZddlmZddlZddlTddl	Z	ddl
Z
ddlZyddlZWne
k
r�dZYnXeed	d
�Zeedd�Zeed
d�ZddgZe�e	�e��eZe
j���d��rfiZded<ded<ded<ded<ded<ded<ded<ded <d!ed"<d#ed$<d%ed&<d'ed(<d)ed*<d+ed,<d-ed.<e�d/�Gd0d1�d1ej�Zd?d2d3�Zeejd4��r�d5d6�Zeed7��r�dedfd8d7�Z e!eeg�Z"Gd9d:�d:ej#�Z$d@d<d�Z%dd=lm&Z&e&dfd>d�Z'dS)AaThis 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

Integer constants:

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

Many other constants may be defined; these may be used in calls to
the setsockopt() and getsockopt() methods.
�)�unicode_literals)�print_function)�division)�absolute_import)�superN)�*�EBADF�	�EAGAIN��EWOULDBLOCK�getfqdn�create_connection�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'�errorTabcs�eZdZdZdddgZeeddfdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
d dd�Zdd�Zejfdd�Zdd�Z�fdd�Z�ZS)!�socketz:A subclass of _socket.socket adding the makefile() method.�__weakref__�_io_refs�_closedrNcCs@|dkrtj�||||�ntj�|||||�d|_d|_dS)NrF)�_socketr�__init__rr)�self�family�type�proto�fileno�r�H/opt/alt/python37/lib/python3.7/site-packages/future/backports/socket.pyrcs
zsocket.__init__cCs|S)Nr)rrrr�	__enter__kszsocket.__enter__cGs|js|��dS)N)r�close)r�argsrrr�__exit__nszsocket.__exit__cCsJtj�|�}|�d�rFd|jj|jjt|dd�r4dp6d|dd�f}|S)	z.Wrap __repr__() to reveal the real class name.z<socket objectz
<%s.%s%s%srFz
 [closed] ��N)rr�__repr__�
startswith�	__class__�
__module__�__name__�getattr)r�srrrr$rs
zsocket.__repr__cCstd��dS)NzCannot serialize socket object)�	TypeError)rrrr�__getstate__|szsocket.__getstate__cCs6t|���}|j|j|j|j|d�}|�|���|S)zjdup() -> socket object

        Return a new socket object connected to the same system resource.
        )r)�duprr&rrr�
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).
        )rNT)�_acceptrrrr�getdefaulttimeoutr/�setblocking)rr0�addrr1rrr�accept�s

z
socket.accept�rcKspd|kr|d}|d=nd}d|kr4|d}|d=nd}d|krP|d}|d=nd}x|D]}|dkrZtd��qZWd|k}d|kp�|}	|	s�|s�t�d	|k}
d
}|	r�|d7}|r�|d7}t||�}|jd7_|dkr�d}|d
kr�tj}|d
k�r|
�std��|S|	�r"|�r"t�|||�}
n*|	�r6t�||�}
n|�s@t�t�||�}
|
�rV|
St�	|
|||�}||_
|S)a
makefile(...) -> an I/O stream connected to the socket

        The arguments are as for io.open() after the filename,
        except the only mode characters supported are 'r', 'w' and 'b'.
        The semantics are similar too.  (XXX refactor to share code?)
        �newlineN�errors�encoding)r7�w�bz&invalid mode %r (only r, w, b allowed)r;r7r<r"����rz!unbuffered streams must be binary)�
ValueError�AssertionError�SocketIOr�io�DEFAULT_BUFFER_SIZE�BufferedRWPair�BufferedReader�BufferedWriter�
TextIOWrapper�mode)rrH�	bufferingZ_3to2kwargsr8r9r:�c�writing�reading�binary�rawmode�raw�buffer�textrrr�makefile�sZ



zsocket.makefilecCs*|jdkr|jd8_|jr&|��dS)Nrr=)rrr)rrrr�_decref_socketios�s
zsocket._decref_socketioscCs|�|�dS)N)r)r�_ssrrr�_real_close�szsocket._real_closecCsd|_|jdkr|��dS)NTr)rrrU)rrrrr�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)rr�detach)r)r&rrrV�sz
socket.detach)r7N)r(r'�__qualname__�__doc__�	__slots__�AF_INET�SOCK_STREAMrrr!r$r,r-r6rRrSrrrUrrV�
__classcell__rr)r&rr]s



0rcCst|�}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)r0rrr�nfdrrr�fromfd�sr^�sharecCstddd|�S)z� fromshare(info) -> socket object

        Create a socket object from a the bytes object returned by
        socket.share(pid).
        r)r)�inforrr�	fromshare�sra�
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)�AF_UNIX�	NameErrorrZrrbrrV)rrr�ar<rrrrb�s
cspeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Z�fdd
�Z	dd�Z
edd��Zedd��Z
dd�Z�ZS)rAz�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)r7r;�rw�rb�wb�rwbzinvalid mode: %rr<r7r;F)	r?rB�	RawIOBaser�_sock�_mode�_reading�_writing�_timeout_occurred)rr1rHrrrrs

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�_checkReadablero�IOErrorrk�	recv_into�timeout�errorr �_blocking_errnos)rr<�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)rp�_checkWritablerk�sendrur rv)rr<rwrrr�writeBszSocketIO.writecCs|jrtd��|jS)z2True if the SocketIO is open for reading.
        zI/O operation on closed socket.)�closedr?rm)rrrr�readableRszSocketIO.readablecCs|jrtd��|jS)z2True if the SocketIO is open for writing.
        zI/O operation on closed socket.)r|r?rn)rrrr�writableYszSocketIO.writablecs|jrtd��t���S)z2True if the SocketIO is open for seeking.
        zI/O operation on closed socket.)r|r?r�seekable)r)r&rrr`szSocketIO.seekablecCs|��|j��S)z=Return the file descriptor of the underlying socket.
        )rprkr)rrrrrgszSocketIO.filenocCs|js|��SdSdS)Nr>)r|r)rrrr�namemsz
SocketIO.namecCs|jS)N)rl)rrrrrHtsz
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)r|rBrjrrkrS)rrrrrxs

zSocketIO.close)r(r'rWrXrrxr{r}r~rr�propertyr�rHrr\rr)r&rrAsrAr"cCsn|��}|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�.)�strip�gethostname�
gethostbyaddrru�insert)r��hostname�aliases�ipaddrsrrrr
�s	
)�_GLOBAL_DEFAULT_TIMEOUTcCs�|\}}d}x�t||dt�D]�}|\}}}	}
}d}y:t|||	�}|tk	rR|�|�|r`|�|�|�|�|Stk
r�}
z|
}|dk	r�|��Wdd}
~
XYqXqW|dk	r�|�ntd��dS)adConnect 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.
    An host of '' or port 0 tells the OS to use the default.
    Nrz!getaddrinfo returns an empty list)	�getaddrinfor[rr�r.�bind�connectrur)�addressrt�source_address�host�port�err�res�af�socktyper�	canonname�sar1�_rrrr�s(


)r)r")(rX�
__future__rrrrZfuture.builtinsrr�os�sysrB�errno�ImportErrorr)rr
r�__all__�extend�_get_exports_listr�_realsocket�platform�lowerr%r�appendr^�hasattrrar[rb�setrvrjrAr
r�rrrrr�<module>-sb


	w


Hacked By AnonymousFox1.0, Coded By AnonymousFox