# The FakeStorage class mimics the FieldStorage object in this limited respect:
# 1. we can initialize our dummy 'form' like this:
# form = FakeStorage()
# form['sparqlQuery'] = "query string"
#
# and access it like this:
# form.getvalue("sparqlQuery")
#
# OR
#
# 2. we can initialize it as an ordinary dict like this:
# form = {"serialize": FakeStorage('serialization format string')}
#
# and access it like this:
# form["serialize"].value
class FakeStorage(dict):
def __init__(self, s=None):
self.value = s
def getvalue(self, k):
return self[k]
# opt. 1:
form = FakeStorage()
form['sparqlQuery'] = "query string"
# then access the form thus:
form.getvalue("sparqlQuery")
# opt. 2: initialize `form` as an ordinary dict:
form = {'serialize': FakeStorage('n3')}
# and access it like this:
form["serialize"].value
Diff to Previous Revision
--- revision 5 2015-06-18 20:04:49
+++ revision 6 2015-06-18 20:46:32
@@ -32,4 +32,4 @@
form = {'serialize': FakeStorage('n3')}
# and access it like this:
- form["sparqlQuery"].value
+ form["serialize"].value