Generic Card Class.
Bases: object
Card can be saved to, and loaded from, a string. Call str() on a Card instance or .save_string() on the instance. This will return a string that when evaluated using eval() can be unpacked into the Card constructor re-create that card. For example. original = Card(1, 'cool card') savestring = str(card) loaded = Card(*eval(savestring)) assert loaded == original
Add the given ability to this Card under the given phase. Returns the length of the abilities for the given phase after the addition.
Add the given attribute to this Card. Returns the length of attributes after addition.
Takes a carddict as produced by Card.save and sets this card instances information to the previously saved cards information.
Generic Card Class.
Bases: object
A collection of possibly recuring cards stored as codes.
Returns how many cards in the deck have the specified value under the specified key in their info data.
This method requires a library to be stored in the deck instance and will return None if there is no library.
Returns how many cards in the deck have the specified attribute.
This method requires a library to be stored in the deck instance and will return None if there is no library.
Retrieve a card any number of cards from the top. Returns a Card object loaded from a library if one is specified otherwise just it will simply return its code.
If index is not set then the top card will be retrieved.
If cache is set to True (the default) it will tell the library to cache the returned card for faster look-ups in the future.
If remove is true then the card will be removed from the deck before returning it.
The Library class, an sqlite database of cards.
Bases: object
Library wraps an sqlite3 database that stores serialized cards.
Library also allows load and save hooks that allow a list of function to be called on each string as it is saved and loaded.
The Library constructor can take a cardclass argument which defaults to librarian.card.Card and is used to construct a card object when loading. A cardclass should be a subclass of librarian.card.Card and be able to take the original carddict constructor argument alone along with providing the original or equal Card.load and Card.save methods.
Cache the card for faster future lookups. Removes the oldest card when the card cache stores more cards then this libraries cache limit.
Return a list of codes and names pertaining to cards that have the given information values stored.
Can take a code integer, name string, abilities dict {phase: ability list/”*”}, attributes list, info dict {key, value list/”*”}.
In the above argument examples “*” is a string that may be passed instead of a list as the dict value to match anything that stores that key.
Load a card with the given code from the database. This calls each save event hook on the save string before commiting it to the database.
Will cache each resulting card for faster future lookups with this method while respecting the libraries cache limit. However only if the cache argument is True.
Will return None if the card could not be loaded.