transit package¶
Submodules¶
transit.class_hash module¶
transit.constants module¶
transit.decoder module¶
-
class
transit.decoder.
Decoder
(options={})[source]¶ Bases:
object
The Decoder is the lowest level entry point for parsing, decoding, and fully converting Transit data into Python objects.
During the creation of a Decoder object, you can specify custom options in a dictionary. One such option is ‘decoders’. Note that while you can specify your own decoders and override many of the built in decoders, some decoders are silently enforced and cannot be overriden. These are known as Ground Decoders, and are needed to maintain bottom-tier compatibility.
-
decode
(node, cache=None, as_map_key=False)[source]¶ Given a node of data (any supported decodeable obj - string, dict, list), return the decoded object. Optionally set the current decode cache [None]. If None, a new RollingCache is instantiated and used. You may also hit to the decoder that this node is to be treated as a map key [False]. This is used internally.
-
decode_list
(node, cache, as_map_key)[source]¶ Special case decodes map-as-array. Otherwise lists are treated as Python lists.
Arguments follow the same convention as the top-level ‘decode’ function.
-
transit.helpers module¶
transit.read_handlers module¶
transit.reader module¶
-
class
transit.reader.
JsonUnmarshaler
[source]¶ Bases:
object
The top-level Unmarshaler used by the Reader for JSON payloads. While you may use this directly, it is strongly discouraged.
-
class
transit.reader.
MsgPackUnmarshaler
[source]¶ Bases:
object
The top-level Unmarshaler used by the Reader for MsgPack payloads. While you may use this directly, it is strongly discouraged.
-
class
transit.reader.
Reader
(protocol='json')[source]¶ Bases:
object
The top-level object for reading in Transit data and converting it to Python objects. During initialization, you must specify the protocol used for unmarshalling the data- json or msgpack.
-
read
(stream)[source]¶ Given a readable file descriptor object (something `load`able by msgpack or json), read the data, and return the Python representation of the contents. One-shot reader.
-
readeach
(stream, **kwargs)[source]¶ Temporary hook for API while streaming reads are in experimental phase. Read each object from stream as available with generator. JSON blocks indefinitely waiting on JSON entities to arrive. MsgPack requires unpacker property to be fed stream using unpacker.feed() method.
-
transit.rolling_cache module¶
-
class
transit.rolling_cache.
RollingCache
[source]¶ Bases:
object
This is the internal cache used by python-transit for cacheing and expanding map keys during writing and reading. The cache enables transit to minimize the amount of duplicate data sent over the wire, effectively compressing down the overall payload size. The cache is not intended to be used directly.
transit.transit_types module¶
-
class
transit.transit_types.
Boolean
(name)[source]¶ Bases:
object
To allow a separate t/f that won’t hash as 1/0. Don’t call directly, instead use true and false as singleton objects. Can use with type check.
Note that the Booleans are for preserving hash/set bools that duplicate 1/0 and not designed for use in Python outside logical evaluation (don’t treat as an int, they’re not). You can get a Python bool using bool(x) where x is a true or false Boolean.
-
class
transit.transit_types.
Keyword
(value)[source]¶ Bases:
transit.transit_types.Named
-
class
transit.transit_types.
Link
(href=None, rel=None, name=None, render=None, prompt=None)[source]¶ Bases:
object
-
HREF
= u'href'¶
-
IMAGE
= u'image'¶
-
LINK
= u'link'¶
-
NAME
= u'name'¶
-
PROMPT
= u'prompt'¶
-
REL
= u'rel'¶
-
RENDER
= u'render'¶
-
as_array
¶
-
as_map
¶
-
href
¶
-
name
¶
-
prompt
¶
-
rel
¶
-
render
¶
-
-
class
transit.transit_types.
Symbol
(value)[source]¶ Bases:
transit.transit_types.Named
-
class
transit.transit_types.
frozendict
(*args, **kwargs)[source]¶ Bases:
_abcoll.Mapping
,_abcoll.Hashable
-
transit.transit_types.
kws
¶
transit.write_handlers module¶
-
class
transit.write_handlers.
DateTimeHandler
[source]¶ Bases:
object
-
epoch
= datetime.datetime(1970, 1, 1, 0, 0, tzinfo=tzutc())¶
-
-
class
transit.write_handlers.
WriteHandler
[source]¶ Bases:
transit.class_hash.ClassDict
This is the master handler for encoding/writing Python data into Transit data, based on its type. The Handler itself is a dispatch map, that resolves on full type/object inheritance.
These handlers can be overriden during the creation of a Transit Writer.
transit.writer module¶
-
class
transit.writer.
JsonMarshaler
(io, opts={})[source]¶ Bases:
transit.writer.Marshaler
The Marshaler tailor to JSON. To use this Marshaler, specify the ‘json’ protocol when creating a Writer.
-
JSON_MAX_INT
= 9007199254740991¶
-
JSON_MIN_INT
= -9007199254740991¶
-
default_opts
= {'min_int': -9007199254740991, 'max_int': 9007199254740991, 'prefer_strings': True}¶
-
-
class
transit.writer.
Marshaler
(opts={})[source]¶ Bases:
object
The base Marshaler from which all Marshalers inherit.
The Marshaler specifies how to emit Transit data given encodeable Python objects. The end of this process is specialized by other Marshalers to covert the final result into an on-the-wire payload (JSON or MsgPack).
-
are_stringable_keys
(m)[source]¶ Test whether the keys within a map are stringable - a simple map, that can be optimized and whose keys can be cached
-
dispatch_map
(rep, as_map_key, cache)[source]¶ Used to determine and dipatch the writing of a map - a simple map with strings as keys, or a complex map, whose keys are also compound types.
-
marshal
(obj, as_map_key, cache)[source]¶ Marshal an individual obj, potentially as part of another container object (like a list/dictionary/etc). Specify if this object is a key to a map/dict, and pass in the current cache being used. This method should only be called by a top-level marshalling call and should not be considered an entry-point for integration.
-
-
class
transit.writer.
MsgPackMarshaler
(io, opts={})[source]¶ Bases:
transit.writer.Marshaler
The Marshaler tailor to MsgPack. To use this Marshaler, specify the ‘msgpack’ protocol when creating a Writer.
-
MSGPACK_MAX_INT
= 9223372036854775807L¶
-
MSGPACK_MIN_INT
= -9223372036854775808L¶
-
default_opts
= {'min_int': -9223372036854775808L, 'max_int': 9223372036854775807L, 'prefer_strings': False}¶
-
-
class
transit.writer.
VerboseJsonMarshaler
(io, opts={})[source]¶ Bases:
transit.writer.VerboseSettings
,transit.writer.JsonMarshaler
JsonMarshaler class with VerboseSettings mixin.
-
class
transit.writer.
VerboseSettings
[source]¶ Bases:
object
Mixin for JsonMarshaler that adds support for Verbose output/input. Verbosity is only suggest for debuging/inspecting purposes.
-
class
transit.writer.
Writer
(io, protocol='json', opts={'cache_enabled': True})[source]¶ Bases:
object
The top-level object for writing out Python objects and converting them to Transit data. During initialization, you must specify the protocol used for marshalling the data- json or msgpack. You must also specify the io source used for writing (a file descriptor). You may optionally pass in an options dictionary that will be forwarded onto the Marshaler. The cache is enabled by default.
-
transit.writer.
is_escapable
(value)¶