summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-27 09:17:48 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-27 09:17:48 (GMT)
commit54ad523f026afd4c06d567cfeeee0fb0e18ba444 (patch)
treed31b32de70a57149ed130d694c9d99ac5bad3188 /Lib/xmlrpclib.py
parent859b5ec240d438c691c0ca843f618c28e643d0c2 (diff)
downloadcpython-54ad523f026afd4c06d567cfeeee0fb0e18ba444.zip
cpython-54ad523f026afd4c06d567cfeeee0fb0e18ba444.tar.gz
cpython-54ad523f026afd4c06d567cfeeee0fb0e18ba444.tar.bz2
Make xmlrpclib fail less (test_sundry passes).
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py49
1 files changed, 19 insertions, 30 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 9684ab0..f0e4f8f 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -144,11 +144,6 @@ from types import *
# Internal stuff
try:
- str
-except NameError:
- str = None # unicode support not available
-
-try:
import datetime
except ImportError:
datetime = None
@@ -160,7 +155,7 @@ except NameError:
def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
# decode non-ascii string (if possible)
- if str and encoding and is8bit(data):
+ if encoding and is8bit(data):
data = str(data, encoding)
return data
@@ -169,15 +164,11 @@ def escape(s):
s = s.replace("<", "&lt;")
return s.replace(">", "&gt;",)
-if str:
- def _stringify(string):
- # convert to 7-bit ascii if possible
- try:
- return string.encode("ascii")
- except UnicodeError:
- return string
-else:
- def _stringify(string):
+def _stringify(string):
+ # convert to 7-bit ascii if possible
+ try:
+ return string.encode("ascii")
+ except UnicodeError:
return string
__version__ = "1.0.1"
@@ -306,7 +297,7 @@ class DateTime:
"""
def __init__(self, value=0):
- if not isinstance(value, StringType):
+ if not isinstance(value, basestring):
if datetime and isinstance(value, datetime.datetime):
self.value = value.strftime("%Y%m%dT%H:%M:%S")
return
@@ -627,15 +618,14 @@ class Marshaller:
write("<value><string>")
write(escape(value))
write("</string></value>\n")
- dispatch[StringType] = dump_string
+ dispatch[str8] = dump_string
- if str:
- def dump_unicode(self, value, write, escape=escape):
- value = value.encode(self.encoding)
- write("<value><string>")
- write(escape(value))
- write("</string></value>\n")
- dispatch[UnicodeType] = dump_unicode
+ def dump_unicode(self, value, write, escape=escape):
+ value = value.encode(self.encoding)
+ write("<value><string>")
+ write(escape(value))
+ write("</string></value>\n")
+ dispatch[str] = dump_unicode
def dump_array(self, value, write):
i = id(value)
@@ -660,11 +650,10 @@ class Marshaller:
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
- if type(k) is not StringType:
- if str and type(k) is UnicodeType:
- k = k.encode(self.encoding)
- else:
- raise TypeError, "dictionary key must be string"
+ if isinstance(k, basestring):
+ k = k.encode(self.encoding)
+ else:
+ raise TypeError, "dictionary key must be string"
write("<name>%s</name>\n" % escape(k))
dump(v, write)
write("</member>\n")
@@ -1044,7 +1033,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
# standard XML-RPC wrappings
if methodname:
# a method call
- if not isinstance(methodname, StringType):
+ if not isinstance(methodname, basestring):
methodname = methodname.encode(encoding)
data = (
xmlheader,