serializations Package¶
serializations Package¶
Turn entities to and fro various representations.
This is the base class and interface class used to transform strings of various forms to model objects and model objects to strings of various forms.
-
class
tiddlyweb.serializations.SerializationInterface(environ=None)¶ Bases:
objectA Serialization is a collection of methods that either turn an input string into the object named by the method, or turn the object into a string form. A Serialization is not called directly, instead a
Serializerfacade is used.The interface is fairly simple: For the core entities that exist in the TiddlyWeb system (
bags,recipesandtiddlersthere (optionally) exists<entity>_asandas_<entity>methods in each Serialization.*_asreturns a string form of the entity, perhaps as HTML, Text, YAML, Atom, whatever the Serialization does.as_*takes a provided entity and string and updates the skeletal entity to use the information contained in the string (in the Serialization format).There are also three supporting methods,
list_tiddlers(),list_recipes()andlist_bags()that provide convenience methods for presenting a collection of entities in the Serialization form. A string is returned.Strings are usually unicode.
If a method doesn’t exist a NoSerializationError is raised and the calling code is expected to do something intelligent when trapping it.
-
as_bag(bag, input_string)¶ Take
input_stringwhich is a serialized bag and use it to populate theBaginbag(if possible).
-
as_recipe(recipe, input_string)¶ Take
input_stringwhich is a serialized recipe and use it to populate theRecipeinrecipe(if possible).
Not called directly, but made public for future use. Turn a string into a list of tags.
-
as_tiddler(tiddler, input_string)¶ Take
input_stringwhich is a serialized tiddler and use it to populate theTiddlerintiddler(if possible).
-
list_bags(bags)¶ Provided a list of
bags, make a serialized list of those bags (e.g. a a list of HTML links).
-
list_recipes(recipes)¶ Provided a list of
recipes, make a serialized list of those recipes (e.g. a a list of HTML links).
Not called directly, but made public for future use. Turn a list of tags into a serialized list.
-
html Module¶
Serialization
for HTML.
HEADER and FOOTER can be overridden to change the basic framing
of the system.
-
class
tiddlyweb.serializations.html.Serialization(environ=None)¶ Bases:
tiddlyweb.serializations.SerializationInterfaceSerialize entities and collections to
HTMLrepresentations. This is primarily used to create browser based presentations. No support is provided for turningHTMLinto entities.Set
css_uriinconfigto control CSS.Set
tiddlyweb.linksinenvironto a list of<link>elements to include those links in the output.
json Module¶
Serialization
for JSON.
-
class
tiddlyweb.serializations.json.Serialization(environ=None)¶ Bases:
tiddlyweb.serializations.SerializationInterfaceTurn entities and collections thereof to and from
JSON.-
as_bag(bag, input_string)¶ Turn a
JSONdictionary into abagif it is in the proper form. Include thepolicy.
-
as_recipe(recipe, input_string)¶ Turn a
JSONdictionary into arecipeif it is in the proper form. Include thepolicy.
-
as_tiddler(tiddler, input_string)¶ Turn a
JSONdictionary into atiddler. Any keys in theJSONwhich are not recognized will be ignored.
-
list_tiddlers(tiddlers)¶ List the provided
tiddlersasJSON. The format is a list of dicts in the form described by_tiddler_dict().If
fat=1is set intiddlyweb.queryinclude thetextof each tiddler in the output.If
render=1is set intiddlyweb.queryinclude therenderingof thetextof each tiddler in the output, if the tiddler is renderable.
-
tiddler_as(tiddler)¶ Create a
JSONdictionary representing a tiddler, as described by_tiddler_dict()plus thetextof the tiddler.If
fat=0is set intiddlyweb.querydo not include thetextof the tiddler in the output.If
render=1is set intiddlyweb.queryinclude therenderingof thetextof the tiddler in the output, if the tiddler is renderable.
-
text Module¶
Serialization
for plain text.
-
class
tiddlyweb.serializations.text.Serialization(environ=None)¶ Bases:
tiddlyweb.serializations.SerializationInterfaceSerialize entities and collections to and from textual representations. This is primarily used by the
textStore.-
as_tiddler(tiddler, input_string)¶ Transform a text representation of a
tiddlerinto a tiddler object.
-
field= 'text'¶
-
list_tiddlers(tiddlers)¶ Return a linefeed separated list of
tiddlertitles in thetiddlerslist.If the tiddlers are a collection of revisions, include the revision identifier.
-
tiddler_as(tiddler, omit_empty=False, omit_members=None)¶ Represent a
tiddleras a text string: headers, blank line, text.omit_*arguments are non-standard options, usable only when this method is called directly (outside the regular Serializer interface)If
omit_emptyis True, don’t emit empty Tiddler members.omit_memberscan be used to provide a list of members to not include in the output.
-
tiddler_members= ['creator', 'created', 'modifier', 'modified', 'tags', 'type']¶
-