Exemplo n.º 1
0
    def __init__(self):

        self.a = False
        self.b = True
        self.c = None
        self.f = a_test_function
        self.k = a_test_class
        
# always show the family tag so I can make sure it's right
#setVerbose(1)
#setParanoia(0)

f = foo()

# dump an object containing bools
s = xmp.dumpsp(f)
if SHOW_XML:
    print s

x = xmp.loads(s)
#print "Expect False, True, None, func, class: ",x.a,x.b,x.c,x.f,x.k

# check it
for attr in ['a','b','c','f','k']:
    if getattr(f,attr) != getattr(x,attr):
        raise "ERROR(1)"
    
# dump builtin obj containing bools
s = xmp.dumpsp( (True,False) )
if SHOW_XML:
    print s
Exemplo n.º 2
0
           o2.c != o1.__getinitargs__()[2] or \
           o2.d != o1.__getinitargs__()[3]:
        raise "ERROR(%d)" % NR
    
x = Foo(1,'abc',[1,2,3],('a','b','c'))

# python-pickle
p = pickle.dumps(x)
x2 = pickle.loads(p)

# test: .a and .b should match x; .c and .d should match
# values from __getinitargs__
check_foo(x, x2, 1)

# xml-pickle
px = xml_pickle.dumpsp(x)
x3 = xml_pickle.loads(px)

print px

print x3.a, x3.b, x3.c, x3.d
print x2.a, x2.b, x2.c, x2.d
# test: .a and .b should match x; .c and .d should match
# values from __getinitargs__
check_foo(x, x3, 2)

# make sure all call counts are correct
# 1 __init__ per loads(), plus original object = 3
# 1 __getinitargs__ per dumps(), plus 2 extra calls per test = 6
if COUNT_INIT != 3 or COUNT_GETARGS != 6:
    raise "ERROR(3)"
Exemplo n.º 3
0
        self.a = False
        self.b = True
        self.c = None
        self.f = a_test_function
        self.k = a_test_class


# always show the family tag so I can make sure it's right
#setVerbose(1)
#setParanoia(0)

f = foo()

# dump an object containing bools
s = xmp.dumpsp(f)
if SHOW_XML:
    print s

x = xmp.loads(s)
#print "Expect False, True, None, func, class: ",x.a,x.b,x.c,x.f,x.k

# check it
for attr in ['a', 'b', 'c', 'f', 'k']:
    if getattr(f, attr) != getattr(x, attr):
        raise "ERROR(1)"

# dump builtin obj containing bools
s = xmp.dumpsp((True, False))
if SHOW_XML:
    print s
Exemplo n.º 4
0
# path 2 - nested ('item/key/val' nodes)
foo.d = {'One': "First dict item", 'Two': 222, 'Three': 333.444}

foo.l = []
foo.l.append("first list")
foo.l.append(321)
foo.l.append(12.34)

foo.tup = ("tuple", 123, 444.333)

#xml_pickle.setVerbose(1)

#print "---PRE-PICKLE---"
#printfoo(foo)

x1 = xml_pickle.dumpsp(foo)
print x1

#print "---POST-PICKLE---"
bar = xml_pickle.loads(x1)
#printfoo(bar)

checkfoo(foo, bar)

x2 = xml_pickle.dumpsp(bar)

print "---XML from original---"
print x1

print "---XML from copy---"
print x2
Exemplo n.º 5
0
class Engine(object):
    pass


def getAuto():
    a = Automobile()
    a.doors = 4
    a.make = 'Honda'
    a.tow_hitch = None
    a.prev_owners = ("Jane Smith", ('John Doe', 'Betty Doe'), 'Charles Ng')
    a.repairs = []
    swindle = Swindle()
    swindle.date = date(1999, 7, 1)
    swindle.swindler = "Ed's Auto"
    swindle.purport = "Fix A/C"
    a.repairs.append("June 1, 1999: Fixed radiator")
    a.repairs.append(swindle)
    a.options = {}
    a.options['Cup Holders'] = 4
    a.options['Custom Wheels'] = 'Chrome Spoked'
    a.engine = Engine()
    a.engine.cylinders = 4
    a.engine.manufacturer = 'Ford'
    return a


if __name__ == '__main__':
    from zif.sedna.persistence import pickle
    print pickle.dumpsp(getAuto())
Exemplo n.º 6
0
foo.l.append( date.DateTime(2005,6,7,8,9,10.11) )
foo.l.append( date.DateTime(2006,7,8,9,10,11.12) )

foo.ul = UserList.UserList()
foo.ul.append( date.DateTime(2007,8,9,10,11,12.13) )
foo.ul.append( date.DateTime(2008,9,10,11,12,13.14) )

foo.tup = (date.DateTime(2009,10,11,12,13,14.15),
           date.DateTime(2010,11,12,13,14,15.16))

#print "---PRE-PICKLE---"
#printfoo(foo)

#__disable_extensions()

x1 = xml_pickle.dumpsp(foo)
print x1

#print "---POST-PICKLE---"
bar = xml_pickle.loads(x1)
#printfoo(bar)
#bar.hi()

checkfoo(foo,bar)

# same thing on copy

x2 = xml_pickle.dumps(bar)
baz = xml_pickle.loads(x2)

checkfoo(bar,baz)
Exemplo n.º 7
0
    o.str = "Hello World \n Special Chars: \t \000 <> & ' \207"
    o.lst = [1, 3.5, 2, 4 + 7j]
    o.lst2 = o.lst
    o.date = datetime.date(2008, 5, 18)
    o.dtm = datetime.datetime.now()
    o2 = MyClass()
    o2.tup = ("x", "y", "z")
    o2.tup2 = o2.tup
    o2.num = 2 + 2j
    o2.dct = {"this": "that", "spam": "eggs", 3.14: "about PI"}
    o2.dct2 = o2.dct
    o.obj = o2

    #print '------* Print python-defined pickled object *-----'
    # pickle it
    s = xml_pickle.dumpsp(o)
    #print '------* Load it and print it again *-----'
    #print '------ should look approximately the same ---'
    print s
    # unpickle it
    #for attr in ['num','str','lst','lst2','dtm','date']:
    #print attr, getattr(o,attr)
    t = xml_pickle.loads(s)

    # sanity, can't possibly happen
    if id(o) == id(t) or id(o.obj) == id(t.obj):
        raise "ERROR(0)"

    # check that it is the same
    for attr in [
            'num', 'str', 'lst', 'lst2', 'dtm', 'children', 'married',
Exemplo n.º 8
0
#funcs.set_parser()

a = (1, 2, 3)
b = [4, 5, 6]
c = {'a': 1, 'b': 2, 'c': 3, 'd': [100, 200, 300]}
dd = c['d']  # make sure subitems get refchecked
uu = UserList([10, 11, 12])

u = UserList([[uu, c, b, a], [a, b, c, uu], [c, a, b, uu], dd])
#print u

# allow xml_pickle to read our namespace
#setParanoia(0)

# by default, with references
x1 = xml_pickle.dumpsp(u)
print x1
#del u

g = xml_pickle.loads(x1)
#print g

if u != g:
    raise "ERROR(1)"

# next, using DEEPCOPY
#print "------ DEEP COPY ------"
#setDeepCopy(1)
x2 = xml_pickle.dumps(g)
#print x
#del g
Exemplo n.º 9
0
#funcs.set_parser()

a = (1,2,3)
b = [4,5,6]
c = {'a':1,'b':2,'c':3,'d':[100,200,300]}
dd = c['d'] # make sure subitems get refchecked
uu = UserList([10,11,12])

u = UserList([[uu,c,b,a],[a,b,c,uu],[c,a,b,uu],dd])
#print u

# allow xml_pickle to read our namespace
#setParanoia(0)

# by default, with references
x1 = xml_pickle.dumpsp(u)
print x1
#del u

g = xml_pickle.loads(x1)
#print g

if u != g:
    raise "ERROR(1)"

# next, using DEEPCOPY
#print "------ DEEP COPY ------"
#setDeepCopy(1)
x2 = xml_pickle.dumps(g)
#print x
#del g
Exemplo n.º 10
0
#mutate.remove_mutator(my)

# handcoded selfrefs from dqm that caused problems (even
# with xml_pickle-0.51)


class Spam:
    pass


item = Spam()
item.lst = []
item.lst.append(item)
item.lst.append(item.lst)

print xml_pickle.dumpsp(item)

s = """
<Pickle xmlns="http://namespaces.zope.org/pickle" class="Spam" module="__main__" xml:id="aaaaa">
  <Attributes>
    <Attribute class="list" name="lst" xml:id="aaaab">
      <Sequence>
        <Item idref="aaaaa"/>
        <Item idref="aaaab"/>
      </Sequence>
    </Attribute>
  </Attributes>
</Pickle>

"""
Exemplo n.º 11
0
f.r = r1
f.l1 = [[1,2,3],r2]
d = {'a':1}
f.l2 = [r3,[4,5,6],r3]
f.d = {'One': 1, 'Two': r4}


# let xml_pickle pull in our imports

# do a side-by-side comparison w/regular pickle, to
# show we do the same thing

sp = pickle.dumps(f)

sx = xml_pickle.dumpsp(f)
#del f
f=None
#import time
#time.sleep(1)
#j = open('setstate_xml.xml','w')
#j.write(sx)
#j.close()

print sx

g = xml_pickle.loads(sx)
h = pickle.loads(sp)

#print sx
print t1, t2, t3, t4
Exemplo n.º 12
0
           o2.d != o1.__getinitargs__()[3]:
        raise "ERROR(%d)" % NR


x = Foo(1, 'abc', [1, 2, 3], ('a', 'b', 'c'))

# python-pickle
p = pickle.dumps(x)
x2 = pickle.loads(p)

# test: .a and .b should match x; .c and .d should match
# values from __getinitargs__
check_foo(x, x2, 1)

# xml-pickle
px = xml_pickle.dumpsp(x)
x3 = xml_pickle.loads(px)

print px

print x3.a, x3.b, x3.c, x3.d
print x2.a, x2.b, x2.c, x2.d
# test: .a and .b should match x; .c and .d should match
# values from __getinitargs__
check_foo(x, x3, 2)

# make sure all call counts are correct
# 1 __init__ per loads(), plus original object = 3
# 1 __getinitargs__ per dumps(), plus 2 extra calls per test = 6
if COUNT_INIT != 3 or COUNT_GETARGS != 6:
    raise "ERROR(3)"
Exemplo n.º 13
0
          'Two': 222,
          'Three': 333.444 }

foo.l = []
foo.l.append( "first list" )
foo.l.append( 321 )
foo.l.append( 12.34 )

foo.tup = ("tuple", 123, 444.333)

#xml_pickle.setVerbose(1)

#print "---PRE-PICKLE---"
#printfoo(foo)

x1 = xml_pickle.dumpsp(foo)
print x1

#print "---POST-PICKLE---"
bar = xml_pickle.loads(x1)
#printfoo(bar)

checkfoo(foo,bar)

x2 = xml_pickle.dumpsp(bar)

print "---XML from original---"
print x1

print "---XML from copy---"
print x2
Exemplo n.º 14
0
import zif.sedna.persistence.pickle as xml_pickle
import funcs

#funcs.set_parser()

#setParanoia(0)

def checkit(o1,o2):
    for attr in ['first','last','addr','city','state']:
        if getattr(o1,attr) != getattr(o2,attr):
            raise "ERROR(1)"
        
c = contact('Joe','Jones','1744 Elk Road','Manchester','NH')
#c.hi()

x = xml_pickle.dumpsp(c)
print x
#del c

d = xml_pickle.loads(x)
#d.hi()
checkit(c,d)

# just to show this is a legal pickleable object ...
import pickle

s = pickle.dumps(d)
#del d

q = pickle.loads(s)
#q.hi()
Exemplo n.º 15
0
#funcs.set_parser()

#setParanoia(0)


def checkit(o1, o2):
    for attr in ['first', 'last', 'addr', 'city', 'state']:
        if getattr(o1, attr) != getattr(o2, attr):
            raise "ERROR(1)"


c = contact('Joe', 'Jones', '1744 Elk Road', 'Manchester', 'NH')
#c.hi()

x = xml_pickle.dumpsp(c)
print x
#del c

d = xml_pickle.loads(x)
#d.hi()
checkit(c, d)

# just to show this is a legal pickleable object ...
import pickle

s = pickle.dumps(d)
#del d

q = pickle.loads(s)
#q.hi()
Exemplo n.º 16
0
    pass
class Engine(object):
    pass
def getAuto():
    a = Automobile()
    a.doors = 4
    a.make='Honda'
    a.tow_hitch = None
    a.prev_owners = ("Jane Smith",('John Doe','Betty Doe'),'Charles Ng')
    a.repairs = []
    swindle = Swindle()
    swindle.date = date(1999,7,1)
    swindle.swindler = "Ed's Auto"
    swindle.purport = "Fix A/C"
    a.repairs.append("June 1, 1999: Fixed radiator")
    a.repairs.append(swindle)
    a.options = {}
    a.options['Cup Holders'] = 4
    a.options['Custom Wheels'] = 'Chrome Spoked'
    a.engine = Engine()
    a.engine.cylinders = 4
    a.engine.manufacturer = 'Ford'
    return a

if __name__ == '__main__':
    from zif.sedna.persistence import pickle
    print pickle.dumpsp(getAuto())
    
    

Exemplo n.º 17
0
    o.str = "Hello World \n Special Chars: \t \000 <> & ' \207"
    o.lst = [1, 3.5, 2, 4+7j]
    o.lst2 = o.lst
    o.date = datetime.date(2008,5,18)
    o.dtm = datetime.datetime.now()
    o2 = MyClass()
    o2.tup = ("x", "y", "z")
    o2.tup2 = o2.tup
    o2.num = 2+2j
    o2.dct = { "this": "that", "spam": "eggs", 3.14: "about PI" }
    o2.dct2 = o2.dct
    o.obj = o2

    #print '------* Print python-defined pickled object *-----'
    # pickle it
    s = xml_pickle.dumpsp(o)
    #print '------* Load it and print it again *-----'
    #print '------ should look approximately the same ---'
    print s
    # unpickle it
    #for attr in ['num','str','lst','lst2','dtm','date']:
        #print attr, getattr(o,attr)
    t = xml_pickle.loads(s)

    # sanity, can't possibly happen
    if id(o) == id(t) or id(o.obj) == id(t.obj):
        raise "ERROR(0)"

    # check that it is the same
    for attr in ['num','str','lst','lst2','dtm','children','married','divorced',
            'c_names','pet_names','date','dtm']:
Exemplo n.º 18
0
foo.l.append(date.DateTime(2005, 6, 7, 8, 9, 10.11))
foo.l.append(date.DateTime(2006, 7, 8, 9, 10, 11.12))

foo.ul = UserList.UserList()
foo.ul.append(date.DateTime(2007, 8, 9, 10, 11, 12.13))
foo.ul.append(date.DateTime(2008, 9, 10, 11, 12, 13.14))

foo.tup = (date.DateTime(2009, 10, 11, 12, 13,
                         14.15), date.DateTime(2010, 11, 12, 13, 14, 15.16))

#print "---PRE-PICKLE---"
#printfoo(foo)

#__disable_extensions()

x1 = xml_pickle.dumpsp(foo)
print x1

#print "---POST-PICKLE---"
bar = xml_pickle.loads(x1)
#printfoo(bar)
#bar.hi()

checkfoo(foo, bar)

# same thing on copy

x2 = xml_pickle.dumps(bar)
baz = xml_pickle.loads(x2)

checkfoo(bar, baz)