From 088df4a3d214d674f22bb3ade45a5823176d36d4 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 17 Dec 2013 22:51:28 +0000 Subject: [PATCH] A few modernisation fixes, mostly for Python 3 support --- direct/src/showbase/ElementTree.py | 20 ++++++++++---------- direct/src/showbase/PythonUtil.py | 18 ------------------ 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/direct/src/showbase/ElementTree.py b/direct/src/showbase/ElementTree.py index 8ea3c79796..3f368edd39 100755 --- a/direct/src/showbase/ElementTree.py +++ b/direct/src/showbase/ElementTree.py @@ -794,7 +794,7 @@ def _encode_entity(text, pattern=_escape): # the following functions assume an ascii-compatible encoding # (or "utf-16") -def _escape_cdata(text, encoding=None, replace=string.replace): +def _escape_cdata(text, encoding=None): # escape character data try: if encoding: @@ -802,14 +802,14 @@ def _escape_cdata(text, encoding=None, replace=string.replace): text = _encode(text, encoding) except UnicodeError: return _encode_entity(text) - text = replace(text, "&", "&") - text = replace(text, "<", "<") - text = replace(text, ">", ">") + text = text.replace("&", "&") + text = text.replace("<", "<") + text = text.replace( ">", ">") return text except (TypeError, AttributeError): _raise_serialization_error(text) -def _escape_attrib(text, encoding=None, replace=string.replace): +def _escape_attrib(text, encoding=None): # escape attribute value try: if encoding: @@ -817,11 +817,11 @@ def _escape_attrib(text, encoding=None, replace=string.replace): text = _encode(text, encoding) except UnicodeError: return _encode_entity(text) - text = replace(text, "&", "&") - text = replace(text, "'", "'") # FIXME: overkill - text = replace(text, "\"", """) - text = replace(text, "<", "<") - text = replace(text, ">", ">") + text = text.replace("&", "&") + text = text.replace("'", "'") # FIXME: overkill + text = text.replace("\"", """) + text = text.replace("<", "<") + text = text.replace(">", ">") return text except (TypeError, AttributeError): _raise_serialization_error(text) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 9b77d6537e..a56643789d 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -68,24 +68,6 @@ from libpandaexpress import ConfigVariableBool 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 def Functor(function, *args, **kArgs):