S.DB: Deferring everything (dummy)
[systematiki.git] / Systematiki / Database / Dummy.py
blob6a9092e620ad524938029291cd501503463aae82
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Systematiki Dummy Database.
6 - Implements documents and links to objects.
7 """
9 # Copyright (C) 2007 Felix Rabe <public@felixrabe.textdriven.com>
11 # This library is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU Lesser General Public
13 # License as published by the Free Software Foundation; either
14 # version 2.1 of the License, or (at your option) any later version.
16 # This library is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # Lesser General Public License for more details.
21 # You should have received a copy of the GNU Lesser General Public License
22 # along with this library; if not, write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 # Recommended line length or text width: 75 characters.
27 from base64 import decodestring as bdec
28 import StringIO
29 from zlib import decompress as zdec
31 from Systematiki.ElementTree import ET
32 from Systematiki.Database.Classes import *
33 from Systematiki.Database import Interface
34 from Systematiki.DeferredReturn import DeferredReturn
37 class Database(Interface.Database):
39 def __init__(self, config):
40 super(Database, self).__init__()
41 self.documents = {}
43 # I use base64'ed zlib here to make the contained XML documents
44 # more compact. Feel free to decode using
45 # zlib.decompress(base64.decodestring(s)) on your own.
47 d = lambda s: self.store_document(Document(ET.XML(zdec(bdec(s)))))
49 # TODO list
50 d("""
51 eJxNjLEOgjAURfd+xUt3QDcHWhI1cTEhURLnSos0lD7SPoj+vcSgeMd7Tk5e
52 PHsHkwnRohd8m244GF+jtv4h+EhNsuOFZCwPpgFCwTXWAZG4rMpjCc5GYuI7
53 xhI4Ifzca4vDMId4JtMZHZRzKzxbP0aoMEzK6bgoNwwdoP9LvCKZXpHt7KJc
54 jNJArVmdvb0786F5Nn+SvQFKDUDM
55 """)
57 # People I know
58 d("""
59 eJylk+9OwjAUxb/3KW760YgyQAXDRjTGxATF+OcBynaRhnJL2qrs7a1xbOsM
60 gtpkW7adnl/uOdtwtF4qeENjpaaYR0dtDkipziS9xPzVzVp9PkoYGxqcgdMx
61 z3RqtHY8uUe9Ugg3sCD9zuL6YmxCKgdNCNrvmqM/DCLYuX6nDcyCtGBQKK8k
62 TNFaYfJDWHkQGjH1T/1GpoR1n0ZHjD2TkrTADHgm7UqJnG+sWGvrYqwF98IZ
63 mS7gxjkkBn4dwKU2dA6dM7jy6OUUDUSDfs+LLzIjBcEd2kAZ9WCSOl0IT7zw
64 GpVcw4OYYiDswq0w6XyjGkt6tfCkzZtQWWjZ6dfhpwPGxsV8pKllcSnIyXSf
65 IYs5y46CgXkSUEvRVBo350kzguGxFyRf57pnlcsOw0ZS2/yq+Hb41QPdZham
66 vGviRu6BadlBuesxt8534eRCcii+vJiX9RwnezT053aq365z5lHV+2XUCe7z
67 z+78k3/XVxGjXoPY/kY8+YG4d8EVsRsCu7/i/eobqOXa35Xr6aBJLS4fIoyF
68 eg==
69 """)
71 def close(self):
72 deferred_return = DeferredReturn()
73 deferred_return.callback(self)
74 return deferred_return
76 def connect_client(self):
77 deferred_return = DeferredReturn()
78 deferred_return.callback(self)
79 return deferred_return
81 def connect_server(self):
82 deferred_return = DeferredReturn()
83 deferred_return.callback(self)
84 return deferred_return
86 def retrieve_document(self, document_uuid):
87 deferred_return = DeferredReturn()
88 for (uuid, document) in self.documents.iteritems():
89 if uuid == document_uuid:
90 deferred_return.callback(self, document)
91 return deferred_return
92 deferred_return.callback(self, None)
93 return deferred_return
95 def retrieve_object(self, obj_name):
96 deferred_return = DeferredReturn()
97 obj = Object(obj_name)
98 for document in self.documents.itervalues():
99 for link in document.iterrefs(obj_name):
100 obj.add_ref(document, link)
101 if not obj.refs: obj = None
102 deferred_return.callback(self, obj)
103 return deferred_return
105 def store_document(self, document):
106 self.documents[document.uuid] = document
107 deferred_return = DeferredReturn()
108 deferred_return.callback(self)
109 return deferred_return