# read-only version of bool test. # show that bools are converted to the "best" value, depending # on Python version being used. --fpm import gnosis.xml.pickle as xmp from gnosis.xml.pickle.util import setVerbose, setParser, setParanoia from funcs import set_parser, unlink import gnosis.pyconfig as pyconfig from types import * # standard test harness setup set_parser() # allow unpickler to load my classes setParanoia(0) # NOTE: The XML below was created by running test_bool.py with # Python >= 2.3 and grabbing the XML output. x1 = """<?xml version="1.0"?> <!DOCTYPE PyObject SYSTEM "PyObjects.dtd"> <PyObject module="__main__" class="foo" id="168690156"> <attr name="a" family="uniq" type="False" value="" /> <attr name="c" family="none" type="None" /> <attr name="b" family="uniq" type="True" value="" /> <attr name="k" family="lang" type="class" module="__main__" class="a_test_class"/> <attr name="f" family="lang" type="function" module="__main__" class="a_test_function"/> </PyObject> """
</attr> </PyObject> """ COUNTER = 0 def incOK(): global COUNTER COUNTER += 1 x = xml_pickle.XML_Pickler() # first case, don't allow xml_pickle to invent classes setParanoia(2) try: # should not be able to load at all ud = x.loads(ud_xml) raise "FAILED 1!!" except: incOK() # second, only allow classes from the xml_pickle namespace, # or on-the-fly setParanoia(1) ud = x.loads(ud_xml) try:
def printfoo(obj): print type(obj.t), obj.t print type(obj.d), obj.d['One'], obj.d['Two'] print type(obj.ud), obj.ud['One'], obj.ud['Two'] print type(obj.l), obj.l[0], obj.l[1] print type(obj.ul), obj.ul[0], obj.ul[1] print type(obj.tup), obj.tup[0], obj.tup[1] #print locals()['foo_class'].__module__ #print type(locals()['foo_class']) foo = foo_class() # allow imported classes to be restored setParanoia(0) # test both code paths # path 1 - non-nested ('attr' nodes) foo.t = date.DateTime(2000,1,2,3,4,5.6) # path 2 - nested ('item/key/val' nodes) foo.d = { 'One': date.DateTime(2001,2,3,4,5,6.7), 'Two': date.DateTime(2002,3,4,5,6,7.8) } foo.ud = UserDict.UserDict() foo.ud['One'] = date.DateTime(2003,4,5,6,7,8.9) foo.ud['Two'] = date.DateTime(2004,5,6,7,8,9.10) foo.l = []
<key type="string" value="Two" /> <val type="numeric" value="2" /> </entry> </attr> </PyObject> """ COUNTER = 0 def incOK(): global COUNTER COUNTER += 1 x = xml_pickle.XML_Pickler() # first case, don't allow xml_pickle to invent classes setParanoia(2) try: # should not be able to load at all ud = x.loads(ud_xml) raise "FAILED 1!!" except: incOK() # second, only allow classes from the xml_pickle namespace, # or on-the-fly setParanoia(1) ud = x.loads(ud_xml) try: