File: //lib/python3.6/site-packages/ndg/httpsclient/__pycache__/ssl_socket.cpython-36.pyc
3
�<�Y�$ � @ sn d Z dZdZdZdZdZdZddlmZ dd lZdd l Z dd
l
mZ ddlm
Z
eje�ZG dd
� 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 e Zd ZdZdZd=dd�Zdd� Zedd � �Zej d
d � �Zdd� Z
d
d� Zdd� Zdd� 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 Nc C sZ |dk r|| _ n&t j t jt j�| _ | j jt jt jd� 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_SOCKETZSO_REUSEADDRr Z
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__c C s | j � dS )zCClose underlying socket when this object goes out of scope
N)�close)r r r r �__del__3 s zSSLSocket.__del__c C s | j S )z1Buffer size for makefile method recv() operations)�_SSLSocket__buf_size)r r r r r 8 s zSSLSocket.buf_sizec C s$ t |t�stdt|� ��|| _dS )z1Buffer size for makefile method recv() operationsz1Expecting int type for "buf_size"; got %r insteadN)�
isinstance�int� TypeError�typer )r �valuer r r r = s
c C sJ | j dk r8y| jj� W qF tjtjfk
r4 Y qFX n| j d8 _ dS )zVShutdown the SSL connection and call the close method of the
underlying socketr N)r
r �shutdownr �Error�SysCallError)r r r r r E s
zSSLSocket.closec C s | j j|� 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 �moder r r r Q s zSSLSocket.set_shutdownc C s
| j j� 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)r r r r r X s zSSLSocket.get_shutdownc C s | j j|� 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 �addrr r r r _ s zSSLSocket.bindc C s | j j|� 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)r Zbacklogr r r r"