HEX
Server: nginx/1.30.4
System: Linux d-twindigital-web-1.host-ed.eu 4.18.0-553.141.2.el8_10.x86_64 #1 SMP Wed Jul 8 10:28:18 EDT 2026 x86_64
User: u_twindigital_html (1009)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/ndg/httpsclient/__pycache__/ssl_socket.cpython-36.pyc
3

�<�Y�$�@sndZdZdZdZdZdZdZddlmZdd	lZdd	l	Z	dd
l
mZddlm
Z
eje�ZGdd
�d
e�Zd	S)z�PyOpenSSL utilities including HTTPSSocket class which wraps PyOpenSSL
SSL connection into a httplib-like interface suitable for use with urllib2

zP J Kershawz21/12/10z2(C) 2012 Science and Technology Facilities Councilz-BSD - see LICENSE file in top-level directoryzPhilip.Kershaw@stfc.ac.ukz$Id$�)�datetimeN)�BytesIO)�SSLc@seZdZdZdZd=dd�Zdd�Zedd	��Zej	d
d	��Zdd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zefd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"dS)>�	SSLSocketa:SSL Socket class wraps pyOpenSSL's SSL.Connection class implementing
    the makefile method so that it is compatible with the standard socket
    interface and usable with httplib.

    @cvar default_buf_size: default buffer size for recv operations in the
    makefile method
    @type default_buf_size: int
    i NcCsZ|dk	r||_n&tjtjtj�|_|jjtjtjd�tj||j�|_|j	j
|_d|_dS)z�Create SSL socket object

        @param ctx: SSL context
        @type ctx: OpenSSL.SSL.Context
        @param sock: underlying socket object
        @type sock: socket.socket
        N�r)
�socketZAF_INETZSOCK_STREAM�
setsockoptZ
SOL_SOCKETZSO_REUSEADDRrZ
Connection�_SSLSocket__ssl_conn�	__class__�default_buf_size�buf_size�_makefile_refs)�selfZctxZsock�r� /usr/lib/python3.6/ssl_socket.py�__init__!s
zSSLSocket.__init__cCs|j�dS)zCClose underlying socket when this object goes out of scope
        N)�close)rrrr�__del__3szSSLSocket.__del__cCs|jS)z1Buffer size for makefile method recv() operations)�_SSLSocket__buf_size)rrrrr8szSSLSocket.buf_sizecCs$t|t�stdt|���||_dS)z1Buffer size for makefile method recv() operationsz1Expecting int type for "buf_size"; got %r insteadN)�
isinstance�int�	TypeError�typer)r�valuerrrr=s
cCsJ|jdkr8y|jj�WqFtjtjfk
r4YqFXn|jd8_dS)zVShutdown the SSL connection and call the close method of the
        underlying socketrN)r
r	�shutdownr�Error�SysCallError)rrrrrEs
zSSLSocket.closecCs|jj|�dS)z�Set the shutdown state of the Connection.
        @param mode: bit vector of either or both of SENT_SHUTDOWN and
        RECEIVED_SHUTDOWN
        N)r	�set_shutdown)r�moderrrrQszSSLSocket.set_shutdowncCs
|jj�S)z�Get the shutdown state of the Connection.
        @return: bit vector of either or both of SENT_SHUTDOWN and
        RECEIVED_SHUTDOWN
        )r	�get_shutdown)rrrrrXszSSLSocket.get_shutdowncCs|jj|�dS)z�bind to the given address - calls method of the underlying socket
        @param addr: address/port number tuple
        @type addr: tupleN)r	�bind)r�addrrrrr _szSSLSocket.bindcCs|jj|�dS)z�Listen for connections made to the socket.

        @param backlog: specifies the maximum number of queued connections and
        should be at least 1; the maximum value is system-dependent (usually 5).
        @param backlog: int
        N)r	�listen)rZbacklogrrrr"eszSSLSocket.listencCs|jj�dS)zlSet the connection to work in server mode. The handshake will be
        handled automatically by read/writeN)r	�set_accept_state)rrrrr#nszSSLSocket.set_accept_statecCs
|jj�S)z�Accept an SSL connection.

        @return: pair (ssl, addr) where ssl is a new SSL connection object and
        addr is the address bound to the other end of the SSL connection.
        @rtype: tuple
        )r	�accept)rrrrr$sszSSLSocket.acceptcCs|jj�dS)zlSet the connection to work in client mode. The handshake will be
        handled automatically by read/writeN)r	�set_connect_state)rrrrr%|szSSLSocket.set_connect_statecCs|jj|�dS)z�Call the connect method of the underlying socket and set up SSL on
        the socket, using the Context object supplied to this Connection object
        at creation.

        @param addr: address/port number pair
        @type addr: tuple
        N)r	�connect)rr!rrrr&�szSSLSocket.connectcCs
|jj�S)a�Send the shutdown message to the Connection.

        @param how: for socket.socket this flag determines whether read, write
        or both type operations are supported.  OpenSSL.SSL.Connection doesn't
        support this so this parameter is IGNORED
        @return: true if the shutdown message exchange is completed and false
        otherwise (in which case you call recv() or send() when the connection
        becomes readable/writeable.
        @rtype: bool
        )r	r)rZhowrrrr�szSSLSocket.shutdowncCs
|jj�S)z-Renegotiate this connection's SSL parameters.)r	�renegotiate)rrrrr'�szSSLSocket.renegotiatecCs
|jj�S)zk@return: numbers of bytes that can be safely read from the SSL
        buffer.
        @rtype: int
        )r	�pending)rrrrr(�szSSLSocket.pendingcGs|jj|�S)z�Send data to the socket. Nb. The optional flags argument is ignored.
        - retained for compatibility with socket.socket interface

        @param data: data to send down the socket
        @type data: string
        )r	�send)r�dataZ	flags_argrrrr)�szSSLSocket.sendcCs|jj|�dS)N)r	�sendall)rr*rrrr+�szSSLSocket.sendallcCs|jj|�S)z�Receive data from the Connection.

        @param size: The maximum amount of data to be received at once
        @type size: int
        @return: data received.
        @rtype: string
        )r	�recv)r�sizerrrr,�szSSLSocket.recvcCs|jj|�dS)z}Set this connection's underlying socket blocking _mode_.

        @param mode: blocking mode
        @type mode: int
        N)r	�setblocking)rrrrrr.�szSSLSocket.setblockingcCs
|jj�S)z_
        @return: file descriptor number for the underlying socket
        @rtype: int
        )r	�fileno)rrrrr/�szSSLSocket.filenocGs|jj|�S)z%See socket.socket.getsockopt
        )r	�
getsockopt)r�argsrrrr0�szSSLSocket.getsockoptcGs|jj|�S)zsSee socket.socket.setsockopt

        @return: value of the given socket option
        @rtype: int/string
        )r	r)rr1rrrr�szSSLSocket.setsockoptcCs
|jj�S)z(Return the SSL state of this connection.)r	�state_string)rrrrr2�szSSLSocket.state_stringc
Gs�|jd7_|j}d}t�}tj�}y8|jj|�}x&|rZ|d7}|j|�|jj|�}q6WWntj	tj
fk
rzYnXtj�t
jkr�tjd|tj�|�|jd�|S)ahSpecific to Python socket API and required by httplib: convert
        response into a file-like object.  This implementation reads using recv
        and copies the output into a StringIO buffer to simulate a file object
        for consumption by httplib

        Nb. Ignoring optional file open mode (StringIO is generic and will
        open for read and write unless a string is passed to the constructor)
        and buffer size - httplib set a zero buffer size which results in recv
        reading nothing

        @return: file object for data returned from socket
        @rtype: cStringIO.StringO
        rrz-Socket.makefile %d recv calls completed in %s)r
rrrZutcnowr	r,�writerZZeroReturnErrorr�logZgetEffectiveLevel�logging�DEBUG�debug�seek)rr1Z	_buf_size�i�streamZ	startTimeZdatrrr�makefile�s$

zSSLSocket.makefilecCs
|jj�S)zC
        @return: the socket's own address
        @rtype:
        )r	�getsockname)rrrrr<szSSLSocket.getsocknamecCs
|jj�S)zJ
        @return: remote address to which the socket is connected
        )r	�getpeername)rrrrr=szSSLSocket.getpeernamecCs
|jj�S)z=Retrieve the Context object associated with this Connection. )r	�get_context)rrrrr>szSSLSocket.get_contextcCs
|jj�S)z0Retrieve the other side's certificate (if any)  )r	�get_peer_certificate)rrrrr?szSSLSocket.get_peer_certificate)N)#�__name__�
__module__�__qualname__�__doc__rrr�propertyr�setterrrrr r"r#r$r%r&rr'r(r)r+r,r.r/r0rr2r;r<r=r>r?rrrrrs>
		

	
.r)rC�
__author__Z__date__Z
__copyright__Z__license__Z__contact__Z__revision__rr5r�iorZOpenSSLrZ	getLoggerr@r4�objectrrrrr�<module>s