[Zope-Checkins] SVN: Zope/trunk/src/ relace has_key call with 'in' operator

Nikolay Kim fafhrd91 at gmail.com
Wed Jun 15 01:35:11 EDT 2011


Log message for revision 121937:
  relace has_key call with 'in' operator

Changed:
  U   Zope/trunk/src/App/ApplicationManager.py
  U   Zope/trunk/src/App/ProductContext.py
  U   Zope/trunk/src/App/ProductRegistry.py
  U   Zope/trunk/src/App/special_dtml.py
  U   Zope/trunk/src/OFS/Image.py
  U   Zope/trunk/src/OFS/ObjectManager.py
  U   Zope/trunk/src/OFS/PropertyManager.py
  U   Zope/trunk/src/OFS/PropertySheets.py
  U   Zope/trunk/src/OFS/Traversable.py
  U   Zope/trunk/src/Products/Five/browser/decode.py
  U   Zope/trunk/src/Products/PageTemplates/PageTemplateFile.py
  U   Zope/trunk/src/Products/PageTemplates/ZopePageTemplate.py
  U   Zope/trunk/src/Products/SiteAccess/VirtualHostMonster.py
  U   Zope/trunk/src/Shared/DC/Scripts/Bindings.py
  U   Zope/trunk/src/ZPublisher/BaseRequest.py
  U   Zope/trunk/src/ZPublisher/HTTPRequest.py
  U   Zope/trunk/src/ZPublisher/HTTPResponse.py
  U   Zope/trunk/src/ZPublisher/Publish.py
  U   Zope/trunk/src/ZTUtils/Zope.py

-=-
Modified: Zope/trunk/src/App/ApplicationManager.py
===================================================================
--- Zope/trunk/src/App/ApplicationManager.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/App/ApplicationManager.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -353,7 +353,7 @@
             return '%.1fM' % (s/1048576.0)
         return '%.1fK' % (s/1024.0)
 
-    if os.environ.has_key('ZMANAGED'):
+    if 'ZMANAGED' in os.environ:
         manage_restartable = 1
         @requestmethod('POST')
         def manage_restart(self, URL1, REQUEST=None):

Modified: Zope/trunk/src/App/ProductContext.py
===================================================================
--- Zope/trunk/src/App/ProductContext.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/App/ProductContext.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -151,7 +151,7 @@
             else:
                 name=method.__name__
                 aliased = 0
-            if not OM.__dict__.has_key(name):
+            if name not in OM.__dict__:
                 setattr(OM, name, method)
                 setattr(OM, name+'__roles__', pr)
                 if aliased:
@@ -213,7 +213,7 @@
                 name, method = method
             else:
                 name=os.path.split(method.__name__)[-1]
-            if not productObject.__dict__.has_key(name):
+            if name not in productObject.__dict__:
                 m[name]=method
                 m[name+'__roles__']=pr
 

Modified: Zope/trunk/src/App/ProductRegistry.py
===================================================================
--- Zope/trunk/src/App/ProductRegistry.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/App/ProductRegistry.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -32,7 +32,7 @@
         r=[]
         pid=product.id
         for mt in self._getProductRegistryMetaTypes():
-            if mt.has_key('product'):
+            if 'product' in mt:
                 if mt['product']==pid and (
                     meta_type is None or meta_type==mt['name']):
                     continue
@@ -52,7 +52,7 @@
 
         for mt in meta_types:
             if mt['name']==meta_type:
-                if not mt.has_key('product'): mt['product']=pid
+                if 'product' not in mt: mt['product']=pid
                 if mt['product'] != pid:
                     raise ValueError, (
                         'The type <em>%s</em> is already defined.' % meta_type)

Modified: Zope/trunk/src/App/special_dtml.py
===================================================================
--- Zope/trunk/src/App/special_dtml.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/App/special_dtml.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -49,7 +49,7 @@
         elif type(_prefix) is not type(''):
             _prefix = Common.package_home(_prefix)
         args=(self, os.path.join(_prefix, name + '.dtml'))
-        if not kw.has_key('__name__'):
+        if '__name__' not in kw:
             kw['__name__'] = os.path.split(name)[-1]
         apply(ClassicHTMLFile.inheritedAttribute('__init__'), args, kw)
 

Modified: Zope/trunk/src/OFS/Image.py
===================================================================
--- Zope/trunk/src/OFS/Image.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/OFS/Image.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -504,7 +504,7 @@
 
     def _get_content_type(self, file, body, id, content_type=None):
         headers=getattr(file, 'headers', None)
-        if headers and headers.has_key('content-type'):
+        if headers and 'content-type' in headers:
             content_type=headers['content-type']
         else:
             if not isinstance(body, str): body=body.data

Modified: Zope/trunk/src/OFS/ObjectManager.py
===================================================================
--- Zope/trunk/src/OFS/ObjectManager.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/OFS/ObjectManager.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -271,7 +271,7 @@
         else:
             all = self.all_meta_types
         for meta_type in all:
-            if meta_type.has_key('permission'):
+            if 'permission' in meta_type:
                 if sm.checkPermission(meta_type['permission'], self):
                     meta_types.append(meta_type)
             else:
@@ -474,7 +474,6 @@
         seen={}
         vals=[]
         relativePhysicalPath = ()
-        have=seen.has_key
         x=0
         while x < 100:
             if not hasattr(obj,'_getOb'): break
@@ -484,7 +483,7 @@
                     try:
                         id=i['id']
                         physicalPath = relativePhysicalPath + (id,)
-                        if (not have(physicalPath)) and (i['meta_type'] in t):
+                        if (physicalPath not in seen) and (i['meta_type'] in t):
                             vals.append(get(id))
                             seen[physicalPath]=1
                     except: pass

Modified: Zope/trunk/src/OFS/PropertyManager.py
===================================================================
--- Zope/trunk/src/OFS/PropertyManager.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/OFS/PropertyManager.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -204,7 +204,7 @@
             raise BadRequest, 'The property %s does not exist' % escape(id)
         if type(value)==type(''):
             proptype=self.getPropertyType(id) or 'string'
-            if type_converters.has_key(proptype):
+            if proptype in type_converters:
                 value=type_converters[proptype](value)
         self._setPropValue(id, value)
 
@@ -281,7 +281,7 @@
 
         Sets a new property with the given id, type, and value.
         """
-        if type_converters.has_key(type):
+        if type in type_converters:
             value=type_converters[type](value)
         self._setProperty(id.strip(), value, type)
         if REQUEST is not None:

Modified: Zope/trunk/src/OFS/PropertySheets.py
===================================================================
--- Zope/trunk/src/OFS/PropertySheets.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/OFS/PropertySheets.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -199,7 +199,7 @@
         pself=self.p_self()
         self=self.v_self()
         if hasattr(aq_base(self),id):
-            if not (id=='title' and not self.__dict__.has_key(id)):
+            if not (id=='title' and not id in self.__dict__):
                 raise BadRequest, (
                     'Invalid property id, <em>%s</em>. It is in use.' %
                         escape(id))
@@ -233,7 +233,7 @@
             raise BadRequest, '%s cannot be changed.' % escape(id)
         if type(value)==type(''):
             proptype=propinfo.get('type', 'string')
-            if type_converters.has_key(proptype):
+            if proptype in type_converters:
                 value=type_converters[proptype](value)
         if meta is not None:
             props=[]
@@ -361,7 +361,7 @@
         # property name and value for the requested property.
         xml_id=self.xml_namespace()
         propdict=self._propdict()
-        if not propdict.has_key(name):
+        if name not in propdict:
             if xml_id:
                 prop='<n:%s xmlns:n="%s"/>\n' % (name, xml_id)
             else:
@@ -419,7 +419,7 @@
     def manage_addProperty(self, id, value, type, REQUEST=None):
         """Add a new property via the web. Sets a new property with
         the given id, type, and value."""
-        if type_converters.has_key(type):
+        if type in type_converters:
             value=type_converters[type](value)
         self._setProperty(id, value, type)
         if REQUEST is not None:

Modified: Zope/trunk/src/OFS/Traversable.py
===================================================================
--- Zope/trunk/src/OFS/Traversable.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/OFS/Traversable.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -26,7 +26,7 @@
 from Acquisition import aq_inner
 from Acquisition import aq_parent
 from Acquisition.interfaces import IAcquirer
-from OFS.interfaces import ITraversable
+from OFS.interfaces import ITraversable, IApplication
 from zExceptions import NotFound
 from ZPublisher.interfaces import UseTraversalDefault
 from ZODB.POSException import ConflictError
@@ -118,11 +118,44 @@
         path = (self.getId(),)
 
         p = aq_parent(aq_inner(self))
+
         if p is not None:
             path = p.getPhysicalPath() + path
 
         return path
 
+        try:
+            path = [self.id]
+        except:
+            path = [self.getId()]
+
+        func = self.getPhysicalPath.im_func
+
+        try:
+            p = self.aq_inner.aq_parent
+        except:
+            p = aq_parent(aq_inner(self))
+
+        while p is not None:
+            if func is not p.getPhysicalPath.im_func:
+                if IApplication.providedBy(p):
+                    path.insert(0, '')
+                    path = tuple(path)
+                else:
+                    path = p.getPhysicalPath() + tuple(path)
+                break
+            else:
+                try:
+                    path.insert(0, p.id)
+                except:
+                    path.insert(0, p.getId())
+                try:
+                    p = p.aq_parent
+                except:
+                    p = None
+                
+        return path
+
     security.declarePrivate('unrestrictedTraverse')
     def unrestrictedTraverse(self, path, default=_marker, restricted=False):
         """Lookup an object by path.

Modified: Zope/trunk/src/Products/Five/browser/decode.py
===================================================================
--- Zope/trunk/src/Products/Five/browser/decode.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/Products/Five/browser/decode.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -17,7 +17,7 @@
 
 from warnings import warn
 
-from zope.publisher.browser import isCGI_NAME
+from ZPublisher.HTTPRequest import isCGI_NAMEs
 from zope.i18n.interfaces import IUserPreferredCharsets
 
 # taken and adapted from zope.publisher.browser.BrowserRequest
@@ -71,7 +71,7 @@
             charsets = envadapter.getPreferredCharsets() or ['utf-8']
 
     for name, value in request.form.items():
-        if not (isCGI_NAME(name) or name.startswith('HTTP_')):
+        if not (name in isCGI_NAMEs or name.startswith('HTTP_')):
             request.form[name] = processInputValue(value, charsets)
 
 def setPageEncoding(request):

Modified: Zope/trunk/src/Products/PageTemplates/PageTemplateFile.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/PageTemplateFile.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/Products/PageTemplates/PageTemplateFile.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -107,7 +107,7 @@
     def _exec(self, bound_names, args, kw):
         """Call a Page Template"""
         self._cook_check()
-        if not kw.has_key('args'):
+        if 'args' not in kw:
             kw['args'] = args
         bound_names['options'] = kw
 

Modified: Zope/trunk/src/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/ZopePageTemplate.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/Products/PageTemplates/ZopePageTemplate.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -303,7 +303,7 @@
 
     def _exec(self, bound_names, args, kw):
         """Call a Page Template"""
-        if not kw.has_key('args'):
+        if 'args' not in kw:
             kw['args'] = args
         bound_names['options'] = kw
 

Modified: Zope/trunk/src/Products/SiteAccess/VirtualHostMonster.py
===================================================================
--- Zope/trunk/src/Products/SiteAccess/VirtualHostMonster.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/Products/SiteAccess/VirtualHostMonster.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -97,7 +97,7 @@
                 else:
                     host_map = fixed_map
                 hostname, port = (host.split( ':', 1) + [None])[:2]
-                if not host_map.has_key(hostname):
+                if hostname not in host_map:
                     host_map[hostname] = {}
                 host_map[hostname][port] = pp
             except 'LineError', msg:

Modified: Zope/trunk/src/Shared/DC/Scripts/Bindings.py
===================================================================
--- Zope/trunk/src/Shared/DC/Scripts/Bindings.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/Shared/DC/Scripts/Bindings.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -55,7 +55,7 @@
         asgns = {}
         _isLegalName = self._isLegalName
         for name, expr in self._exprs:
-            if mapping.has_key(name):
+            if name in mapping:
                 assigned_name = string.strip(mapping[name])
                 if not assigned_name:
                     continue
@@ -71,7 +71,7 @@
         return 0
 
     def isNameAssigned(self, name):
-        return self._asgns.has_key(name)
+        return name in self._asgns
 
     def getAssignedName(self, name, default=_marker):
         val = self._asgns.get(name, default)
@@ -89,7 +89,7 @@
         rval = []
         asgns = self._asgns
         for name, expr in self._exprs:
-            if asgns.has_key(name):
+            if name in asgns:
                 assigned_name = asgns[name]
                 rval.append(assigned_name)
         return rval
@@ -114,7 +114,7 @@
         assigned_names = []
         asgns = self._asgns
         for name, expr in self._exprs:
-            if asgns.has_key(name):
+            if name in asgns:
                 assigned_name = asgns[name]
                 assigned_names.append(assigned_name)
                 exprtext.append('"%s":%s,' % (assigned_name, expr))
@@ -133,7 +133,7 @@
             passedLastBoundArg = 1
             for name, expr in self._exprs:
                 # Provide a value for the available exprs.
-                if asgns.has_key(name):
+                if name in asgns:
                     assigned_name = asgns[name]
                     if assigned_name == argName:
                         # The value for this argument will be filled in.

Modified: Zope/trunk/src/ZPublisher/BaseRequest.py
===================================================================
--- Zope/trunk/src/ZPublisher/BaseRequest.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/ZPublisher/BaseRequest.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -669,7 +669,7 @@
         if auth: name,password = auth
         elif roles is None: return ''
         else: return None
-    elif request.environ.has_key('REMOTE_USER'):
+    elif 'REMOTE_USER' in request.environ:
         name=request.environ['REMOTE_USER']
         password=None
     else:
@@ -693,11 +693,11 @@
         if roles is UNSPECIFIED_ROLES: roles=keys()
         g=[]
         for role in roles:
-            if groups.has_key(role): g.append(groups[role])
+            if role in groups: g.append(groups[role])
         groups=g
 
     for d in groups:
-        if d.has_key(name) and (d[name]==password or password is None):
+        if name in d and (d[name]==password or password is None):
             return name
 
     if keys is None:

Modified: Zope/trunk/src/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/trunk/src/ZPublisher/HTTPRequest.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/ZPublisher/HTTPRequest.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -58,7 +58,7 @@
 # This may get overwritten during configuration
 default_encoding = 'iso-8859-15'
 
-isCGI_NAME = {
+isCGI_NAMEs = {
         'SERVER_SOFTWARE' : 1,
         'SERVER_NAME' : 1,
         'GATEWAY_INTERFACE' : 1,
@@ -77,10 +77,12 @@
         'CONTENT_TYPE' : 1,
         'CONTENT_LENGTH' : 1,
         'SERVER_URL': 1,
-        }.has_key
+        }
 
-hide_key = {'HTTP_AUTHORIZATION':1, 'HTTP_CGI_AUTHORIZATION': 1}.has_key
+isCGI_NAME = isCGI_NAMEs.has_key
 
+hide_key = {'HTTP_AUTHORIZATION':1, 'HTTP_CGI_AUTHORIZATION': 1}
+
 default_port = {'http': '80', 'https': '443'}
 
 tainting_env = str(os.environ.get('ZOPE_DTML_REQUEST_AUTOQUOTE', '')).lower()
@@ -320,14 +322,13 @@
         if not clean:
             environ = sane_environment(environ)
 
-        if environ.has_key('HTTP_AUTHORIZATION'):
+        if 'HTTP_AUTHORIZATION' in environ:
             self._auth = environ['HTTP_AUTHORIZATION']
             response._auth = 1
             del environ['HTTP_AUTHORIZATION']
 
         self.stdin = stdin
         self.environ = environ
-        have_env = environ.has_key
         get_env = environ.get
         self.response = response
         other = self.other = {'RESPONSE': response}
@@ -340,9 +341,9 @@
         # We don't set up the locale initially but just on first access
         self._locale = _marker
 
-        if environ.has_key('REMOTE_ADDR'):
+        if 'REMOTE_ADDR' in environ:
             self._client_addr = environ['REMOTE_ADDR']
-            if (environ.has_key('HTTP_X_FORWARDED_FOR') and
+            if ('HTTP_X_FORWARDED_FOR' in environ and
                 self._client_addr in trusted_proxies):
                 # REMOTE_ADDR is one of our trusted local proxies.
                 # Not really very remote at all.  The proxy can tell us the
@@ -381,16 +382,16 @@
         if server_url is not None:
             other['SERVER_URL'] = server_url = server_url.strip()
         else:
-            if have_env('HTTPS') and (
+            if 'HTTPS' in environ and (
                 environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
                 protocol = 'https'
-            elif (have_env('SERVER_PORT_SECURE') and
+            elif ('SERVER_PORT_SECURE' in environ and
                 environ['SERVER_PORT_SECURE'] == "1"):
                 protocol = 'https'
             else:
                 protocol = 'http'
 
-            if have_env('HTTP_HOST'):
+            if 'HTTP_HOST' in environ:
                 host = environ['HTTP_HOST'].strip()
                 hostname, port = splitport(host)
 
@@ -400,7 +401,7 @@
                 # the commented code here in case we care enough to come
                 # back and do anything with it later.
                 #
-                # if port is None and environ.has_key('SERVER_PORT'):
+                # if port is None and 'SERVER_PORT' in environ:
                 #     s_port = environ['SERVER_PORT']
                 #     if s_port not in ('80', '443'):
                 #         port = s_port
@@ -485,17 +486,17 @@
         # If 'QUERY_STRING' is not present in environ
         # FieldStorage will try to get it from sys.argv[1]
         # which is not what we need.
-        if not environ.has_key('QUERY_STRING'):
+        if 'QUERY_STRING' not in environ:
             environ['QUERY_STRING'] = ''
 
         meth = None
         fs = ZopeFieldStorage(fp=fp,environ=environ,keep_blank_values=1)
         if not hasattr(fs,'list') or fs.list is None:
-            if environ.has_key('HTTP_SOAPACTION'):
+            if 'HTTP_SOAPACTION' in environ:
                 # Stash XML request for interpretation by a SOAP-aware view
                 other['SOAPXML'] = fs.value
             # Hm, maybe it's an XML-RPC
-            elif (fs.headers.has_key('content-type') and
+            elif ('content-type' in fs.headers and
                 'text/xml' in fs.headers['content-type'] and
                 method == 'POST'):
                 # Ye haaa, XML-RPC!
@@ -512,7 +513,7 @@
             fslist = fs.list
             tuple_items = {}
             lt = type([])
-            CGI_name = isCGI_NAME
+            CGI_name = isCGI_NAMEs
             defaults = {}
             tainteddefaults = {}
             converter = None
@@ -604,7 +605,7 @@
                             l = -1
 
                 # Filter out special names from form:
-                if CGI_name(key) or key[:5] == 'HTTP_':
+                if key in CGI_name or key[:5] == 'HTTP_':
                     continue
 
                 # If the key is tainted, mark it so as well.
@@ -669,13 +670,13 @@
 
                         except:
                             if (not item and not (flags & DEFAULT) and
-                                defaults.has_key(key)):
+                                key in defaults):
                                 item = defaults[key]
                                 if flags & RECORD:
                                     item = getattr(item,attr)
                                 if flags & RECORDS:
                                     item = getattr(item[-1], attr)
-                                if tainteddefaults.has_key(tainted_key):
+                                if tainted_key in tainteddefaults:
                                     tainted = tainteddefaults[tainted_key]
                                     if flags & RECORD:
                                         tainted = getattr(tainted, attr)
@@ -702,7 +703,7 @@
                         tainted_mapping = taintedform
 
                     #Insert in dictionary
-                    if mapping_object.has_key(key):
+                    if key in mapping_object:
                         if flags & RECORDS:
                             #Get the list and the last record
                             #in the list. reclist is mutable.
@@ -711,7 +712,7 @@
 
                             if tainted:
                                 # Store a tainted copy as well
-                                if not tainted_mapping.has_key(tainted_key):
+                                if tainted_key not in tainted_mapping:
                                     tainted_mapping[tainted_key] = deepcopy(
                                         reclist)
                                 treclist = tainted_mapping[tainted_key]
@@ -730,7 +731,7 @@
                                         setattr(newrec, attr, tainted)
                                         treclist.append(newrec)
 
-                            elif tainted_mapping.has_key(tainted_key):
+                            elif tainted_key in tainted_mapping:
                                 # If we already put a tainted value into this
                                 # recordset, we need to make sure the whole
                                 # recordset is built.
@@ -790,7 +791,7 @@
 
                             # Store a tainted copy as well if necessary
                             if tainted:
-                                if not tainted_mapping.has_key(tainted_key):
+                                if tainted_key not in tainted_mapping:
                                     tainted_mapping[tainted_key] = deepcopy(
                                         mapping_object[key])
                                 b = tainted_mapping[tainted_key]
@@ -801,7 +802,7 @@
                                 else:
                                     setattr(b, attr, tainted)
 
-                            elif tainted_mapping.has_key(tainted_key):
+                            elif tainted_key in tainted_mapping:
                                 # If we already put a tainted value into this
                                 # record, we need to make sure the whole record
                                 # is built.
@@ -819,7 +820,7 @@
 
                             if tainted:
                                 # Store a tainted version if necessary
-                                if not tainted_mapping.has_key(tainted_key):
+                                if tainted_key not in tainted_mapping:
                                     copied = deepcopy(found)
                                     if isinstance(copied, lt):
                                         tainted_mapping[tainted_key] = copied
@@ -827,7 +828,7 @@
                                         tainted_mapping[tainted_key] = [copied]
                                 tainted_mapping[tainted_key].append(tainted)
 
-                            elif tainted_mapping.has_key(tainted_key):
+                            elif tainted_key in tainted_mapping:
                                 # We may already have encountered a tainted
                                 # value for this key, and the tainted_mapping
                                 # needs to hold all the values.
@@ -898,13 +899,13 @@
                         tainted = item
 
                     #Insert in dictionary
-                    if mapping_object.has_key(key):
+                    if key in mapping_object:
                         # it is not a record or list of records
                         found = mapping_object[key]
 
                         if tainted:
                             # Store a tainted version if necessary
-                            if not taintedform.has_key(tainted_key):
+                            if tainted_key not in taintedform:
                                 copied = deepcopy(found)
                                 if isinstance(copied, lt):
                                     taintedform[tainted_key] = copied
@@ -915,7 +916,7 @@
                                     taintedform[tainted_key]]
                             taintedform[tainted_key].append(tainted)
 
-                        elif taintedform.has_key(tainted_key):
+                        elif tainted_key in taintedform:
                             # We may already have encountered a tainted value
                             # for this key, and the taintedform needs to hold
                             # all the values.
@@ -942,12 +943,12 @@
                     if '<' in key:
                         tainted_key = TaintedString(key)
 
-                    if not form.has_key(key):
+                    if key not in form:
                         # if the form does not have the key,
                         # set the default
                         form[key] = value
 
-                        if tainteddefaults.has_key(tainted_key):
+                        if tainted_key in tainteddefaults:
                             taintedform[tainted_key] = \
                                 tainteddefaults[tainted_key]
                     else:
@@ -959,13 +960,13 @@
                             r = form[key]
 
                             # First deal with tainted defaults.
-                            if taintedform.has_key(tainted_key):
+                            if tainted_key in taintedform:
                                 tainted = taintedform[tainted_key]
                                 for k, v in tdefault.__dict__.items():
                                     if not hasattr(tainted, k):
                                         setattr(tainted, k, v)
 
-                            elif tainteddefaults.has_key(tainted_key):
+                            elif tainted_key in tainteddefaults:
                                 # Find out if any of the tainted default
                                 # attributes needs to be copied over.
                                 missesdefault = 0
@@ -996,7 +997,7 @@
                                 l = [l]
 
                             # First deal with tainted copies
-                            if taintedform.has_key(tainted_key):
+                            if tainted_key in taintedform:
                                 tainted = taintedform[tainted_key]
                                 if not isinstance(tainted, lt):
                                     tainted = [tainted]
@@ -1011,7 +1012,7 @@
                                             tainted.append(defitem)
                                 taintedform[tainted_key] = tainted
 
-                            elif tainteddefaults.has_key(tainted_key):
+                            elif tainted_key in tainteddefaults:
                                 missesdefault = 0
                                 for defitem in tdefault:
                                     if isinstance(defitem, record):
@@ -1088,7 +1089,7 @@
                         a = a.split( ":")
                         a,new = ':'.join(a[:-1]), a[-1]
                     attr = new
-                    if form.has_key(k):
+                    if k in form:
                         # If the form has the split key get its value
                         tainted_split_key = k
                         if '<' in k:
@@ -1112,7 +1113,7 @@
                                     setattr(x,attr,value)
 
                         # Do the same for the tainted counterpart
-                        if taintedform.has_key(tainted_split_key):
+                        if tainted_split_key in taintedform:
                             tainted = taintedform[tainted_split_key]
                             if isinstance(item, record):
                                 seq = tuple(getattr(tainted, attr))
@@ -1128,19 +1129,19 @@
                         tainted_key = key
                         if '<' in key:
                             tainted_key = TaintedString(key)
-                        if form.has_key(key):
+                        if key in form:
                             # if it has the original key, get the item
                             # convert it to a tuple
                             item = form[key]
                             item = tuple(form[key])
                             form[key] = item
 
-                        if taintedform.has_key(tainted_key):
+                        if tainted_key in taintedform:
                             tainted = tuple(taintedform[tainted_key])
                             taintedform[tainted_key] = tainted
 
         if meth:
-            if environ.has_key('PATH_INFO'):
+            if 'PATH_INFO' in environ:
                 path = environ['PATH_INFO']
                 while path[-1:] == '/':
                     path = path[:-1]
@@ -1258,7 +1259,7 @@
 
         """ #"
         other = self.other
-        if other.has_key(key):
+        if key in other:
             if key == 'REQUEST':
                 return self
             return other[key]
@@ -1276,15 +1277,15 @@
                 else:
                     path = [other['SERVER_URL']] + path[:n]
                 URL = '/'.join(path)
-                if other.has_key('PUBLISHED'):
+                if 'PUBLISHED' in other:
                     # Don't cache URLs until publishing traversal is done.
                     other[key] = URL
                     self._urls = self._urls + (key,)
                 return URL
 
-        if isCGI_NAME(key) or key[:5] == 'HTTP_':
+        if key in isCGI_NAMEs or key[:5] == 'HTTP_':
             environ = self.environ
-            if environ.has_key(key) and (not hide_key(key)):
+            if key in environ and (key not in hide_key):
                 return environ[key]
             return ''
 
@@ -1310,7 +1311,7 @@
                 else:
                     v.insert(0, other['SERVER_URL'])
                 URL = '/'.join(v)
-                if other.has_key('PUBLISHED'):
+                if 'PUBLISHED' in other:
                     # Don't cache URLs until publishing traversal is done.
                     other[key] = URL
                     self._urls = self._urls + (key,)
@@ -1411,7 +1412,7 @@
         keys.update(self._lazies)
 
         for key in self.environ.keys():
-            if (isCGI_NAME(key) or key[:5] == 'HTTP_') and (not hide_key(key)):
+            if (key in isCGI_NAMEs or key[:5] == 'HTTP_') and (key not in hide_key):
                 keys[key] = 1
 
         # Cache URLN and BASEN in self.other.
@@ -1475,7 +1476,7 @@
 
         result = result + "</table><h3>environ</h3><table>"
         for k,v in self.environ.items():
-            if not hide_key(k):
+            if k not in hide_key:
                 result = result + row % (escape(k), escape(repr(v)))
         return result + "</table>"
 
@@ -1514,7 +1515,7 @@
 
         result = result + "\nENVIRON\n\n"
         for k,v in self.environ.items():
-            if not hide_key(k):
+            if k not in hide_key:
                 result = result + row % (k, v)
         return result
 
@@ -1580,7 +1581,7 @@
         while key[:9] == 'REDIRECT_':
             key = key[9:]
         dict[key] = val
-    if dict.has_key('HTTP_CGI_AUTHORIZATION'):
+    if 'HTTP_CGI_AUTHORIZATION' in dict:
         dict['HTTP_AUTHORIZATION'] = dict['HTTP_CGI_AUTHORIZATION']
         try:
             del dict['HTTP_CGI_AUTHORIZATION']
@@ -1666,7 +1667,6 @@
 
     if result is None:
         result = {}
-    already_have = result.has_key
 
     acquire()
     try:
@@ -1699,7 +1699,7 @@
     finally:
         release()
 
-    if not already_have(name):
+    if name not in result:
         result[name] = unquote(value)
 
     return apply(parse_cookie,(text[l:],result))

Modified: Zope/trunk/src/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/src/ZPublisher/HTTPResponse.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/ZPublisher/HTTPResponse.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -220,7 +220,7 @@
         if isinstance(status, str):
             status = status.lower()
 
-        if status_codes.has_key(status):
+        if status in status_codes:
             status = status_codes[status]
         else:
             status = 500
@@ -228,7 +228,7 @@
         self.status = status
 
         if reason is None:
-            if status_reasons.has_key(status):
+            if status in status_reasons:
                 reason = status_reasons[status]
             else:
                 reason = 'Unknown'
@@ -252,7 +252,7 @@
         value = str(value)
 
         cookies = self.cookies
-        if cookies.has_key(name):
+        if name in cookies:
             cookie = cookies[name]
         else:
             cookie = cookies[name] = {}
@@ -273,11 +273,11 @@
         value = str(value)
 
         cookies = self.cookies
-        if cookies.has_key(name):
+        if name in cookies:
             cookie = cookies[name]
         else:
             cookie = cookies[name] = {}
-        if cookie.has_key('value'):
+        if 'value' in cookie:
             cookie['value'] = '%s:%s' % (cookie['value'], value)
         else:
             cookie['value'] = value
@@ -351,7 +351,7 @@
         name = name.lower()
 
         headers = self.headers
-        if headers.has_key(name):
+        if name in headers:
             h = headers[name]
             h = "%s%s%s" % (h, delimiter, value)
         else:

Modified: Zope/trunk/src/ZPublisher/Publish.py
===================================================================
--- Zope/trunk/src/ZPublisher/Publish.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/ZPublisher/Publish.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -296,7 +296,7 @@
                     release=_l.release,
                     ):
 
-    if modules.has_key(module_name): return modules[module_name]
+    if module_name in modules: return modules[module_name]
 
     if module_name[-4:]=='.cgi': module_name=module_name[:-4]
 

Modified: Zope/trunk/src/ZTUtils/Zope.py
===================================================================
--- Zope/trunk/src/ZTUtils/Zope.py	2011-06-15 05:28:30 UTC (rev 121936)
+++ Zope/trunk/src/ZTUtils/Zope.py	2011-06-15 05:35:11 UTC (rev 121937)
@@ -297,18 +297,17 @@
             omits = {}
             for name in omit:
                 omits[name] = None
-        omitted = omits.has_key
 
         unq = urllib.unquote
         for i in range(len(qsparts)):
             name = unq(qsparts[i].split('=', 1)[0])
-            if omitted(name):
+            if name in omits:
                 qsparts[i] = ''
             name = name.split(':', 1)[0]
-            if omitted(name):
+            if name in omits:
                 qsparts[i] = ''
             name = name.split('.', 1)[0]
-            if omitted(name):
+            if name in omits:
                 qsparts[i] = ''
 
         qs = '&'.join(filter(None, qsparts))



More information about the Zope-Checkins mailing list