Shared code for test data transports..

plainbox.impl.transport – shared code for test data transports

Warning

THIS MODULE DOES NOT HAVE STABLE PUBLIC API

class plainbox.impl.transport.CertificationTransport(where, options)[source]

Bases: plainbox.impl.transport.TransportBase

Transport for sending data to certification database.

  • POSTs data to a http(s) endpoint
  • Adds a header with a hardware identifier
  • Data is expected to be in checkbox xml-compatible format. This means it will work best with a stream produced by the xml exporter.
send(data, config=None, session_state=None)[source]

Send data to the specified server.

Parameters:
  • data – Data containing the xml dump to be sent to the server. This can be either bytes or a file-like object (BytesIO works fine too). If this is a file-like object, it will be read and streamed “on the fly”.
  • config – Optional PlainBoxConfig object. If http_proxy and https_proxy values are set in this config object, they will be used to send data via the specified protocols. Note that the transport also honors the http_proxy and https_proxy environment variables. Proxy string format is http://[user:password@]<proxy-ip>:port
  • session_state – The session for which this transport is associated with the data being sent (optional)
Returns:

A dictionary with responses from the server if submission was successful. This should contain an ‘id’ key, however the server response may change, so the only guarantee we make is that this will be non-False if the server accepted the data.

Raises:
  • requests.exceptions.Timeout – If sending timed out.
  • requests.exceptions.ConnectionError – If connection failed outright.
  • requests.exceptions.HTTPError – If the server returned a non-success result code
class plainbox.impl.transport.FileTransport(where, options=None)[source]

Bases: plainbox.impl.transport.TransportBase

send(data, config=None, session_state=None)[source]

Write data to the specified file.

Parameters:
  • data – Data to be written to the stream.This can be either bytes or a file-like object (BytesIO works fine too). If this is a file-like object, it will be read and streamed “on the fly”.
  • config – Optional PlainBoxConfig object.
  • session_state – The session for which this transport is associated with the data being sent (optional)
Returns:

A dictionary with url pointing to the file.

Raises:

OSError – When there was IO related error.

exception plainbox.impl.transport.InvalidSecureIDError(value)[source]

Bases: ValueError

Exception raised when the secure ID is formatted incorrectly.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class plainbox.impl.transport.NoOauthTransport(**args)[source]

Bases: object

plainbox.impl.transport.OAuthTransport

alias of NoOauthTransport

class plainbox.impl.transport.StreamTransport(stream, options=None)[source]

Bases: plainbox.impl.transport.TransportBase

Transport for printing data to a stream (stdout or stderr).

send(data, config=None, session_state=None)[source]

Write data to the specified stream.

Parameters:
  • data – Data to be written to the stream.This can be either bytes or a file-like object (BytesIO works fine too). If this is a file-like object, it will be read and streamed “on the fly”.
  • config – Optional PlainBoxConfig object.
  • session_state – The session for which this transport is associated with the data being sent (optional)
Returns:

Empty dictionary

class plainbox.impl.transport.TransportBase(where, option_string)[source]

Bases: plainbox.abc.ISessionStateTransport

Base class for transports that send test data somewhere.

They handle just the transmission portion of data sending; exporters are expected to produce data in the proper format (e.g. json, xml).

Each transport can have specific parameters that are required for the other end to properly process received information (like system identification, authorization data and so on), and that don’t semantically belong in the test data as produced by the exporter. Additionally each transport needs to be told where to send test data. This is transport-dependent; things like a HTTP endpoint, IP address, port are good examples.

send(data, config=None, session_state=None)

Send data somewhere.

Parameters:
  • data – a stream-like object of data to send (read only)
  • config – a PlainBoxConfig object (optional)
  • session_state – the session for which this transport is associated with the data being sent (optional)
Raises:
  • ValueError – if any of the arguments are somehow invalid
  • TransportError – if any transport-specific problem arises
Returns:

a dictionary with additional items, see notes below

Note

The return value is especially vague specifically to allow various transports to express whatever they may need to express for a particular vertical use case yet still to allow most of the code to just work with all transports.

It is expected that certain keys in the returned dictionary will gain special semantics that can be further standardized. As of this writing there are no standard keys.

exception plainbox.impl.transport.TransportError[source]

Bases: Exception

Base class for any problems related to transports.

This class acts the base exception for any and all problems encountered by the any ISessionStateTransport during execution. Typically this is raised from .send() that failed in some way.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

plainbox.impl.transport.get_all_transports()[source]

Discover and load all transport classes.

Returns a map of transports (mapping from name to transport class)

plainbox.impl.transport.oauth_available()[source]
comments powered by Disqus