Commit 32facaf0 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Back on track with optimized XML for CVS stability


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2328 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ff0aa38e
...@@ -975,7 +975,7 @@ def reorderPickle(jar, p): ...@@ -975,7 +975,7 @@ def reorderPickle(jar, p):
p=newp.getvalue() p=newp.getvalue()
return obj, p return obj, p
def PatchedXMLrecord(oid, plen, p, id_mapping): def XMLrecord(oid, plen, p, id_mapping):
# Proceed as usual # Proceed as usual
q=ppml.ToXMLUnpickler q=ppml.ToXMLUnpickler
f=StringIO(p) f=StringIO(p)
...@@ -993,9 +993,9 @@ def PatchedXMLrecord(oid, plen, p, id_mapping): ...@@ -993,9 +993,9 @@ def PatchedXMLrecord(oid, plen, p, id_mapping):
return String return String
from OFS import XMLExportImport from OFS import XMLExportImport
XMLrecord = XMLExportImport.XMLrecord = PatchedXMLrecord XMLExportImport.XMLrecord = XMLrecord
def PatchedexportXML(jar, oid, file=None): def exportXML(jar, oid, file=None):
if file is None: file=TemporaryFile() if file is None: file=TemporaryFile()
elif type(file) is StringType: file=open(file,'w+b') elif type(file) is StringType: file=open(file,'w+b')
...@@ -1047,13 +1047,11 @@ def PatchedexportXML(jar, oid, file=None): ...@@ -1047,13 +1047,11 @@ def PatchedexportXML(jar, oid, file=None):
write('</ZopeData>\n') write('</ZopeData>\n')
return file return file
from OFS import XMLExportImport XMLExportImport.exportXML = exportXML
XMLExportImport.exportXML = PatchedexportXML
###################################################################################### ######################################################################################
# Shared/DC/xml/ppml patch # Shared/DC/xml/ppml patch
# Import everything right now, not after # Import everything right now, not after
# or new patch will not work # or new patch will not work
from Shared.DC.xml.ppml import * from Shared.DC.xml.ppml import *
...@@ -1073,6 +1071,7 @@ class Global: ...@@ -1073,6 +1071,7 @@ class Global:
return '%s<%s%s name="%s" module="%s"/>\n' % ( return '%s<%s%s name="%s" module="%s"/>\n' % (
' '*indent, name, id, self.name, self.module) ' '*indent, name, id, self.name, self.module)
from Shared.DC.xml import ppml
ppml.Global = Global ppml.Global = Global
class Scalar: class Scalar:
...@@ -1085,11 +1084,14 @@ class Scalar: ...@@ -1085,11 +1084,14 @@ class Scalar:
def __str__(self, indent=0): def __str__(self, indent=0):
id = '' id = ''
if hasattr(self, 'id'):
if self.mapping.isMarked(self.id): id=' id="%s"' % self.mapping[self.id]
name=string.lower(self.__class__.__name__) name=string.lower(self.__class__.__name__)
return '%s<%s%s>%s</%s>\n' % ( result = '%s<%s%s>%s</%s>\n' % (
' '*indent, name, id, self.value(), name) ' '*indent, name, id, self.value(), name)
if hasattr(self, 'id'):
# The value is Immutable - let us add it the the immutable mapping
# to reduce the number of unreadable references
self.mapping.setImmutable(self.id, Immutable(value = result))
return result
ppml.Scalar = Scalar ppml.Scalar = Scalar
...@@ -1116,16 +1118,19 @@ class String(Scalar): ...@@ -1116,16 +1118,19 @@ class String(Scalar):
# Make sure we never produce this kind of xml output # Make sure we never produce this kind of xml output
raise raise
id = '' id = ''
if hasattr(self, 'id'):
if self.mapping.isMarked(self.id): id=' id="%s"' % self.mapping[self.id]
encoding='' encoding=''
if hasattr(self, 'encoding'): if hasattr(self, 'encoding'):
if self.encoding != 'repr': if self.encoding != 'repr':
# JPS repr is default encoding # JPS repr is default encoding
encoding=' encoding="%s"' % self.encoding encoding=' encoding="%s"' % self.encoding
name=string.lower(self.__class__.__name__) name=string.lower(self.__class__.__name__)
return '%s<%s%s%s>%s</%s>\n' % ( result = '%s<%s%s%s>%s</%s>\n' % (
' '*indent, name, id, encoding, v, name) ' '*indent, name, id, encoding, v, name)
if hasattr(self, 'id'):
# The value is Immutable - let us add it the the immutable mapping
# to reduce the number of unreadable references
self.mapping.setImmutable(self.id, Immutable(value = result))
return result
ppml.String = String ppml.String = String
...@@ -1249,6 +1254,10 @@ class Reference(Scalar): ...@@ -1249,6 +1254,10 @@ class Reference(Scalar):
def __str__(self, indent=0): def __str__(self, indent=0):
v=self._v v=self._v
name=string.lower(self.__class__.__name__) name=string.lower(self.__class__.__name__)
#LOG('Reference', 0, str(v))
if self.mapping.hasImmutable(v):
return self.mapping.getImmutable(v).getValue()
LOG('noImmutable', 0, "%s mapped to %s" % (v, self.mapping[v]))
self.mapping.mark(v) self.mapping.mark(v)
return '%s<%s id="%s"/>\n' % (' '*indent,name,self.mapping[v]) return '%s<%s id="%s"/>\n' % (' '*indent,name,self.mapping[v])
...@@ -1266,6 +1275,13 @@ class Object(Sequence): ...@@ -1266,6 +1275,13 @@ class Object(Sequence):
ppml.Object = Object ppml.Object = Object
class IdentityMapping: class IdentityMapping:
def __init__(self):
self.immutable = {}
def resetMapping(self):
pass
def __getitem__(self, id): def __getitem__(self, id):
return id return id
...@@ -1281,6 +1297,16 @@ class IdentityMapping: ...@@ -1281,6 +1297,16 @@ class IdentityMapping:
def isMarked(self, v): def isMarked(self, v):
return 1 return 1
def setImmutable(self, k, v):
self.immutable[k] = v
def getImmutable(self, k):
return self.immutable[k]
def hasImmutable(self, k):
return self.immutable.has_key(k)
ppml.IdentityMapping = IdentityMapping ppml.IdentityMapping = IdentityMapping
class MinimalMapping(IdentityMapping): class MinimalMapping(IdentityMapping):
...@@ -1291,6 +1317,15 @@ class MinimalMapping(IdentityMapping): ...@@ -1291,6 +1317,15 @@ class MinimalMapping(IdentityMapping):
self.last_id = 1 self.last_id = 1
self.converted_aka = {} self.converted_aka = {}
self.marked_reference = {} self.marked_reference = {}
self.immutable = {}
def resetMapping(self):
self.mapped_id = {}
self.mapped_core_id = {}
self.last_sub_id = {}
self.last_id = 1
self.converted_aka = {}
self.marked_reference = {}
def __getitem__(self, id): def __getitem__(self, id):
id = str(id) id = str(id)
...@@ -1545,8 +1580,7 @@ class ToXMLUnpickler(Unpickler): ...@@ -1545,8 +1580,7 @@ class ToXMLUnpickler(Unpickler):
self.func = func self.func = func
def __call__(self, context): def __call__(self, context):
from zLOG import LOG #LOG('LogCall', 0, 'self.stack = %r, func = %s' % (context.stack, self.func.__name__))
LOG('LogCall', 0, 'self.stack = %r, func = %s' % (context.stack, self.func.__name__))
return self.func(context) return self.func(context)
#for code in dispatch.keys(): #for code in dispatch.keys():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment