[Python-checkins] CVS: python/dist/src/Lib xmlrpclib.py,1.9,1.10
Fredrik Lundh
effbot@users.sourceforge.net
Mon, 01 Oct 2001 12:42:05 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv21782
Modified Files:
xmlrpclib.py
Log Message:
restored 1.5.2 compatibility
added local escape method (made the dumps method some 50-80% faster)
minor tweaks to the unmarshalling code
Index: xmlrpclib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xmlrpclib.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** xmlrpclib.py 2001/10/01 17:50:29 1.9
--- xmlrpclib.py 2001/10/01 19:42:03 1.10
***************
*** 32,35 ****
--- 32,37 ----
# 2001-09-03 fl Allow Transport subclass to override getparser
# 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup)
+ # 2001-10-01 fl Remove containers from memo cache when done with them
+ # 2001-10-01 fl Use faster escape method (80% dumps speedup)
#
# Copyright (c) 1999-2001 by Secret Labs AB.
***************
*** 71,86 ****
# things to look into before 1.0 final:
- # TODO: unicode marshalling -DONE
- # TODO: ascii-compatible encoding support -DONE
- # TODO: safe transport -DONE (but mostly untested)
- # TODO: sgmlop memory leak -DONE
- # TODO: sgmlop xml parsing -DONE
- # TODO: support unicode method names -DONE
- # TODO: update selftest -DONE
- # TODO: add docstrings -DONE
- # TODO: clean up parser encoding (trust the parser) -DONE
- # TODO: expat support -DONE
- # TODO: _xmlrpclib accelerator support -DONE
- # TODO: use smarter/faster escape from effdom
# TODO: support basic authentication (see robin's patch)
# TODO: fix host tuple handling in the server constructor
--- 73,76 ----
***************
*** 88,92 ****
# TODO: update documentation
# TODO: authentication plugins
- # TODO: memo problem (see HP's mail)
"""
--- 78,81 ----
***************
*** 135,141 ****
"""
! import re, string, time, operator
from types import *
- from cgi import escape as _escape
try:
--- 124,130 ----
"""
! import re, string, sys, time, operator
!
from types import *
try:
***************
*** 150,153 ****
--- 139,147 ----
return data
+ def escape(s, replace=string.replace):
+ s = replace(s, "&", "&")
+ s = replace(s, "<", "<")
+ return replace(s, ">", ">",)
+
if unicode:
def _stringify(string):
***************
*** 161,165 ****
return string
! __version__ = "1.0b3"
# --------------------------------------------------------------------
--- 155,159 ----
return string
! __version__ = "1.0b4"
# --------------------------------------------------------------------
***************
*** 473,487 ****
dispatch[FloatType] = dump_double
! def dump_string(self, value):
! self.write("<value><string>%s</string></value>\n" % _escape(value))
dispatch[StringType] = dump_string
if unicode:
! def dump_unicode(self, value):
value = value.encode(self.encoding)
! self.write("<value><string>%s</string></value>\n" % _escape(value))
dispatch[UnicodeType] = dump_unicode
! def container(self, value):
if value:
i = id(value)
--- 467,481 ----
dispatch[FloatType] = dump_double
! def dump_string(self, value, escape=escape):
! self.write("<value><string>%s</string></value>\n" % escape(value))
dispatch[StringType] = dump_string
if unicode:
! def dump_unicode(self, value, escape=escape):
value = value.encode(self.encoding)
! self.write("<value><string>%s</string></value>\n" % escape(value))
dispatch[UnicodeType] = dump_unicode
! def opencontainer(self, value):
if value:
i = id(value)
***************
*** 490,511 ****
self.memo[i] = None
! def endcontainer(self, value):
if value:
del self.memo[id(value)]
def dump_array(self, value):
! self.container(value)
write = self.write
write("<value><array><data>\n")
for v in value:
! self.__dump(v)
write("</data></array></value>\n")
! self.endcontainer(value)
dispatch[TupleType] = dump_array
dispatch[ListType] = dump_array
! def dump_struct(self, value):
! self.container(value)
write = self.write
write("<value><struct>\n")
for k, v in value.items():
--- 484,507 ----
self.memo[i] = None
! def closecontainer(self, value):
if value:
del self.memo[id(value)]
def dump_array(self, value):
! self.opencontainer(value)
write = self.write
+ dump = self.__dump
write("<value><array><data>\n")
for v in value:
! dump(v)
write("</data></array></value>\n")
! self.closecontainer(value)
dispatch[TupleType] = dump_array
dispatch[ListType] = dump_array
! def dump_struct(self, value, escape=escape):
! self.opencontainer(value)
write = self.write
+ dump = self.__dump
write("<value><struct>\n")
for k, v in value.items():
***************
*** 513,521 ****
if type(k) is not StringType:
raise TypeError, "dictionary key must be string"
! write("<name>%s</name>\n" % _escape(k))
! self.__dump(v)
write("</member>\n")
write("</struct></value>\n")
! self.endcontainer(value)
dispatch[DictType] = dump_struct
--- 509,517 ----
if type(k) is not StringType:
raise TypeError, "dictionary key must be string"
! write("<name>%s</name>\n" % escape(k))
! dump(v)
write("</member>\n")
write("</struct></value>\n")
! self.closecontainer(value)
dispatch[DictType] = dump_struct
***************
*** 578,582 ****
self._data.append(text)
! def end(self, tag):
# call the appropriate end tag handler
try:
--- 574,578 ----
self._data.append(text)
! def end(self, tag, join=string.join):
# call the appropriate end tag handler
try:
***************
*** 585,589 ****
pass # unknown tag ?
else:
! return f(self, self._data)
#
--- 581,585 ----
pass # unknown tag ?
else:
! return f(self, join(self._data, ""))
#
***************
*** 604,609 ****
dispatch = {}
! def end_boolean(self, data, join=string.join):
! data = join(data, "")
if data == "0":
self.append(False)
--- 600,604 ----
dispatch = {}
! def end_boolean(self, data):
if data == "0":
self.append(False)
***************
*** 615,631 ****
dispatch["boolean"] = end_boolean
! def end_int(self, data, join=string.join):
! self.append(int(join(data, "")))
self._value = 0
dispatch["i4"] = end_int
dispatch["int"] = end_int
! def end_double(self, data, join=string.join):
! self.append(float(join(data, "")))
self._value = 0
dispatch["double"] = end_double
! def end_string(self, data, join=string.join):
! data = join(data, "")
if self._encoding:
data = _decode(data, self._encoding)
--- 610,625 ----
dispatch["boolean"] = end_boolean
! def end_int(self, data):
! self.append(int(data))
self._value = 0
dispatch["i4"] = end_int
dispatch["int"] = end_int
! def end_double(self, data):
! self.append(float(data))
self._value = 0
dispatch["double"] = end_double
! def end_string(self, data):
if self._encoding:
data = _decode(data, self._encoding)
***************
*** 655,668 ****
dispatch["struct"] = end_struct
! def end_base64(self, data, join=string.join):
value = Binary()
! value.decode(join(data, ""))
self.append(value)
self._value = 0
dispatch["base64"] = end_base64
! def end_dateTime(self, data, join=string.join):
value = DateTime()
! value.decode(join(data, ""))
self.append(value)
dispatch["dateTime.iso8601"] = end_dateTime
--- 649,662 ----
dispatch["struct"] = end_struct
! def end_base64(self, data):
value = Binary()
! value.decode(data)
self.append(value)
self._value = 0
dispatch["base64"] = end_base64
! def end_dateTime(self, data):
value = DateTime()
! value.decode(data)
self.append(value)
dispatch["dateTime.iso8601"] = end_dateTime
***************
*** 683,688 ****
dispatch["fault"] = end_fault
! def end_methodName(self, data, join=string.join):
! data = join(data, "")
if self._encoding:
data = _decode(data, self._encoding)
--- 677,681 ----
dispatch["fault"] = end_fault
! def end_methodName(self, data):
if self._encoding:
data = _decode(data, self._encoding)