mtgdeck.base package

Submodules

mtgdeck.base.decoder module

Abstract base decoder classes.

class mtgdeck.base.decoder.Decoder[source]

Bases: object

Abstract base class for decoders.

Decoders are expected to implement a single method, _decode().

load(fin)[source]

Deserialize fin (a .read()-supporting file-like object containing an MTG decklist) to a Python object.

loads(string)[source]

Deserialize string (a str, bytes or bytearray instance containing an MTG decklist) to a Python object.

class mtgdeck.base.decoder.TextDecoder[source]

Bases: mtgdeck.base.decoder.Decoder

Abstract base class for text-based decoders.

Decoders are expected to set the deck property, and override the decode_entry method.

deck

Pyparsing parser that should consume the full input string.

A OneOrMore-wrapped pyparsing parser capable of consuming the full input string.

decode_entry(entry)[source]

Extract and return from entry a (card name (str), attributes (dict)).

entry is a tuple argument (as returned by the parseString method on deck.)

class mtgdeck.base.decoder.XMLDecoder[source]

Bases: mtgdeck.base.decoder.Decoder

Abstract base class for XML-based decoders.

Decoders are expected to set the root, section and count properties.

count

Quantity (ie: qty, number) tag for the XML decoding format.

root

Root (top-level) tag for the XML decoding format.

section

Section (ie: sideboard) tag for the XML decoding format.

mtgdeck.base.encoder module

Abstract base encoder classes.

class mtgdeck.base.encoder.Encoder[source]

Bases: object

Abstract base class for encoders.

Encoders are expected to implement a single method, _encode().

dump(obj, fout)[source]

Serialize obj as a MTG decklist formatted stream to fout (a .write()-supporting file-like object).

dumps(obj)[source]

Serialize obj to a MTG decklist formatted str.

class mtgdeck.base.encoder.TextEncoder[source]

Bases: mtgdeck.base.encoder.Encoder

Abstract base class for text-based encoders.

Encoders are expected to override the encode_entry method.

encode_entry(name, attrs)[source]

Build and return from name and attrs an encoded entry string.

(name, attrs) is a tuple argument (str, dict).

class mtgdeck.base.encoder.XMLEncoder[source]

Bases: mtgdeck.base.encoder.Encoder

Abstract base class for XML-based encoders.

Encoders are expected to set the root, section, section_name and count properties, and the set_content method.

count

Quantity (ie: qty, number) tag for the XML encoding format.

root

Root (top-level) tag for the XML encoding format.

section

Section (ie: sideboard, etc) tag for the XML encoding format.

section_name

Section name(ie: sideboard) tag for the XML encoding format.

set_content(card, name)[source]

Set name in card.

card is an ElementTree.Element, and name should be set either as an attribute (card.attribs['key']) or as the text node (card.text).

Module contents

Abstract base classes.