diff options
author | Guido van Rossum <guido@python.org> | 2006-08-19 02:45:06 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-08-19 02:45:06 (GMT) |
commit | 1b01e5c706a1fd2bef24ec3e67c41b16423bcd7b (patch) | |
tree | 99388ee6f8a2c56c4ed6808317bfa12829dd3be6 | |
parent | 5c303dec170a0c4cb278c819869e652b0832725e (diff) | |
download | cpython-1b01e5c706a1fd2bef24ec3e67c41b16423bcd7b.zip cpython-1b01e5c706a1fd2bef24ec3e67c41b16423bcd7b.tar.gz cpython-1b01e5c706a1fd2bef24ec3e67c41b16423bcd7b.tar.bz2 |
Fix some more has_key() uses. This could really use a tool to automate...
-rw-r--r-- | Lib/ctypes/__init__.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/domreg.py | 2 | ||||
-rw-r--r-- | Lib/xml/dom/minidom.py | 18 | ||||
-rw-r--r-- | Lib/xml/dom/xmlbuilder.py | 4 | ||||
-rw-r--r-- | Lib/xml/sax/__init__.py | 4 | ||||
-rw-r--r-- | Lib/xml/sax/xmlreader.py | 9 |
6 files changed, 18 insertions, 21 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index a4e3c36..9e91ac6 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -265,7 +265,7 @@ def SetPointerType(pointer, cls): 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) diff --git a/Lib/xml/dom/domreg.py b/Lib/xml/dom/domreg.py index 684c436..ec3acdf 100644 --- a/Lib/xml/dom/domreg.py +++ b/Lib/xml/dom/domreg.py @@ -57,7 +57,7 @@ def getDOMImplementation(name = None, features = ()): 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 diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 3a35781..1a3b74f 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -243,7 +243,7 @@ class Node(xml.dom.Node): 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 @@ class NamedNodeMap(object): 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 @@ class NamedNodeMap(object): _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 @@ class NamedNodeMap(object): _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 @@ class Element(Node): 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 @@ class Document(Node, DocumentLS): 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 diff --git a/Lib/xml/dom/xmlbuilder.py b/Lib/xml/dom/xmlbuilder.py index ac1d448..dc7c5d4 100644 --- a/Lib/xml/dom/xmlbuilder.py +++ b/Lib/xml/dom/xmlbuilder.py @@ -91,7 +91,7 @@ class DOMBuilder: 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 @@ class DOMEntityResolver(object): 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() diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index 054064c..d55ffb7 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -59,7 +59,7 @@ if _false: 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 @@ def make_parser(parser_list = []): 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 diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py index 1cade65..1763ea4 100644 --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -294,12 +294,12 @@ class AttributesImpl: 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 @@ class AttributesImpl: 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) |