[Zope3-checkins] CVS: Zope3/src/zope/xmlpickle - ppml.py:1.4

Fred L. Drake, Jr. fred@zope.com
Fri, 4 Apr 2003 12:27:50 -0500


Update of /cvs-repository/Zope3/src/zope/xmlpickle
In directory cvs.zope.org:/tmp/cvs-serv9045

Modified Files:
	ppml.py 
Log Message:
Shave a few milliseconds off the test runs; this avoids a variety of
temp object creations (lists) and avoids repeating some string
formatting operations sometimes.


=== Zope3/src/zope/xmlpickle/ppml.py 1.3 => 1.4 ===
--- Zope3/src/zope/xmlpickle/ppml.py:1.3	Thu Feb  6 12:33:40 2003
+++ Zope3/src/zope/xmlpickle/ppml.py	Fri Apr  4 12:27:49 2003
@@ -53,11 +53,11 @@
         else:
 
             if apos >= 0:
-                string = '&'.join(string.split('&'))
+                string = string.replace("&", "&")
             if lpos >= 0:
-                string = '&lt;'.join(string.split('<'))
+                string = string.replace("<", "&lt;")
             if rpos >= 0:
-                string = '&#x0d;'.join(string.split('\r'))
+                string = string.replace("\r", "&#x0d;")
 
     return '', string
 
@@ -75,8 +75,7 @@
 
 def unconvert_unicode(encoding, string):
     if encoding == 'base64':
-        string = string.encode('ascii')
-        string = base64.decodestring(string)
+        string = base64.decodestring(string.encode('ascii'))
     elif encoding:
         raise ValueError('bad encoding', encoding)
 
@@ -313,6 +312,8 @@
     def value(self, write, indent):
         ind = ' '*indent
         ind4 = indent+4
+        begin = '%s<%s>\n' % (ind, self.item_name)
+        end = '%s</%s>\n' % (ind, self.item_name)
         for key, value in self._d:
             if (key.__class__ is String
                 and not key.encoding
@@ -321,16 +322,16 @@
                 id = getattr(key, 'id', '')
                 if id:
                     id = ' id="%s"' % id
-                s = key.value()
                 write('%s<%s %s="%s"%s>\n' %
-                      (ind, self.item_name, self.key_name, s, id))
+                      (ind, self.item_name, self.key_name, key.value(), id))
                 value.output(write, ind4)
-                write('%s</%s>\n' % (ind, self.item_name))
+                write(end)
             else:
-                write('%s<%s>\n' % (ind, self.item_name))
-                self.key_class(key).output(write, indent+2)
-                Value(value).output(write, indent+2)
-                write('%s</%s>\n' % (ind, self.item_name))
+                write(begin)
+                ind2 = indent+2
+                self.key_class(key).output(write, ind2)
+                Value(value).output(write, ind2)
+                write(end)
 
 class Attributes(Dictionary):
     key_name = 'name'
@@ -400,9 +401,7 @@
 class Reference(Scalar):
 
     def output(self, write, indent=0, strip=0):
-        v = self._v
-        name = self.__class__.__name__.lower()
-        write('%s<%s id="%s"/>' % (' '*indent,name,v))
+        write('%s<reference id="%s"/>' % (' '*indent,self._v))
         if not strip:
             write('\n')