transit package

Submodules

transit.class_hash module

class transit.class_hash.ClassDict(*args, **kwargs)[source]

Bases: _abcoll.MutableMapping

A dictionary that looks up class/type keys with inheritance

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_hash(hash, cache, as_map_key)[source]
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

decode_string(string, cache, as_map_key)[source]

Decode a string - arguments follow the same convention as the top-level ‘decode’ function

decode_tag(tag, rep)[source]
parse_string(string, cache, as_map_key)[source]
register(key_or_tag, obj)[source]

Register a custom Transit tag and new parsing function with the decoder. Also, you can optionally set the ‘default_decoder’ with this function. Your new tag and parse/decode function will be added to the interal dictionary of decoders for this Decoder object

class transit.decoder.Tag(tag)[source]

Bases: object

transit.helpers module

transit.helpers.mapcat(f, i)[source]
transit.helpers.pairs(i)[source]
transit.helpers.take(n, i)[source]

transit.read_handlers module

class transit.read_handlers.BigIntegerHandler[source]

Bases: object

static from_rep(d)[source]
class transit.read_handlers.BooleanHandler[source]

Bases: object

static from_rep(x)[source]
class transit.read_handlers.CmapHandler[source]

Bases: object

static from_rep(cmap)[source]
class transit.read_handlers.DateHandler[source]

Bases: object

static from_rep(d)[source]
class transit.read_handlers.DefaultHandler[source]

Bases: object

static from_rep(t, v)[source]
class transit.read_handlers.FloatHandler[source]

Bases: object

static from_rep(v)[source]
class transit.read_handlers.IdentityHandler[source]

Bases: object

static from_rep(i)[source]
class transit.read_handlers.IntHandler[source]

Bases: object

static from_rep(v)[source]
class transit.read_handlers.KeywordHandler[source]

Bases: object

static from_rep(v)[source]
class transit.read_handlers.LinkHandler[source]

Bases: object

static from_rep(l)[source]
class transit.read_handlers.ListHandler[source]

Bases: object

static from_rep(l)[source]
class transit.read_handlers.NoneHandler[source]

Bases: object

static from_rep(_)[source]
class transit.read_handlers.SetHandler[source]

Bases: object

static from_rep(s)[source]
class transit.read_handlers.SymbolHandler[source]

Bases: object

static from_rep(v)[source]
class transit.read_handlers.UriHandler[source]

Bases: object

static from_rep(u)[source]
class transit.read_handlers.UuidHandler[source]

Bases: object

static from_rep(u)[source]

Given a string, return a UUID object

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.

load(stream)[source]
class transit.reader.MsgPackUnmarshaler[source]

Bases: object

The top-level Unmarshaler used by the Reader for MsgPacke payloads. While you may use this directly, it is strongly discouraged.

load(stream)[source]
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.

register(key_or_tag, f_val)[source]

Register a custom transit tag and decoder/parser function for use during reads.

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.

clear()[source]
decode(name, as_map_key=False)[source]

Always returns the name

encache(name)[source]
encode(name, as_map_key=False)[source]

Returns the name the first time and the key after that

is_cache_full()[source]
size()[source]
transit.rolling_cache.decode_key(s)[source]
transit.rolling_cache.encode_key(i)[source]
transit.rolling_cache.is_cache_key(name)[source]
transit.rolling_cache.is_cacheable(string, as_map_key=False)[source]

transit.transit_types module

class transit.transit_types.Array(rep)[source]

Bases: transit.transit_types.TaggedValue

class transit.transit_types.CMap(rep)[source]

Bases: transit.transit_types.TaggedValue

class transit.transit_types.Keyword(value)[source]

Bases: object

Bases: object

HREF = 'href'
IMAGE = 'image'
NAME = 'name'
PROMPT = 'prompt'
REL = 'rel'
RENDER = 'render'
as_array[source]
as_map[source]
href[source]
name[source]
prompt[source]
rel[source]
render[source]
class transit.transit_types.List(rep)[source]

Bases: transit.transit_types.TaggedValue

class transit.transit_types.Set(rep)[source]

Bases: transit.transit_types.TaggedValue

class transit.transit_types.Symbol(value)[source]

Bases: object

class transit.transit_types.TaggedValue(tag, rep)[source]

Bases: object

class transit.transit_types.URI(rep)[source]

Bases: transit.transit_types.TaggedValue

class transit.transit_types.Vector(rep)[source]

Bases: transit.transit_types.TaggedValue

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.ArrayHandler[source]

Bases: object

static rep(a)[source]
static string_rep(a)[source]
static tag(a)[source]
class transit.write_handlers.BigIntHandler[source]

Bases: object

static rep(n)[source]
static string_rep(n)[source]
static tag(_)[source]
class transit.write_handlers.BooleanHandler[source]

Bases: object

static rep(b)[source]
static string_rep(b)[source]
static tag(_)[source]
class transit.write_handlers.DateTimeHandler[source]

Bases: object

epoch = datetime.datetime(1970, 1, 1, 0, 0, tzinfo=tzutc())
static rep(d)[source]
static string_rep(d)[source]
static tag(_)[source]
static verbose_handler()[source]
class transit.write_handlers.FloatHandler[source]

Bases: object

static rep(f)[source]
static string_rep(f)[source]
static tag(_)[source]
class transit.write_handlers.IntHandler[source]

Bases: object

static rep(i)[source]
static string_rep(i)[source]
static tag(i)[source]
class transit.write_handlers.KeywordHandler[source]

Bases: object

static rep(k)[source]
static string_rep(k)[source]
static tag(k)[source]
class transit.write_handlers.LinkHandler[source]

Bases: object

static rep(l)[source]
static string_rep(_)[source]
static tag(_)[source]
class transit.write_handlers.MapHandler[source]

Bases: object

static rep(m)[source]
static string_rep(_)[source]
static tag(_)[source]
class transit.write_handlers.NoneHandler[source]

Bases: object

static rep(_)[source]
static string_rep(n)[source]
static tag(_)[source]
class transit.write_handlers.SetHandler[source]

Bases: object

static rep(s)[source]
static string_rep(_)[source]
static tag(_)[source]
class transit.write_handlers.StringHandler[source]

Bases: object

static rep(s)[source]
static string_rep(s)[source]
static tag(s)[source]
class transit.write_handlers.SymbolHandler[source]

Bases: object

static rep(s)[source]
static string_rep(s)[source]
static tag(s)[source]
class transit.write_handlers.TaggedMap(tag, rep, str)[source]

Bases: object

rep()[source]
string_rep()[source]
tag()[source]
class transit.write_handlers.TaggedValueHandler[source]

Bases: object

static rep(tv)[source]
static string_rep(_)[source]
static tag(tv)[source]
class transit.write_handlers.UriHandler[source]

Bases: object

static rep(u)[source]
static string_rep(u)[source]
static tag(_)[source]
class transit.write_handlers.UuidHandler[source]

Bases: object

mask = 18446744073709551615L
static rep(u)[source]
static string_rep(u)[source]
static tag(_)[source]
class transit.write_handlers.VerboseDateTimeHandler[source]

Bases: object

static rep(d)[source]
static string_rep(d)[source]
static tag(_)[source]
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 = 9223372036854775808L
JSON_MIN_INT = -9223372036854775808L
default_opts = {'min_int': -9223372036854775808L, 'max_int': 9223372036854775808L, 'prefer_strings': True}
emit_array_end()[source]
emit_array_start(size)[source]
emit_map(m, _, cache)[source]

Emits array as per default JSON spec.

emit_map_end()[source]
emit_map_start(size)[source]
emit_object(obj, as_map_key=False)[source]
pop_level()[source]
push_level()[source]
push_map()[source]
write_sep()[source]
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.

emit_array(a, _, cache)[source]
emit_boolean(b, as_map_key, cache)[source]
emit_cmap(m, _, cache)[source]
emit_double(d, as_map_key, cache)[source]
emit_encoded(tag, handler, obj, as_map_key, cache)[source]
emit_int(i, as_map_key, cache)[source]
emit_map(m, _, cache)[source]
emit_nil(_, as_map_key, cache)[source]
emit_string(prefix, tag, string, as_map_key, cache)[source]
emit_tagged(tag, rep, _, cache)[source]
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.

marshal_top(obj, cache=None)[source]

Given a complete object that needs to be marshaled into Transit data, and optionally a cache, dispatch accordingly, and flush the data directly into the IO stream.

register(obj_type, handler_class)[source]

Register custom converters for object types present in your application. This allows you to extend Transit to encode new types. You must specify the obj type to be encoded, and the handler class that should be used by this marshaller.

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}
emit_array_end()[source]
emit_array_start(size)[source]
emit_map_end()[source]
emit_map_start(size)[source]
emit_object(obj, as_map_key=False)[source]
flush()[source]
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.

emit_map(m, _, cache)[source]
emit_string(prefix, tag, string, as_map_key, cache)[source]
emit_tagged(tag, rep, _, cache)[source]
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.

register(obj_type, handler_class)[source]

Register custom converters for object types present in your application. This allows you to extend Transit to encode new types. You must specify the obj type to be encoded, and the handler class that should be used by the Marshaler during write-time.

write(obj)[source]

Given a Python object, marshal it into Transit data and write it to the ‘io’ source.

transit.writer.escape(s)[source]
transit.writer.flatten_map(m)[source]

Expand a dictionary’s items into a flat list

transit.writer.is_escapable(value)
transit.writer.re_fn(pat)[source]

Module contents