A few modernisation fixes, mostly for Python 3 support

This commit is contained in:
rdb 2013-12-17 22:51:28 +00:00
parent 4b9da436a0
commit 088df4a3d2
2 changed files with 10 additions and 28 deletions

View File

@ -794,7 +794,7 @@ def _encode_entity(text, pattern=_escape):
# the following functions assume an ascii-compatible encoding # the following functions assume an ascii-compatible encoding
# (or "utf-16") # (or "utf-16")
def _escape_cdata(text, encoding=None, replace=string.replace): def _escape_cdata(text, encoding=None):
# escape character data # escape character data
try: try:
if encoding: if encoding:
@ -802,14 +802,14 @@ def _escape_cdata(text, encoding=None, replace=string.replace):
text = _encode(text, encoding) text = _encode(text, encoding)
except UnicodeError: except UnicodeError:
return _encode_entity(text) return _encode_entity(text)
text = replace(text, "&", "&") text = text.replace("&", "&")
text = replace(text, "<", "&lt;") text = text.replace("<", "&lt;")
text = replace(text, ">", "&gt;") text = text.replace( ">", "&gt;")
return text return text
except (TypeError, AttributeError): except (TypeError, AttributeError):
_raise_serialization_error(text) _raise_serialization_error(text)
def _escape_attrib(text, encoding=None, replace=string.replace): def _escape_attrib(text, encoding=None):
# escape attribute value # escape attribute value
try: try:
if encoding: if encoding:
@ -817,11 +817,11 @@ def _escape_attrib(text, encoding=None, replace=string.replace):
text = _encode(text, encoding) text = _encode(text, encoding)
except UnicodeError: except UnicodeError:
return _encode_entity(text) return _encode_entity(text)
text = replace(text, "&", "&amp;") text = text.replace("&", "&amp;")
text = replace(text, "'", "&apos;") # FIXME: overkill text = text.replace("'", "&apos;") # FIXME: overkill
text = replace(text, "\"", "&quot;") text = text.replace("\"", "&quot;")
text = replace(text, "<", "&lt;") text = text.replace("<", "&lt;")
text = replace(text, ">", "&gt;") text = text.replace(">", "&gt;")
return text return text
except (TypeError, AttributeError): except (TypeError, AttributeError):
_raise_serialization_error(text) _raise_serialization_error(text)

View File

@ -68,24 +68,6 @@ from libpandaexpress import ConfigVariableBool
ScalarTypes = (types.FloatType, types.IntType, types.LongType) ScalarTypes = (types.FloatType, types.IntType, types.LongType)
import __builtin__
if not hasattr(__builtin__, 'enumerate'):
def enumerate(L):
"""Returns (0, L[0]), (1, L[1]), etc., allowing this syntax:
for i, item in enumerate(L):
...
enumerate is a built-in feature in Python 2.3, which implements it
using an iterator. For now, we can use this quick & dirty
implementation that returns a list of tuples that is completely
constructed every time enumerate() is called.
"""
return zip(xrange(len(L)), L)
__builtin__.enumerate = enumerate
else:
enumerate = __builtin__.enumerate
""" """
# with one integer positional arg, this uses about 4/5 of the memory of the Functor class below # with one integer positional arg, this uses about 4/5 of the memory of the Functor class below
def Functor(function, *args, **kArgs): def Functor(function, *args, **kArgs):