mtgdeck package

Submodules

mtgdeck.decoder module

Decoder implementations for mtgdeck.

class mtgdeck.decoder.AutoDecoder[source]

Bases: mtgdeck.base.decoder.Decoder

Auto-decoding class.

Determines the input decoding format by try-catching until it succeeds. If it fails, raises a DecodeError exception.

loads(string)[source]

Try to decode string with different decoders.

Raise DecodeError if all decoders are exhausted.

class mtgdeck.decoder.CockatriceDecoder[source]

Bases: mtgdeck.base.decoder.XMLDecoder

Decoding class for the Cockatrice format.

count = 'number'
root = 'cockatrice_deck'
section = 'zone'
exception mtgdeck.decoder.DecodeError[source]

Bases: Exception

Format decoding exception.

class mtgdeck.decoder.MagicOnlineDecoder[source]

Bases: mtgdeck.base.decoder.TextDecoder

Decoding class for the simple text format.

card = {empty rest of line}
comment = C++ style comment
count = W:(0123...)
deck = {{{C++ style comment | Group:("Sideboard")} | Group:({W:(0123...) {empty rest of line}})}}...
decode_entry(entry)[source]

Return (card name (str), attributes (dict)) from entry.

entry = Group:({W:(0123...) {empty rest of line}})
section = Group:("Sideboard")
setid = nested [] expression
class mtgdeck.decoder.MagicWorkstationDecoder[source]

Bases: mtgdeck.base.decoder.TextDecoder

Decoding class for the Magic Workstation format.

card = {empty rest of line}
comment = C++ style comment
count = W:(0123...)
deck = {{C++ style comment | Group:({{{[Group:("SB:")] W:(0123...)} [nested [] expression]} {empty rest of line}})}}...
decode_entry(entry)[source]

Return (card name (str), attributes (dict)) from entry.

entry = Group:({{{[Group:("SB:")] W:(0123...)} [nested [] expression]} {empty rest of line}})
section = Group:("SB:")
setid = nested [] expression
class mtgdeck.decoder.OCTGNDecoder[source]

Bases: mtgdeck.base.decoder.XMLDecoder

Decoding class for the OCTGN Deck Creator format.

count = 'qty'
root = 'deck'
section = 'section'

mtgdeck.encoder module

Encoder implementations for mtgdeck.

class mtgdeck.encoder.CockatriceEncoder[source]

Bases: mtgdeck.base.encoder.XMLEncoder

Encoding class for the Cockatrice format.

count = 'number'
root = 'cockatrice_deck'
section = 'zone'
section_name = 'main'
set_content(card, name)[source]
exception mtgdeck.encoder.EncodeError[source]

Bases: Exception

Format encoding exception.

class mtgdeck.encoder.MagicOnlineEncoder[source]

Bases: mtgdeck.base.encoder.TextEncoder

Encoding class for the simple text format.

This is the format that MTGO outputs. Each line has the form ‘quantity name’. An optional line containing the word ‘Sideboard’ indicates that subsequent entries are sideboard material.

encode_entry(name, attrs)[source]
class mtgdeck.encoder.MagicWorkstationEncoder[source]

Bases: mtgdeck.base.encoder.TextEncoder

Encoding class for the Magic Workstation format.

Each line has the form ‘[SB: ]quantity [SETID ]name’, ‘[]’ meaning optional fields.

encode_entry(name, attrs)[source]
class mtgdeck.encoder.OCTGNEncoder[source]

Bases: mtgdeck.base.encoder.XMLEncoder

Encoding class for the OCTGN Deck Creator format.

count = 'qty'
root = 'deck'
section = 'section'
section_name = 'Main'
set_content(card, name)[source]

Module contents

Public API entry-point for mtgdeck.

mtgdeck.load(fin, cls=<class 'mtgdeck.decoder.AutoDecoder'>)[source]

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

To use a custom MTGDeckDecoder subclass, specify it with the cls kwarg; otherwise AutoDecoder is used.

mtgdeck.loads(string, cls=<class 'mtgdeck.decoder.AutoDecoder'>)[source]

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

To use a custom MTGDeckDecoder subclass, specify it with the cls kwarg; otherwise AutoDecoder is used.

mtgdeck.dump(obj, fout, cls=<class 'mtgdeck.encoder.MagicOnlineEncoder'>)[source]

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

To use a custom Encoder subclass, specify it with the cls kwarg; otherwise Encoder is used.

mtgdeck.dumps(obj, cls=<class 'mtgdeck.encoder.MagicOnlineEncoder'>)[source]

Serialize obj to a MTG decklist formatted str.

To use a custom Encoder subclass, specify it with the cls kwarg; otherwise Encoder is used.

exception mtgdeck.DecodeError[source]

Bases: Exception

Format decoding exception.

class mtgdeck.AutoDecoder[source]

Bases: mtgdeck.base.decoder.Decoder

Auto-decoding class.

Determines the input decoding format by try-catching until it succeeds. If it fails, raises a DecodeError exception.

loads(string)[source]

Try to decode string with different decoders.

Raise DecodeError if all decoders are exhausted.

class mtgdeck.MagicOnlineDecoder[source]

Bases: mtgdeck.base.decoder.TextDecoder

Decoding class for the simple text format.

card = {empty rest of line}
comment = C++ style comment
count = W:(0123...)
deck = {{{C++ style comment | Group:("Sideboard")} | Group:({W:(0123...) {empty rest of line}})}}...
decode_entry(entry)[source]

Return (card name (str), attributes (dict)) from entry.

entry = Group:({W:(0123...) {empty rest of line}})
section = Group:("Sideboard")
setid = nested [] expression
class mtgdeck.MagicWorkstationDecoder[source]

Bases: mtgdeck.base.decoder.TextDecoder

Decoding class for the Magic Workstation format.

card = {empty rest of line}
comment = C++ style comment
count = W:(0123...)
deck = {{C++ style comment | Group:({{{[Group:("SB:")] W:(0123...)} [nested [] expression]} {empty rest of line}})}}...
decode_entry(entry)[source]

Return (card name (str), attributes (dict)) from entry.

entry = Group:({{{[Group:("SB:")] W:(0123...)} [nested [] expression]} {empty rest of line}})
section = Group:("SB:")
setid = nested [] expression
class mtgdeck.OCTGNDecoder[source]

Bases: mtgdeck.base.decoder.XMLDecoder

Decoding class for the OCTGN Deck Creator format.

count = 'qty'
root = 'deck'
section = 'section'
class mtgdeck.CockatriceDecoder[source]

Bases: mtgdeck.base.decoder.XMLDecoder

Decoding class for the Cockatrice format.

count = 'number'
root = 'cockatrice_deck'
section = 'zone'
exception mtgdeck.EncodeError[source]

Bases: Exception

Format encoding exception.

class mtgdeck.MagicOnlineEncoder[source]

Bases: mtgdeck.base.encoder.TextEncoder

Encoding class for the simple text format.

This is the format that MTGO outputs. Each line has the form ‘quantity name’. An optional line containing the word ‘Sideboard’ indicates that subsequent entries are sideboard material.

encode_entry(name, attrs)[source]
class mtgdeck.MagicWorkstationEncoder[source]

Bases: mtgdeck.base.encoder.TextEncoder

Encoding class for the Magic Workstation format.

Each line has the form ‘[SB: ]quantity [SETID ]name’, ‘[]’ meaning optional fields.

encode_entry(name, attrs)[source]
class mtgdeck.OCTGNEncoder[source]

Bases: mtgdeck.base.encoder.XMLEncoder

Encoding class for the OCTGN Deck Creator format.

count = 'qty'
root = 'deck'
section = 'section'
section_name = 'Main'
set_content(card, name)[source]
class mtgdeck.CockatriceEncoder[source]

Bases: mtgdeck.base.encoder.XMLEncoder

Encoding class for the Cockatrice format.

count = 'number'
root = 'cockatrice_deck'
section = 'zone'
section_name = 'main'
set_content(card, name)[source]