Quellcode durchsuchen

A few modernisation fixes, mostly for Python 3 support

rdb vor 12 Jahren
Ursprung
Commit
088df4a3d2
2 geänderte Dateien mit 10 neuen und 28 gelöschten Zeilen
  1. 10 10
      direct/src/showbase/ElementTree.py
  2. 0 18
      direct/src/showbase/PythonUtil.py

+ 10 - 10
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, "<", "&lt;")
-        text = replace(text, ">", "&gt;")
+        text = text.replace("&", "&amp;")
+        text = text.replace("<", "&lt;")
+        text = text.replace( ">", "&gt;")
         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, "&", "&amp;")
-        text = replace(text, "'", "&apos;") # FIXME: overkill
-        text = replace(text, "\"", "&quot;")
-        text = replace(text, "<", "&lt;")
-        text = replace(text, ">", "&gt;")
+        text = text.replace("&", "&amp;")
+        text = text.replace("'", "&apos;") # FIXME: overkill
+        text = text.replace("\"", "&quot;")
+        text = text.replace("<", "&lt;")
+        text = text.replace(">", "&gt;")
         return text
     except (TypeError, AttributeError):
         _raise_serialization_error(text)

+ 0 - 18
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):