Commit acdd897a authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[py3k] use next builtin instead of next method

parent 4fb62d791073
......@@ -87,7 +87,7 @@ def ucsvreader(stream, encoding='utf-8', delimiter=',', quotechar='"',
it = iter(csvmod.reader(stream, delimiter=delimiter, quotechar=quotechar))
if not ignore_errors:
if skipfirst:
it.next()
next(it)
for row in it:
decoded = [item.decode(encoding) for item in row]
if not skip_empty or any(decoded):
......@@ -95,13 +95,13 @@ def ucsvreader(stream, encoding='utf-8', delimiter=',', quotechar='"',
else:
if skipfirst:
try:
row = it.next()
row = next(it)
except csvmod.Error:
pass
# Safe version, that can cope with error in CSV file
while True:
try:
row = it.next()
row = next(it)
# End of CSV, break
except StopIteration:
break
......
......@@ -79,7 +79,7 @@ def lazytable(reader):
>>> data = lazytable(ucsvreader(open(filename)))
"""
header = reader.next()
header = next(reader)
for row in reader:
yield dict(zip(header, row))
......
......@@ -458,7 +458,7 @@ class Entity(AppObject):
if len(value) == 0:
continue # avoid crash with empty IN clause
elif len(value) == 1:
value = iter(value).next()
value = next(iter(value))
else:
# prepare IN clause
pendingrels.append( (attr, role, value) )
......@@ -852,7 +852,7 @@ class Entity(AppObject):
if attributes is None:
self._cw_completed = True
varmaker = rqlvar_maker()
V = varmaker.next()
V = next(varmaker)
rql = ['WHERE %s eid %%(x)s' % V]
selected = []
for attr in (attributes or self._cw_to_complete_attributes(skip_bytes, skip_pwd)):
......@@ -860,7 +860,7 @@ class Entity(AppObject):
if attr in self.cw_attr_cache:
continue
# case where attribute must be completed, but is not yet in entity
var = varmaker.next()
var = next(varmaker)
rql.append('%s %s %s' % (V, attr, var))
selected.append((attr, var))
# +1 since this doesn't include the main variable
......@@ -879,7 +879,7 @@ class Entity(AppObject):
# * user has read perm on the relation and on the target entity
assert rschema.inlined
assert role == 'subject'
var = varmaker.next()
var = next(varmaker)
# keep outer join anyway, we don't want .complete to crash on
# missing mandatory relation (see #1058267)
rql.append('%s %s %s?' % (V, rtype, var))
......
......@@ -62,7 +62,7 @@ class FormulaDependenciesMatrixTC(TestCase):
def test_computed_attribute_by_relation(self):
comp_by_rdef = self.dependencies.computed_attribute_by_relation
self.assertEqual(len(comp_by_rdef), 1)
key, values = iter(comp_by_rdef.items()).next()
key, values = next(iter(comp_by_rdef.items()))
self.assertEqual(key.rtype, 'works_for')
self.assertEqual(len(values), 1)
self.assertEqual(values[0].rtype, 'total_salary')
......
......@@ -80,17 +80,17 @@ class PathParser :
self._restrictions = []
def parse(self) :
self._entity = self._components.next()
self._entity = next(self._components)
try:
self.process_entity()
except StopIteration :
pass
def process_entity(self) :
_next = self._components.next()
_next = next(self._components)
if _next in self.schema.get_attrs(self._entity) :
self._attr = _next
_next = self._components.next()
_next = next(self._components)
self._restrictions.append( (self._entity, self._attr, _next) )
self._attr = None
self._rel = None
......@@ -136,7 +136,7 @@ class SytPathParser :
def parse(self):
self._var = self._alphabet.pop(0)
self._e_type = self._components.next()
self._e_type = next(self._components)
e_type = self._e_type.capitalize()
self._restrictions.append('%s is %s' % (self._var, e_type))
try:
......@@ -146,11 +146,11 @@ class SytPathParser :
return 'Any %s WHERE %s' % (self._var, ', '.join(self._restrictions))
def process_entity(self) :
_next = self._components.next()
_next = next(self._components)
if _next in self.schema.get_attrs(self._e_type) :
attr = _next
try:
_next = self._components.next()
_next = next(self._components)
self._restrictions.append('%s %s %s' % (self._var, attr, _next))
except StopIteration:
a_var = self._alphabet.pop(0)
......@@ -163,7 +163,7 @@ class SytPathParser :
self._restrictions.append('%s %s %s' % (self._var, rel, r_var))
self._var = r_var
try:
_next = self._components.next()
_next = next(self._components)
self._restrictions.append('%s is %s' % (r_var, _next.capitalize()))
except StopIteration:
raise
......
......@@ -218,7 +218,7 @@ class RequestSessionBase(object):
parts.append(
'%(varname)s %(attr)s X, '
'%(varname)s eid %%(reverse_%(attr)s)s'
% {'attr': attr, 'varname': varmaker.next()})
% {'attr': attr, 'varname': next(varmaker)})
else:
assert attr in eschema.subjrels, \
'%s not in %s subject relations' % (attr, eschema)
......
......@@ -94,7 +94,7 @@ def add_types_restriction(schema, rqlst, newroot=None, solutions=None):
for etype in sorted(possibletypes):
node.append(n.Constant(etype, 'etype'))
else:
etype = iter(possibletypes).next()
etype = next(iter(possibletypes))
node = n.Constant(etype, 'etype')
comp = mytyperel.children[1]
comp.replace(comp.children[0], node)
......@@ -288,7 +288,7 @@ class RQLRewriter(object):
if fnode.name == 'FTIRANK':
# we've to fetch the has_text relation as well
var = fnode.children[0].variable
rel = iter(var.stinfo['ftirels']).next()
rel = next(iter(var.stinfo['ftirels']))
assert not rel.ored(), 'unsupported'
newselect.add_restriction(rel.copy(newselect))
# remove relation from the orig select and
......@@ -550,7 +550,7 @@ class RQLRewriter(object):
'cant check security of %s, ambigous type for %s in %s',
stmt, varname, key[0]) # key[0] == the rql expression
raise Unauthorized()
etype = iter(ptypes).next()
etype = next(iter(ptypes))
eschema = self.schema.eschema(etype)
if not eschema.has_perm(self.session, action):
rqlexprs = eschema.get_rqlexprs(action)
......@@ -684,7 +684,7 @@ class RQLRewriter(object):
# remove variable which have always the same type
for key in self.rewritten:
it = iter(variantes)
etype = it.next()[key]
etype = next(it)[key]
for variante in it:
if variante[key] != etype:
break
......
......@@ -384,7 +384,7 @@ class HooksRegistry(CWRegistry):
(main_filter.frometypes is not None or \
main_filter.toetypes is not None):
continue
first_kwargs = _iter_kwargs(entities, eids_from_to, kwargs).next()
first_kwargs = next(_iter_kwargs(entities, eids_from_to, kwargs))
if not main_filter(hook, cnx, **first_kwargs):
pruned.add(hook)
return pruned
......
......@@ -1560,12 +1560,14 @@ class ForRqlIterator:
else:
raise StopIteration
def next(self):
def __next__(self):
if self._rsetit is not None:
return self._rsetit.next()
return next(self._rsetit)
rset = self._get_rset()
self._rsetit = iter(rset)
return self._rsetit.next()
return next(self._rsetit)
next = __next__
def entities(self):
try:
......
......@@ -619,7 +619,7 @@ class Repository(object):
raise Exception('bad input for find_user')
with self.internal_cnx() as cnx:
varmaker = rqlvar_maker()
vars = [(attr, varmaker.next()) for attr in fetch_attrs]
vars = [(attr, next(varmaker)) for attr in fetch_attrs]
rql = 'Any %s WHERE X is CWUser, ' % ','.join(var[1] for var in vars)
rql += ','.join('X %s %s' % (var[0], var[1]) for var in vars) + ','
rset = cnx.execute(rql + ','.join('X %s %%(%s)s' % (attr, attr)
......
......@@ -195,7 +195,7 @@ def _select_principal(scope, relations, _sort=lambda x:x):
# if DISTINCT query, can use variable from a different scope as principal
# since introduced duplicates will be removed
if scope.stmt.distinct and diffscope_rels:
return iter(_sort(diffscope_rels)).next()
return next(iter(_sort(diffscope_rels)))
# XXX could use a relation from a different scope if it can't generate
# duplicates, so we should have to check cardinality
raise CantSelectPrincipal()
......
......@@ -1477,7 +1477,7 @@ class SQLGenerator(object):
"""generate SQL name for a function"""
if func.name == 'FTIRANK':
try:
rel = iter(func.children[0].variable.stinfo['ftirels']).next()
rel = next(iter(func.children[0].variable.stinfo['ftirels']))
except KeyError:
raise BadRQLQuery("can't use FTIRANK on variable not used in an"
" 'has_text' relation (eg full-text search)")
......@@ -1563,7 +1563,7 @@ class SQLGenerator(object):
# add additional restriction on entities.type column
pts = variable.stinfo['possibletypes']
if len(pts) == 1:
etype = iter(variable.stinfo['possibletypes']).next()
etype = next(iter(variable.stinfo['possibletypes']))
restr = "%s.type='%s'" % (vtablename, etype)
else:
etypes = ','.join("'%s'" % et for et in pts)
......@@ -1670,7 +1670,7 @@ class SQLGenerator(object):
except KeyError:
pass
rel = (variable.stinfo.get('principal') or
iter(variable.stinfo['rhsrelations']).next())
next(iter(variable.stinfo['rhsrelations'])))
linkedvar = rel.children[0].variable
if rel.r_type == 'eid':
return linkedvar.accept(self)
......
......@@ -85,7 +85,7 @@ class travaille_subdivision(RelationDefinition):
object = 'SubDivision'
from cubicweb.schemas.base import CWUser
CWUser.get_relations('login').next().fulltextindexed = True
next(CWUser.get_relations('login')).fulltextindexed = True
class Note(WorkflowableEntityType):
date = String(maxsize=10)
......
......@@ -148,7 +148,7 @@ class QueryInfo(object):
"""return corresponding rql query (string) / args (dict)"""
for varname, ptypes in self.possible_types.items():
if len(ptypes) == 1:
self.restrictions.append('%s is %s' % (varname, iter(ptypes).next()))
self.restrictions.append('%s is %s' % (varname, next(iter(ptypes))))
unions = []
for releq, subjvar, obj in self.union_params:
thisunions = []
......
......@@ -215,7 +215,7 @@ class View(AppObject):
return self._cw.build_url('view', vid=self.__regid__)
coltypes = rset.column_types(0)
if len(coltypes) == 1:
etype = iter(coltypes).next()
etype = next(iter(coltypes))
if not self._cw.vreg.schema.eschema(etype).final:
if len(rset) == 1:
entity = rset.get_entity(0, 0)
......@@ -283,7 +283,7 @@ class View(AppObject):
else :
etypes = rset.column_types(0)
if len(etypes) == 1:
etype = iter(etypes).next()
etype = next(iter(etypes))
clabel = display_name(self._cw, etype, 'plural')
else :
clabel = u'#[*] (%s)' % vtitle
......
......@@ -82,7 +82,7 @@ def rtype_facet_title(facet):
ptypes = facet.cw_rset.column_types(0)
if len(ptypes) == 1:
return display_name(facet._cw, facet.rtype, form=facet.role,
context=iter(ptypes).next())
context=next(iter(ptypes)))
return display_name(facet._cw, facet.rtype, form=facet.role)
def get_facet(req, facetid, select, filtered_variable):
......@@ -135,7 +135,7 @@ def get_filtered_variable(select, mainvar=None):
or the first variable selected in column 0
"""
if mainvar is None:
vref = select.selection[0].iget_nodes(nodes.VariableRef).next()
vref = next(select.selection[0].iget_nodes(nodes.VariableRef))
return vref.variable
return select.defined_vars[mainvar]
......@@ -831,13 +831,13 @@ class RelationFacet(VocabularyFacet):
if self._cw.vreg.schema.rschema(self.rtype).final:
return False
if self.role == 'object':
subj = utils.rqlvar_maker(defined=self.select.defined_vars,
aliases=self.select.aliases).next()
subj = next(utils.rqlvar_maker(defined=self.select.defined_vars,
aliases=self.select.aliases))
obj = self.filtered_variable.name
else:
subj = self.filtered_variable.name
obj = utils.rqlvar_maker(defined=self.select.defined_vars,
aliases=self.select.aliases).next()
obj = next(utils.rqlvar_maker(defined=self.select.defined_vars,
aliases=self.select.aliases))
restrictions = []
if self.select.where:
restrictions.append(self.select.where.as_string())
......@@ -1165,7 +1165,7 @@ class RQLPathFacet(RelationFacet):
if len(attrtypes) > 1:
raise Exception('ambigous attribute %s, specify attrtype on %s'
% (rtype, self.__class__))
self.restr_attr_type = iter(attrtypes).next()
self.restr_attr_type = next(iter(attrtypes))
if skipattrfilter:
actual_filter_variable = subject
continue
......
......@@ -362,7 +362,7 @@ def parseKeyValue(val):
def parseArgs(field):
args = split(field, Token(';'))
val = args.next()
val = next(args)
args = [parseKeyValue(arg) for arg in args]
return val, args
......
......@@ -357,7 +357,7 @@ class InlineEntityCreationFormView(InlineEntityEditionFormView):
self.w(self._cw._('no such entity type %s') % self.etype)
return
entity = cls(self._cw)
entity.eid = self._cw.varmaker.next()
entity.eid = next(self._cw.varmaker)
return entity
def call(self, i18nctx, **kwargs):
......
......@@ -395,7 +395,7 @@ class SameETypeListView(EntityView):
@property
def title(self):
etype = iter(self.cw_rset.column_types(0)).next()
etype = next(iter(self.cw_rset.column_types(0)))
return display_name(self._cw, etype, form='plural')
def call(self, **kwargs):
......
......@@ -93,7 +93,7 @@ class EditBox(component.CtxComponent):
etypes = self.cw_rset.column_types(0)
if len(etypes) == 1:
plural = self.cw_rset.rowcount > 1 and 'plural' or ''
etypelabel = display_name(self._cw, iter(etypes).next(), plural)
etypelabel = display_name(self._cw, next(iter(etypes)), plural)
title = u'%s - %s' % (title, etypelabel.lower())
w(title)
......
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