Commit 1890c5fa authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[toward py3k] rewrite has_key() (part of #2711624)

The `has_key` method is not in Python3K but dict supports __contains__ check for
ages.
parent 0bb18407c053
......@@ -898,7 +898,7 @@ class Entity(AppObject):
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()
......
......@@ -123,14 +123,14 @@ class HTMLTranslator(CSS1HTMLTranslator):
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'}
......
......@@ -169,7 +169,7 @@ def winclude_directive(name, arguments, options, content, lineno,
% (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
......
......@@ -501,7 +501,7 @@ class InsertPlan(ExecutionPlan):
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 @@ class InsertPlan(ExecutionPlan):
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 = []
......
......@@ -57,7 +57,7 @@ def _extract_const_attributes(plan, rqlst, to_build):
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:
......
......@@ -28,7 +28,7 @@ from cubicweb.server.migractions import ServerMigrationHelper
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') + '/'
......
......@@ -176,7 +176,7 @@ def read_config(config_file, raise_if_unreadable=False):
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
......
......@@ -127,9 +127,9 @@ class Controller(AppObject):
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)
......
......@@ -1292,8 +1292,7 @@ class Headers(object):
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 @@ class Headers(object):
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]
......
......@@ -92,7 +92,7 @@ def templatable_view(cls, req, rset, *args, **kwargs):
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 @@ class NonTemplatableViewTemplate(MainTemplate):
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()
......
......@@ -145,7 +145,7 @@ class EditController(basecontrollers.ViewController):
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 @@ class EditController(basecontrollers.ViewController):
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)
......
......@@ -127,7 +127,7 @@ class EmbedAction(Action):
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)
......
......@@ -43,7 +43,7 @@ class SendEmailAction(action.Action):
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)
......
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