[Python-3000-checkins] r51396 - in python/branches/p3yk/Lib: ctypes/__init__.py xml/dom/domreg.py xml/dom/minidom.py xml/dom/xmlbuilder.py xml/sax/__init__.py xml/sax/xmlreader.py

guido.van.rossum python-3000-checkins at python.org
Sat Aug 19 04:45:07 CEST 2006


Author: guido.van.rossum
Date: Sat Aug 19 04:45:06 2006
New Revision: 51396

Modified:
   python/branches/p3yk/Lib/ctypes/__init__.py
   python/branches/p3yk/Lib/xml/dom/domreg.py
   python/branches/p3yk/Lib/xml/dom/minidom.py
   python/branches/p3yk/Lib/xml/dom/xmlbuilder.py
   python/branches/p3yk/Lib/xml/sax/__init__.py
   python/branches/p3yk/Lib/xml/sax/xmlreader.py
Log:
Fix some more has_key() uses.  This could really use a tool to automate...


Modified: python/branches/p3yk/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/p3yk/Lib/ctypes/__init__.py	(original)
+++ python/branches/p3yk/Lib/ctypes/__init__.py	Sat Aug 19 04:45:06 2006
@@ -265,7 +265,7 @@
     if _pointer_type_cache.get(cls, None) is not None:
         raise RuntimeError, \
               "This type already exists in the cache"
-    if not _pointer_type_cache.has_key(id(pointer)):
+    if id(pointer) not in _pointer_type_cache:
         raise RuntimeError, \
               "What's this???"
     pointer.set_type(cls)

Modified: python/branches/p3yk/Lib/xml/dom/domreg.py
==============================================================================
--- python/branches/p3yk/Lib/xml/dom/domreg.py	(original)
+++ python/branches/p3yk/Lib/xml/dom/domreg.py	Sat Aug 19 04:45:06 2006
@@ -57,7 +57,7 @@
         return mod.getDOMImplementation()
     elif name:
         return registered[name]()
-    elif os.environ.has_key("PYTHON_DOM"):
+    elif "PYTHON_DOM" in os.environ:
         return getDOMImplementation(name = os.environ["PYTHON_DOM"])
 
     # User did not specify a name, try implementations in arbitrary

Modified: python/branches/p3yk/Lib/xml/dom/minidom.py
==============================================================================
--- python/branches/p3yk/Lib/xml/dom/minidom.py	(original)
+++ python/branches/p3yk/Lib/xml/dom/minidom.py	Sat Aug 19 04:45:06 2006
@@ -243,7 +243,7 @@
         except AttributeError:
             d = {}
             self._user_data = d
-        if d.has_key(key):
+        if key in d:
             old = d[key][0]
         if data is None:
             # ignore handlers passed for None
@@ -494,11 +494,11 @@
             L.append(((node.namespaceURI, node.localName), node.value))
         return L
 
-    def has_key(self, key):
+    def __contains__(self, key):
         if isinstance(key, StringTypes):
-            return self._attrs.has_key(key)
+            return key in self._attrs
         else:
-            return self._attrsNS.has_key(key)
+            return key in self._attrsNS
 
     def keys(self):
         return self._attrs.keys()
@@ -560,7 +560,7 @@
             _clear_id_cache(self._ownerElement)
             del self._attrs[n.nodeName]
             del self._attrsNS[(n.namespaceURI, n.localName)]
-            if n.__dict__.has_key('ownerElement'):
+            if 'ownerElement' in n.__dict__:
                 n.__dict__['ownerElement'] = None
             return n
         else:
@@ -572,7 +572,7 @@
             _clear_id_cache(self._ownerElement)
             del self._attrsNS[(n.namespaceURI, n.localName)]
             del self._attrs[n.nodeName]
-            if n.__dict__.has_key('ownerElement'):
+            if 'ownerElement' in n.__dict__:
                 n.__dict__['ownerElement'] = None
             return n
         else:
@@ -779,10 +779,10 @@
     removeAttributeNodeNS = removeAttributeNode
 
     def hasAttribute(self, name):
-        return self._attrs.has_key(name)
+        return name in self._attrs
 
     def hasAttributeNS(self, namespaceURI, localName):
-        return self._attrsNS.has_key((namespaceURI, localName))
+        return (namespaceURI, localName) in self._attrsNS
 
     def getElementsByTagName(self, name):
         return _get_elements_by_tagName_helper(self, name, NodeList())
@@ -1660,7 +1660,7 @@
         return n
 
     def getElementById(self, id):
-        if self._id_cache.has_key(id):
+        if id in self._id_cache:
             return self._id_cache[id]
         if not (self._elem_info or self._magic_id_count):
             return None

Modified: python/branches/p3yk/Lib/xml/dom/xmlbuilder.py
==============================================================================
--- python/branches/p3yk/Lib/xml/dom/xmlbuilder.py	(original)
+++ python/branches/p3yk/Lib/xml/dom/xmlbuilder.py	Sat Aug 19 04:45:06 2006
@@ -91,7 +91,7 @@
 
     def canSetFeature(self, name, state):
         key = (_name_xform(name), state and 1 or 0)
-        return self._settings.has_key(key)
+        return key in self._settings
 
     # This dictionary maps from (feature,value) to a list of
     # (option,value) pairs that should be set on the Options object.
@@ -247,7 +247,7 @@
 
     def _guess_media_encoding(self, source):
         info = source.byteStream.info()
-        if info.has_key("Content-Type"):
+        if "Content-Type" in info:
             for param in info.getplist():
                 if param.startswith("charset="):
                     return param.split("=", 1)[1].lower()

Modified: python/branches/p3yk/Lib/xml/sax/__init__.py
==============================================================================
--- python/branches/p3yk/Lib/xml/sax/__init__.py	(original)
+++ python/branches/p3yk/Lib/xml/sax/__init__.py	Sat Aug 19 04:45:06 2006
@@ -59,7 +59,7 @@
     import xml.sax.expatreader
 
 import os, sys
-if os.environ.has_key("PY_SAX_PARSER"):
+if "PY_SAX_PARSER" in os.environ:
     default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
 del os
 
@@ -81,7 +81,7 @@
             return _create_parser(parser_name)
         except ImportError,e:
             import sys
-            if sys.modules.has_key(parser_name):
+            if parser_name in sys.modules:
                 # The parser module was found, but importing it
                 # failed unexpectedly, pass this exception through
                 raise

Modified: python/branches/p3yk/Lib/xml/sax/xmlreader.py
==============================================================================
--- python/branches/p3yk/Lib/xml/sax/xmlreader.py	(original)
+++ python/branches/p3yk/Lib/xml/sax/xmlreader.py	Sat Aug 19 04:45:06 2006
@@ -294,12 +294,12 @@
         return self._attrs[name]
 
     def getNameByQName(self, name):
-        if not self._attrs.has_key(name):
+        if name not in self._attrs:
             raise KeyError, name
         return name
 
     def getQNameByName(self, name):
-        if not self._attrs.has_key(name):
+        if name not in self._attrs:
             raise KeyError, name
         return name
 
@@ -318,11 +318,8 @@
     def keys(self):
         return self._attrs.keys()
 
-    def has_key(self, name):
-        return self._attrs.has_key(name)
-
     def __contains__(self, name):
-        return self._attrs.has_key(name)
+        return name in self._attrs
 
     def get(self, name, alternative=None):
         return self._attrs.get(name, alternative)


More information about the Python-3000-checkins mailing list