Package ndg :: Package httpsclient :: Module ssl_socket :: Class SSLSocket
[hide private]

Class SSLSocket

source code


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.

Instance Methods [hide private]
 
__init__(self, ctx, sock=None)
Create SSL socket object
source code
 
__del__(self)
Close underlying socket when this object goes out of scope
source code
 
close(self)
Shutdown the SSL connection and call the close method of the underlying socket
source code
 
set_shutdown(self, mode)
Set the shutdown state of the Connection.
source code
 
get_shutdown(self)
Get the shutdown state of the Connection.
source code
 
bind(self, addr)
bind to the given address - calls method of the underlying socket
source code
 
listen(self, backlog)
Listen for connections made to the socket.
source code
 
set_accept_state(self)
Set the connection to work in server mode.
source code
tuple
accept(self)
Accept an SSL connection.
source code
 
set_connect_state(self)
Set the connection to work in client mode.
source code
 
connect(self, addr)
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.
source code
bool
shutdown(self, how)
Send the shutdown message to the Connection.
source code
 
renegotiate(self)
Renegotiate this connection's SSL parameters.
source code
int
pending(self)
Returns: numbers of bytes that can be safely read from the SSL buffer.
source code
 
send(self, data, *flags_arg)
Send data to the socket.
source code
 
sendall(self, data) source code
string
recv(self, size=8192)
Receive data from the Connection.
source code
 
setblocking(self, mode)
Set this connection's underlying socket blocking _mode_.
source code
int
fileno(self)
Returns: file descriptor number for the underlying socket
source code
 
getsockopt(self, *args)
See socket.socket.getsockopt
source code
int/string
setsockopt(self, *args)
See socket.socket.setsockopt
source code
 
state_string(self)
Return the SSL state of this connection.
source code
cStringIO.StringO
makefile(self, *args)
Specific to Python socket API and required by httplib: convert response into a file-like object.
source code
 
getsockname(self)
Returns: the socket's own address
source code
 
getpeername(self)
Returns: remote address to which the socket is connected
source code
 
get_context(self)
Retrieve the Context object associated with this Connection.
source code
 
get_peer_certificate(self)
Retrieve the other side's certificate (if any)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
int default_buf_size = 8192
default buffer size for recv operations in the makefile method
Properties [hide private]
  buf_size
Buffer size for makefile method recv() operations

Inherited from object: __class__

Method Details [hide private]

__init__(self, ctx, sock=None)
(Constructor)

source code 

Create SSL socket object

Parameters:
  • ctx (OpenSSL.SSL.Context) - SSL context
  • sock (socket.socket) - underlying socket object
Overrides: object.__init__

set_shutdown(self, mode)

source code 

Set the shutdown state of the Connection.

Parameters:
  • mode - bit vector of either or both of SENT_SHUTDOWN and RECEIVED_SHUTDOWN

get_shutdown(self)

source code 

Get the shutdown state of the Connection.

Returns:
bit vector of either or both of SENT_SHUTDOWN and RECEIVED_SHUTDOWN

bind(self, addr)

source code 

bind to the given address - calls method of the underlying socket

Parameters:
  • addr (tuple) - address/port number tuple

listen(self, backlog)

source code 

Listen for connections made to the socket.

Parameters:
  • backlog - specifies the maximum number of queued connections and should be at least 1; the maximum value is system-dependent (usually 5).
  • backlog - int

set_accept_state(self)

source code 

Set the connection to work in server mode. The handshake will be handled automatically by read/write

accept(self)

source code 

Accept an SSL connection.

Returns: tuple
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.

set_connect_state(self)

source code 

Set the connection to work in client mode. The handshake will be handled automatically by read/write

connect(self, addr)

source code 

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.

Parameters:
  • addr (tuple) - address/port number pair

shutdown(self, how)

source code 

Send the shutdown message to the Connection.

Parameters:
  • 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
Returns: bool
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.

pending(self)

source code 
Returns: int
numbers of bytes that can be safely read from the SSL buffer.

send(self, data, *flags_arg)

source code 

Send data to the socket. Nb. The optional flags argument is ignored.

  • retained for compatibility with socket.socket interface
Parameters:
  • data (string) - data to send down the socket

recv(self, size=8192)

source code 

Receive data from the Connection.

Parameters:
  • size (int) - The maximum amount of data to be received at once
Returns: string
data received.

setblocking(self, mode)

source code 

Set this connection's underlying socket blocking _mode_.

Parameters:
  • mode (int) - blocking mode

fileno(self)

source code 
Returns: int
file descriptor number for the underlying socket

setsockopt(self, *args)

source code 

See socket.socket.setsockopt

Returns: int/string
value of the given socket option

makefile(self, *args)

source code 

Specific 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

Returns: cStringIO.StringO
file object for data returned from socket

getsockname(self)

source code 
Returns:
the socket's own address

getpeername(self)

source code 
Returns:
remote address to which the socket is connected

Property Details [hide private]

buf_size

Buffer size for makefile method recv() operations

Get Method:
unreachable.buf_size(self) - Buffer size for makefile method recv() operations
Set Method:
unreachable.buf_size(self, value) - Buffer size for makefile method recv() operations