Created
July 15, 2009 18:18
-
-
Save FND/147874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cf. http://tiddlyweb.peermore.com/wiki/recipes/docs/tiddlers/Serializing%20and%20Deserializing | |
| from tiddlyweb.model.tiddler import Tiddler | |
| from tiddlyweb.serializer import Serializer | |
| def internalize(serialization, title, format): | |
| serializer = Serializer(format) | |
| serializer.object = Tiddler(title) | |
| return serializer.from_string(serialization) | |
| def externalize(tiddler, format): | |
| serializer = Serializer(format) | |
| serializer.object = tiddler | |
| return serializer.to_string() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from shortcuts import internalize, externalize | |
| from tiddlyweb.model.tiddler import Tiddler | |
| def test_internalize(): | |
| serialization = '{ "modifier": "FND" }' | |
| tiddler = internalize(serialization, "Foo", "json") | |
| assert tiddler.title == "Foo" | |
| assert tiddler.modifier == "FND" | |
| def test_externalize(): | |
| tiddler = Tiddler("Foo") | |
| tiddler.modifier = "FND" | |
| serialization = externalize(tiddler, "json") | |
| assert '"title": "Foo"' in serialization | |
| assert '"modifier": "FND"' in serialization |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment