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:
object
A 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
Serializer
facade is used.The interface is fairly simple: For the core entities that exist in the TiddlyWeb system (
bags
,recipes
andtiddlers
there (optionally) exists<entity>_as
andas_<entity>
methods in each Serialization.*_as
returns 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_string
which is a serialized bag and use it to populate theBag
inbag
(if possible).
-
as_recipe
(recipe, input_string)¶ Take
input_string
which is a serialized recipe and use it to populate theRecipe
inrecipe
(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_string
which is a serialized tiddler and use it to populate theTiddler
intiddler
(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.SerializationInterface
Serialize entities and collections to
HTML
representations. This is primarily used to create browser based presentations. No support is provided for turningHTML
into entities.Set
css_uri
inconfig
to control CSS.Set
tiddlyweb.links
inenviron
to 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.SerializationInterface
Turn entities and collections thereof to and from
JSON
.-
as_bag
(bag, input_string)¶ Turn a
JSON
dictionary into abag
if it is in the proper form. Include thepolicy
.
-
as_recipe
(recipe, input_string)¶ Turn a
JSON
dictionary into arecipe
if it is in the proper form. Include thepolicy
.
-
as_tiddler
(tiddler, input_string)¶ Turn a
JSON
dictionary into atiddler
. Any keys in theJSON
which are not recognized will be ignored.
-
list_tiddlers
(tiddlers)¶ List the provided
tiddlers
asJSON
. The format is a list of dicts in the form described by_tiddler_dict()
.If
fat=1
is set intiddlyweb.query
include thetext
of each tiddler in the output.If
render=1
is set intiddlyweb.query
include therendering
of thetext
of each tiddler in the output, if the tiddler is renderable.
-
tiddler_as
(tiddler)¶ Create a
JSON
dictionary representing a tiddler, as described by_tiddler_dict()
plus thetext
of the tiddler.If
fat=0
is set intiddlyweb.query
do not include thetext
of the tiddler in the output.If
render=1
is set intiddlyweb.query
include therendering
of thetext
of 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.SerializationInterface
Serialize entities and collections to and from textual representations. This is primarily used by the
text
Store
.-
as_tiddler
(tiddler, input_string)¶ Transform a text representation of a
tiddler
into a tiddler object.
-
field
= 'text'¶
-
list_tiddlers
(tiddlers)¶ Return a linefeed separated list of
tiddler
titles in thetiddlers
list.If the tiddlers are a collection of revisions, include the revision identifier.
-
tiddler_as
(tiddler, omit_empty=False, omit_members=None)¶ Represent a
tiddler
as 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_empty
is True, don’t emit empty Tiddler members.omit_members
can be used to provide a list of members to not include in the output.
-
tiddler_members
= ['creator', 'created', 'modifier', 'modified', 'tags', 'type']¶
-