def exportXML(jar, oid, file=None): if file is None: file = TemporaryFile() elif type(file) is str: file = open(file, 'w+b') write = file.write write('<?xml version="1.0"?>\012<ZopeData>\012') ref = referencesf oids = [oid] done_oids = {} done = done_oids.has_key load = jar._storage.load while oids: oid = oids[0] del oids[0] if done(oid): continue done_oids[oid] = 1 try: try: p, serial = load(oid) except TypeError: # Some places inside the ZODB 3.9 still want a version # argument, for example TmpStore from Connection.py p, serial = load(oid, None) except: pass # Ick, a broken reference else: ref(p, oids) write(XMLrecord(oid, len(p), p)) write('</ZopeData>\n') return file
def exportXML(jar, oid, file=None): if file is None: file = TemporaryFile() elif type(file) is str: file = open(file, 'w+b') write = file.write write('<?xml version="1.0"?>\012<ZopeData>\012') version = jar._version ref = referencesf oids = [oid] done_oids = {} done = done_oids.has_key load = jar._storage.load while oids: oid = oids[0] del oids[0] if done(oid): continue done_oids[oid] = 1 try: p, serial = load(oid, version) except: pass # Ick, a broken reference else: ref(p, oids) write(XMLrecord(oid, len(p), p)) write('</ZopeData>\n') return file
def importXML(jar, file, clue=''): import xml.parsers.expat if type(file) is str: file = open(file, 'rb') outfile = TemporaryFile() data = file.read() F = ppml.xmlPickler() F.end_handlers['record'] = save_record F.end_handlers['ZopeData'] = save_zopedata F.start_handlers['ZopeData'] = start_zopedata F.binary = 1 F.file = outfile p = xml.parsers.expat.ParserCreate() p.CharacterDataHandler = F.handle_data p.StartElementHandler = F.unknown_starttag p.EndElementHandler = F.unknown_endtag r = p.Parse(data) outfile.seek(0) return jar.importFile(outfile, clue)
def importXML(jar, file, clue=''): import xml.parsers.expat if type(file) is str: file=open(file, 'rb') outfile=TemporaryFile() data=file.read() F=ppml.xmlPickler() F.end_handlers['record'] = save_record F.end_handlers['ZopeData'] = save_zopedata F.start_handlers['ZopeData'] = start_zopedata F.binary=1 F.file=outfile p=xml.parsers.expat.ParserCreate() p.CharacterDataHandler=F.handle_data p.StartElementHandler=F.unknown_starttag p.EndElementHandler=F.unknown_endtag r=p.Parse(data) outfile.seek(0) return jar.importFile(outfile,clue)
def exportXML(jar, oid, file=None): # For performance reasons, exportXML does not use 'XMLrecord' anymore to map # oids. This requires to initialize MinimalMapping.marked_reference before # any string output, i.e. in ppml.Reference.__init__ # This also fixed random failures when DemoStorage is used, because oids # can have values that have a shorter representation in 'repr' instead of # 'base64' (see ppml.convert) and ppml.String does not support this. load = jar._storage.load pickle_dict = {oid: None} max_cache = [1e7] # do not cache more than 10MB of pickle data def getReorderedPickle(oid): p = pickle_dict[oid] if p is None: # Versions are ignored, but some 'load()' implementations require them # FIXME: remove "''" when TmpStore.load() on ZODB stops asking for it. p = load(oid, '')[0] p = reorderPickle(jar, p)[1] if len(p) < max_cache[0]: max_cache[0] -= len(p) pickle_dict[oid] = p return p # Sort records and initialize id_mapping id_mapping = ppml.MinimalMapping() reordered_oid_list = [oid] for oid in reordered_oid_list: _mapOid(id_mapping, oid) for oid in referencesf(getReorderedPickle(oid)): if oid not in pickle_dict: pickle_dict[oid] = None reordered_oid_list.append(oid) # Do real export if file is None: file = TemporaryFile() elif isinstance(file, basestring): file = open(file, 'w+b') write = file.write write('<?xml version="1.0"?>\n<ZopeData>\n') for oid in reordered_oid_list: p = getReorderedPickle(oid) write(XMLrecord(oid, len(p), p, id_mapping)) write('</ZopeData>\n') return file