[toward py3k] rewrite has_key() (part of #2711624)
The `has_key` method is not in Python3K but dict supports __contains__ check for
ages.
--- a/entity.py Thu Feb 14 16:01:24 2013 +0100
+++ b/entity.py Thu Feb 14 16:45:07 2013 +0100
@@ -898,7 +898,7 @@
selected = []
for attr in (attributes or self._cw_to_complete_attributes(skip_bytes, skip_pwd)):
# if attribute already in entity, nothing to do
- if self.cw_attr_cache.has_key(attr):
+ if attr in self.cw_attr_cache:
continue
# case where attribute must be completed, but is not yet in entity
var = varmaker.next()
--- a/ext/html4zope.py Thu Feb 14 16:01:24 2013 +0100
+++ b/ext/html4zope.py Thu Feb 14 16:45:07 2013 +0100
@@ -123,14 +123,14 @@
def visit_reference(self, node):
"""syt: i want absolute urls"""
- if node.has_key('refuri'):
+ if 'refuri' in node:
href = node['refuri']
if ( self.settings.cloak_email_addresses
and href.startswith('mailto:')):
href = self.cloak_mailto(href)
self.in_mailto = 1
else:
- assert node.has_key('refid'), \
+ assert 'refid' in node, \
'References must have "refuri" or "refid" attribute.'
href = '%s#%s' % (self.base_url, node['refid'])
atts = {'href': href, 'class': 'reference'}
--- a/ext/rest.py Thu Feb 14 16:01:24 2013 +0100
+++ b/ext/rest.py Thu Feb 14 16:45:07 2013 +0100
@@ -169,7 +169,7 @@
% (name, error.__class__.__name__, error),
nodes.literal_block(block_text, block_text), line=lineno)
return [severe]
- if options.has_key('literal'):
+ if 'literal' in options:
literal_block = nodes.literal_block(include_text, include_text,
source=path)
literal_block.line = 1
--- a/server/querier.py Thu Feb 14 16:01:24 2013 +0100
+++ b/server/querier.py Thu Feb 14 16:45:07 2013 +0100
@@ -501,7 +501,7 @@
self.e_defs.append(row)
# now, see if this entity def is referenced as subject in some relation
# definition
- if self._r_subj_index.has_key(edef):
+ if edef in self._r_subj_index:
for rdef in self._r_subj_index[edef]:
expanded = self._expanded(rdef)
result = []
@@ -511,7 +511,7 @@
self._expanded_r_defs[rdef] = result
# and finally, see if this entity def is referenced as object in some
# relation definition
- if self._r_obj_index.has_key(edef):
+ if edef in self._r_obj_index:
for rdef in self._r_obj_index[edef]:
expanded = self._expanded(rdef)
result = []
--- a/server/ssplanner.py Thu Feb 14 16:01:24 2013 +0100
+++ b/server/ssplanner.py Thu Feb 14 16:45:07 2013 +0100
@@ -57,7 +57,7 @@
if attrtype == 'Password' and isinstance(value, unicode):
value = value.encode('UTF8')
edef.edited_attribute(rtype, value)
- elif to_build.has_key(str(rhs)):
+ elif str(rhs) in to_build:
# create a relation between two newly created variables
plan.add_relation_def((edef, rtype, to_build[rhs.name]))
else:
--- a/test/unittest_migration.py Thu Feb 14 16:01:24 2013 +0100
+++ b/test/unittest_migration.py Thu Feb 14 16:45:07 2013 +0100
@@ -28,7 +28,7 @@
class Schema(dict):
def has_entity(self, e_type):
- return self.has_key(e_type)
+ return e_type in self
SMIGRDIR = join(dirname(__file__), 'data', 'server_migration') + '/'
TMIGRDIR = join(dirname(__file__), 'data', 'migration') + '/'
--- a/toolsutils.py Thu Feb 14 16:01:24 2013 +0100
+++ b/toolsutils.py Thu Feb 14 16:45:07 2013 +0100
@@ -176,7 +176,7 @@
if option[0] == '[':
# start a section
section = option[1:-1]
- assert not config.has_key(section), \
+ assert section not in config, \
'Section %s is defined more than once' % section
config[section] = current = {}
continue
--- a/web/controller.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/controller.py Thu Feb 14 16:45:07 2013 +0100
@@ -127,9 +127,9 @@
msg = self._cw.message
if msg:
newparams['_cwmsgid'] = self._cw.set_redirect_message(msg)
- if self._cw.form.has_key('__action_apply'):
+ if '__action_apply' in self._cw.form:
self._return_to_edition_view(newparams)
- if self._cw.form.has_key('__action_cancel'):
+ if '__action_cancel' in self._cw.form:
self._return_to_lastpage(newparams)
else:
self._return_to_original_view(newparams)
--- a/web/http_headers.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/http_headers.py Thu Feb 14 16:45:07 2013 +0100
@@ -1292,8 +1292,7 @@
def __contains__(self, name):
"""Does a header with the given name exist?"""
- name=name.lower()
- return self._raw_headers.has_key(name)
+ return name.lower() in self._raw_headers
hasHeader = __contains__
@@ -1377,7 +1376,7 @@
def removeHeader(self, name):
"""Removes the header named."""
name=name.lower()
- if self._raw_headers.has_key(name):
+ if name in self._raw_headers:
del self._raw_headers[name]
del self._headers[name]
--- a/web/views/basetemplates.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/views/basetemplates.py Thu Feb 14 16:45:07 2013 +0100
@@ -92,7 +92,7 @@
return 1
if view.binary:
return 0
- if req.form.has_key('__notemplate'):
+ if '__notemplate' in req.form:
return 0
return view.templatable
@@ -105,7 +105,8 @@
def call(self, view):
view.set_request_content_type()
view.set_stream()
- if (self._cw.form.has_key('__notemplate') and view.templatable
+ if (('__notemplate' in self._cw.form)
+ and view.templatable
and view.content_type == self._cw.html_content_type()):
view.w(self._cw.document_surrounding_div())
view.render()
--- a/web/views/editcontroller.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/views/editcontroller.py Thu Feb 14 16:45:07 2013 +0100
@@ -145,7 +145,7 @@
for querydef in self.relations_rql:
self._cw.execute(*querydef)
# XXX this processes *all* pending operations of *all* entities
- if req.form.has_key('__delete'):
+ if '__delete' in req.form:
todelete = req.list_form_param('__delete', req.form, pop=True)
if todelete:
autoform.delete_relations(self._cw, todelete)
@@ -212,11 +212,11 @@
self._update_entity(eid, rqlquery)
if is_main_entity:
self.notify_edited(entity)
- if formparams.has_key('__delete'):
+ if '__delete' in formparams:
# XXX deprecate?
todelete = self._cw.list_form_param('__delete', formparams, pop=True)
autoform.delete_relations(self._cw, todelete)
- if formparams.has_key('__cloned_eid'):
+ if '__cloned_eid' in formparams:
entity.copy_relations(typed_eid(formparams['__cloned_eid']))
if is_main_entity: # only execute linkto for the main entity
self.execute_linkto(entity.eid)
--- a/web/views/embedding.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/views/embedding.py Thu Feb 14 16:45:07 2013 +0100
@@ -127,7 +127,7 @@
def url(self, row=0):
entity = self.cw_rset.get_entity(row, 0)
url = urljoin(self._cw.base_url(), entity.cw_adapt_to('IEmbedable').embeded_url())
- if self._cw.form.has_key('rql'):
+ if 'rql' in self._cw.form:
return self._cw.build_url('embed', url=url, rql=self._cw.form['rql'])
return self._cw.build_url('embed', url=url)
--- a/web/views/massmailing.py Thu Feb 14 16:01:24 2013 +0100
+++ b/web/views/massmailing.py Thu Feb 14 16:45:07 2013 +0100
@@ -43,7 +43,7 @@
def url(self):
params = {'vid': 'massmailing', '__force_display': 1}
- if self._cw.form.has_key('rql'):
+ if 'rql' in self._cw.form:
params['rql'] = self._cw.form['rql']
return self._cw.build_url(self._cw.relative_path(includeparams=False),
**params)