Commit c244e98a authored by Nikolay Kim's avatar Nikolay Kim

replace has_key with in operator

parent 05f73bda
......@@ -353,7 +353,7 @@ class ApplicationManager(Folder,CacheManager):
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):
......
......@@ -151,7 +151,7 @@ class ProductContext:
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 @@ class ProductContext:
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
......
......@@ -32,7 +32,7 @@ class ProductRegistryMixin:
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 @@ class ProductRegistryMixin:
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)
......
......@@ -44,7 +44,7 @@ class ClassicHTMLFile(DocumentTemplate.HTMLFile,MethodObject.Method,):
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)
......
......@@ -504,7 +504,7 @@ class File(Persistent, Implicit, PropertyManager,
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
......
......@@ -273,7 +273,7 @@ class ObjectManager(CopyContainer,
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:
......@@ -476,7 +476,6 @@ class ObjectManager(CopyContainer,
seen={}
vals=[]
relativePhysicalPath = ()
have=seen.has_key
x=0
while x < 100:
if not hasattr(obj,'_getOb'): break
......@@ -486,7 +485,7 @@ class ObjectManager(CopyContainer,
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
......
......@@ -204,7 +204,7 @@ class PropertyManager(Base, ElementWithAttributes):
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 @@ class PropertyManager(Base, ElementWithAttributes):
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:
......
......@@ -199,7 +199,7 @@ class PropertySheet(Traversable, Persistent, Implicit):
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 @@ class PropertySheet(Traversable, Persistent, Implicit):
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 @@ class PropertySheet(Traversable, Persistent, Implicit):
# 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 @@ class PropertySheet(Traversable, Persistent, Implicit):
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:
......
......@@ -15,7 +15,7 @@
encoding.
"""
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
......@@ -62,7 +62,7 @@ def processInputs(request, charsets=None):
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):
......
......@@ -109,7 +109,7 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable):
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
......
......@@ -303,7 +303,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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
......
......@@ -97,7 +97,7 @@ class VirtualHostMonster(Persistent, Item, Implicit):
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:
......
......@@ -55,7 +55,7 @@ class NameAssignments:
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 @@ class NameAssignments:
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 @@ class NameAssignments:
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 @@ class NameAssignments:
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 @@ class NameAssignments:
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.
......
......@@ -669,7 +669,7 @@ def old_validation(groups, request, auth,
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 @@ def old_validation(groups, request, auth,
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:
......
......@@ -69,7 +69,7 @@ class BaseResponse:
cookie in the Response object.
'''
cookies = self.cookies
if cookies.has_key(name):
if name in cookies:
cookie = cookies[name]
else:
cookie = cookies[name] = {}
......
This diff is collapsed.
......@@ -220,7 +220,7 @@ class HTTPResponse(BaseResponse):
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 @@ class HTTPResponse(BaseResponse):
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 @@ class HTTPResponse(BaseResponse):
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 @@ class HTTPResponse(BaseResponse):
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 @@ class HTTPResponse(BaseResponse):
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:
......
......@@ -286,7 +286,7 @@ def get_module_info(module_name, modules={},
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]
......
......@@ -297,18 +297,17 @@ def url_query(request, req_name="URL", omit=None):
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))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment