Пример #1
0
 def load_index(self, INDEXDB=None, reload=0, wordlist=None):
     # Unless reload is indicated, do not load twice
     if self.index_loaded() and not reload: return 0
     # Ok, now let's actually load it
     from gnosis.xml.pickle import XML_Pickler
     INDEXDB = INDEXDB or self.indexdb
     try:  # XML file exists
         xml_str = open(INDEXDB).read()
         db = XML_Pickler().loads(xml_str)
     except:  # New index
         db = Index({}, {'_TOP': (0, None)}, {})
     self.words, self.files, self.fileids = db.WORDS, db.FILES, db.FILEIDS
Пример #2
0
 def save_index(self, INDEXDB=None):
     from gnosis.xml.pickle import XML_Pickler
     INDEXDB = INDEXDB or self.indexdb
     db = Index(self.words, self.files, self.fileids)
     open(INDEXDB, 'w').write(XML_Pickler(db).dumps())
Пример #3
0
 def __init__(self):
     XML_Pickler.__init__(self)
     UserList.__init__(self)
Пример #4
0
    def hello(self):
        return "BAT!"


class FunList(UserList, XML_Pickler):
    def __init__(self):
        XML_Pickler.__init__(self)
        UserList.__init__(self)

    pass


# allow xml_pickle to use our imports
setParanoia(0)

l = FunList()
l.append(Foo())
l.append(Bar())
l.append(Bat())

for n in l:
    n.hi()

s = l.dumps()
print s

x = XML_Pickler().loads(s)

for n in x:
    n.hi()
Пример #5
0
 def __init__(self):
     XML_Pickler.__init__(self)
Пример #6
0
        XML_Pickler.__init__(self)

    def hello(self):
        return "BAT!"


class FunList(UserList, XML_Pickler):
    def __init__(self):
        XML_Pickler.__init__(self)
        UserList.__init__(self)


# allow xml_pickle to use our imports
setParanoia(0)

l = FunList()
l.append(Foo())
l.append(Bar())
l.append(Bat())

x = l.dumps()

o = XML_Pickler().loads(x)

if o[0].hello() != 'FOO!' or \
   o[1].hello() != 'BAR!' or \
   o[2].hello() != 'BAT!':
    raise "ERROR(1)"

print "** OK **"
Пример #7
0
      <attr name="manufacturer" type="string" value="Ford" />
   </attr>
</PyObject>"""

if __name__ == '__main__':
    from gnosis.xml.pickle import XML_Pickler
    import gnosis.xml.pickle as xml_pickle
    from gnosis.xml.pickle.util import add_class_to_store
    from . import funcs

    funcs.set_parser()

    class MyClass:
        pass

    o = XML_Pickler()
    o.num = 37
    o.str = "Hello World \n Special Chars: \t \000 < > & ' \207"
    o.lst = [1, 3.5, 2, 4 + 7j]
    o.lst2 = o.lst
    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 = o.dumps()
    #print s
Пример #8
0
 def __init__(self):
     XML_Pickler.__init__(self)
     UserList.__init__(self)
Пример #9
0
 def __init__(self):
     XML_Pickler.__init__(self)
Пример #10
-49
   <attr name="engine" type="PyObject" class="Engine">
      <attr name="cylinders" type="numeric" value="4" />
      <attr name="manufacturer" type="string" value="Ford" />
   </attr>
</PyObject>"""

if __name__=='__main__':
    from gnosis.xml.pickle import XML_Pickler
    import gnosis.xml.pickle as xml_pickle	
    from gnosis.xml.pickle.util import add_class_to_store
    import funcs

    funcs.set_parser()		   
    
    class MyClass: pass
    o = XML_Pickler()
    o.num = 37
    o.str = "Hello World \n Special Chars: \t \000 < > & ' \207"
    o.lst = [1, 3.5, 2, 4+7j]
    o.lst2 = o.lst
    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 = o.dumps()
    #print s