pyxmpp2.transport.TCPTransport

Package pyxmpp2 :: Module transport :: Class TCPTransport |
[hide private]

# Class TCPTransport

XMPP over TCP with optional TLS.

Nested Classes | [hide private]
Inherited from `interfaces.XMPPTransport`: `__metaclass__`

Instance Methods | [hide private]
__init__(self, settings=None, sock=None) Initialize the TCPTransport object. |
_set_state(self, state) Set _state and notify any threads waiting for the change. |
connect(self, addr, port=None, service=None) Start establishing TCP connection with given address. |
_connect(self, addr, port, service) Same as connect, but assumes lock acquired. |
_resolve_srv(self) Start resolving the SRV record. |
_got_srv(self, addrs) Handle SRV lookup result. |
_resolve_hostname(self) Start hostname resolution for the next name to try. |
_got_addresses(self, name, port, addrs) Handler DNS address record lookup result. |
_start_connect(self) Start connecting to the next address on the _dst_addrs list. |
_continue_connect(self) Continue connecting. |
_write(self, data) Write raw data to the socket. |
set_target(self, stream) Make the `stream` the target for this transport instance. |
send_stream_head(self, stanza_namespace, stream_from, stream_to, stream_id=None, version=`u'``1.0``'`, language=None) Send stream head via the transport. |
restart(self) Restart the stream after SASL or StartTLS handshake. |
send_stream_tail(self) Send stream tail via the transport. |
send_element(self, element) Send an element via the transport. |
IOHandlerPrepareResult |
prepare(self) When connecting start the next connection step and schedule next prepare call, when connected return HandlerReady() |
fileno(self) Return file descriptor to poll or select. |
is_readable(self) Returns: `True` when the I/O channel can be read |
wait_for_readability(self) Stop current thread until the channel is readable. |
is_writable(self) Returns: `False` as currently the data is always written synchronously |
wait_for_writability(self) Stop current thread until the channel is writable. |
handle_write(self) Handle the 'channel writable' state. |
starttls(self, **kwargs) Request a TLS handshake on the socket ans switch to encrypted output. |
getpeercert(self) Return the peer certificate. |
_initiate_starttls(self, **kwargs) Initiate starttls handshake over the socket. |
_continue_tls_handshake(self) Continue a TLS handshake. |
handle_read(self) Handle the 'channel readable' state. |
handle_hup(self) Handle the 'channel hungup' state. |
handle_err(self) Handle an error reported. |
handle_nval(self) Handle an error reported. |
is_connected(self) Check if the transport is connected. |
disconnect(self) Disconnect the stream gracefully. |
close(self) Close the stream immediately, so it won't expect more events. |
_close(self) Same as _close but expects lock acquired. |
_feed_reader(self, data) Feed the stream reader with data received. |
event(self, event) Pass an event to the target stream or just log it. |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables | [hide private]
Inherited from `interfaces.XMPPTransport`: `__abstractmethods__` Inherited from `interfaces.XMPPTransport` (private): `_abc_cache`, `_abc_negative_cache`, `_abc_negative_cache_version`, `_abc_registry`

Instance Variables | [hide private]
tuple | _dst_addr socket address currently in use
list of tuples | _dst_addrs list of (family, sockaddr) candidates to connect to
`int` | _dst_family address family of the socket
`unicode` | _dst_hostname hostname the transport is connecting to or connected to
`unicode` | _dst_name requested domain name of the remote service
list of tuples | _dst_nameports list of (hostname, port) candidates to connect to
`int` | _dst_port requested port of the remote service
`unicode` | _dst_service requested service name (e.g.
`bool` | _eof `True` when reading side of the socket is closed
`Queue.Queue` | _event_queue queue to send connection events to
`bool` | _hup `True` when the writing side of the socket is closed
StreamReader | _reader parser for the data received from the socket
XMPPSerializer | _serializer XML serializer for data sent over the socket
`socket.socket` | _socket socket currently used by the transport (`None` if no
`unicode` | _state connection state (one of: `None`, "resolve-srv", "resolve-hostname", "connect", "connected", "tls-handshake", "closing", "closed", "aborted")
`threading.Condition` | _state_cond condition object to synchronize threads over state change
streambase.StreamBase | _stream the stream associated with this transport
`unicode` | _tls_state state of TLS handshake
`threading.RLock` | lock the lock protecting this object
XMPPSettings | settings settings for this object socket is currently open)

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, settings=None, sock=None) (Constructor) |
Initialize the TCPTransport object. Parameters: `settings` - XMPP settings to use `sock` - existing socket, e.g. for accepted incoming connection. Overrides: object.__init__

### connect(self, addr, port=None, service=None) |
Start establishing TCP connection with given address. One of: `port` or `service` must be provided and `addr` must be a domain name and not an IP address if `port` is not given. When `service` is given try an SRV lookup for that service at domain `addr`. If `service` is not given or `addr` is an IP address, or the SRV lookup fails, connect to `port` at host `addr` directly. [initiating entity only] Parameters: `addr` - peer name or IP address `port` - port number to connect to `service` - service name (to be resolved using SRV DNS records)

### _got_srv(self, addrs) |
Handle SRV lookup result. Parameters: `addrs` - properly sorted list of (hostname, port) tuples

### _resolve_hostname(self) |
Start hostname resolution for the next name to try. [called with lock acquired]

### _got_addresses(self, name, port, addrs) |
Handler DNS address record lookup result. Parameters: `name` - the name requested `port` - port number to connect to `addrs` - list of (family, address) tuples

### _start_connect(self) |
Start connecting to the next address on the _dst_addrs list. [ called with lock acquired ]

### _continue_connect(self) |
Continue connecting. [called with lock acquired] Returns: `True` when just connected

### _write(self, data) |
Write raw data to the socket. Parameters: `data` (`bytes`) - data to send

### set_target(self, stream) |
Make the `stream` the target for this transport instance. The 'stream_start', 'stream_end' and 'stream_element' methods of the target will be called when appropriate content is received. Parameters: `stream` (StreamBase) - the stream handler to receive stream content from the transport Overrides: interfaces.XMPPTransport.set_target

### send_stream_head(self, stanza_namespace, stream_from, stream_to, stream_id=None, version=`u'``1.0``'`, language=None) |
Send stream head via the transport. Parameters: `stanza_namespace` (`unicode`) - namespace of stream stanzas (e.g. 'jabber:client') `stream_from` (`unicode`) - the 'from' attribute of the stream. May be `None`. `stream_to` (`unicode`) - the 'to' attribute of the stream. May be `None`. `version` (`unicode`) - the 'version' of the stream. `language` (`unicode`) - the 'xml:lang' of the stream Overrides: interfaces.XMPPTransport.send_stream_head

### restart(self) |
Restart the stream after SASL or StartTLS handshake. Overrides: interfaces.XMPPTransport.restart

### send_stream_tail(self) |
Send stream tail via the transport. Overrides: interfaces.XMPPTransport.send_stream_tail

### send_element(self, element) |
Send an element via the transport. Overrides: interfaces.XMPPTransport.send_element

### prepare(self) |
When connecting start the next connection step and schedule next prepare call, when connected return HandlerReady() Returns: IOHandlerPrepareResult HandlerReady() if there is no need to call prepare again or PrepareAgain() otherwise. Overrides: mainloop.interfaces.IOHandler.prepare

### fileno(self) |
Return file descriptor to poll or select. Overrides: mainloop.interfaces.IOHandler.fileno

### is_readable(self) |
Returns: `True` when the I/O channel can be read Overrides: mainloop.interfaces.IOHandler.is_readable

### wait_for_readability(self) |
Stop current thread until the channel is readable. Returns: `False` if it won't be readable (e.g. is closed) Overrides: mainloop.interfaces.IOHandler.wait_for_readability

### is_writable(self) |
Returns: `False` as currently the data is always written synchronously Overrides: mainloop.interfaces.IOHandler.is_writable

### wait_for_writability(self) |
Stop current thread until the channel is writable. Returns: `False` if it won't be readable (e.g. is closed) Overrides: mainloop.interfaces.IOHandler.wait_for_writability

### handle_write(self) |
Handle the 'channel writable' state. E.g. send buffered data via a socket. Overrides: mainloop.interfaces.IOHandler.handle_write

### starttls(self, **kwargs) |
Request a TLS handshake on the socket ans switch to encrypted output. The handshake will start after any currently buffered data is sent. Parameters: `kwargs` - arguments for `ssl.wrap_socket`

### getpeercert(self) |
Return the peer certificate. The format is the same as for the standard `ssl.SSLSocket.getpeercert()` method, but may (in future) include data not normally recognized by Python.

### handle_read(self) |
Handle the 'channel readable' state. E.g. read from a socket. Overrides: mainloop.interfaces.IOHandler.handle_read

### handle_hup(self) |
Handle the 'channel hungup' state. The handler should not be writtable after this. Overrides: mainloop.interfaces.IOHandler.handle_hup

### handle_err(self) |
Handle an error reported. Overrides: mainloop.interfaces.IOHandler.handle_err

### handle_nval(self) |
Handle an error reported. Overrides: mainloop.interfaces.IOHandler.handle_nval

### is_connected(self) |
Check if the transport is connected. Returns: `True` if is connected. Overrides: interfaces.XMPPTransport.is_connected

### disconnect(self) |
Disconnect the stream gracefully. Overrides: interfaces.XMPPTransport.disconnect

### close(self) |
Close the stream immediately, so it won't expect more events. Overrides: mainloop.interfaces.IOHandler.close

### _feed_reader(self, data) |
Feed the stream reader with data received. [ called with lock acquired ] If `data` is None or empty, then stream end (peer disconnected) is assumed and the stream is closed. lock is acquired during the operation. Parameters: `data` (`unicode`) - data received from the stream socket.

Instance Variable Details | [hide private]

### _dst_service requested service name (e.g. 'xmpp-client') Type: `unicode`