"exercise all 4 list-writing methods --fpm" import gnosis.xml.pickle as xml_pickle import sys import funcs funcs.set_parser() class foo: pass f = foo() f.a = (1,2,3) # method 1 -- StreamWriter is an uncompressed StringIO x = xml_pickle.dumps(f) # check header (to ensure correct method used) + contents if x[0:5] == '<?xml': print "OK" else: print "ERROR" sys.exit(1) g = xml_pickle.loads(x) if g.a == (1,2,3): print "OK" else: print "ERROR" sys.exit(1)
"""Make sure xml_pickle and xml_objectify play nicely together --dqm Note that xml_pickle no longer has any builtin knowledge of xml_objectify -- used to be necessary to workaround circular refs (fpm)""" import gnosis.xml.objectify as xo import gnosis.xml.pickle as xp from StringIO import StringIO import funcs funcs.set_parser() xml = '''<?xml version="1.0"?> <!DOCTYPE Spam SYSTEM "spam.dtd" > <Spam> <Eggs>Some text about eggs.</Eggs> <MoreSpam>Ode to Spam</MoreSpam> </Spam> ''' fh = StringIO(xml) o = xo.make_instance(xml) s = xp.dumps(o) #print "---------- xml_objectify'd object, xml_pickle'd ----------" #print s o2 = xp.loads(s) #print "---------- object after the pickle/unpickle cycle --------" #print xp.dumps(o2) if o.Eggs.PCDATA != o2.Eggs.PCDATA or \ o.MoreSpam.PCDATA != o2.MoreSpam.PCDATA: raise "ERROR(1)"
# 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> """
""" Here are collected miscellaneous tests (from bug reports,etc.) that don't clearly fit elsewhere. --fpm """ import gnosis.xml.pickle as xml_pickle from funcs import set_parser import gnosis.pyconfig as pyconfig set_parser() # this is from a bug report from Even Westvang <*****@*****.**>. # the problem is that new-style classes used as attributes weren't # being pickled correctly. # let it load my classes xml_pickle.setParanoia(0) if pyconfig.Have_ObjectClass(): # need new-style classes class PickleMeOld: def __init__(self): pass class PickleMeNew(object): def __init__(self): pass class Container(object): def __init__(self, klass): self.classRef = klass