[py3k] use next builtin instead of next method
authorRémi Cardona <remi.cardona@logilab.fr>
Fri, 18 Sep 2015 14:29:53 +0200
changeset 10669 155c29e0ed1c
parent 10668 4fb62d791073
child 10670 96380c1524b0
[py3k] use next builtin instead of next method
dataimport/csv.py
dataimport/deprecated.py
entity.py
hooks/test/unittest_synccomputed.py
misc/cwfs/cwfs.py
req.py
rqlrewrite.py
server/hook.py
server/migractions.py
server/repository.py
server/rqlannotation.py
server/sources/rql2sql.py
server/test/data/schema.py
spa2rql.py
view.py
web/facet.py
web/http_headers.py
web/views/autoform.py
web/views/baseviews.py
web/views/boxes.py
web/views/cwproperties.py
web/views/editcontroller.py
web/views/editforms.py
web/views/magicsearch.py
web/views/plots.py
web/views/reledit.py
web/views/wdoc.py
web/views/workflow.py
--- a/dataimport/csv.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/dataimport/csv.py	Fri Sep 18 14:29:53 2015 +0200
@@ -87,7 +87,7 @@
     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 @@
     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
--- a/dataimport/deprecated.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/dataimport/deprecated.py	Fri Sep 18 14:29:53 2015 +0200
@@ -79,7 +79,7 @@
 
     >>> data = lazytable(ucsvreader(open(filename)))
     """
-    header = reader.next()
+    header = next(reader)
     for row in reader:
         yield dict(zip(header, row))
 
--- a/entity.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/entity.py	Fri Sep 18 14:29:53 2015 +0200
@@ -458,7 +458,7 @@
                 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 @@
         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 @@
             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 @@
                 # * 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))
--- a/hooks/test/unittest_synccomputed.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/hooks/test/unittest_synccomputed.py	Fri Sep 18 14:29:53 2015 +0200
@@ -62,7 +62,7 @@
     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')
--- a/misc/cwfs/cwfs.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/misc/cwfs/cwfs.py	Fri Sep 18 14:29:53 2015 +0200
@@ -80,17 +80,17 @@
         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 @@
 
     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 @@
         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 @@
             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
--- a/req.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/req.py	Fri Sep 18 14:29:53 2015 +0200
@@ -218,7 +218,7 @@
                 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)
--- a/rqlrewrite.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/rqlrewrite.py	Fri Sep 18 14:29:53 2015 +0200
@@ -94,7 +94,7 @@
                     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 @@
                         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 @@
                     '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 @@
         # 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
--- a/server/hook.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/hook.py	Fri Sep 18 14:29:53 2015 +0200
@@ -384,7 +384,7 @@
                            (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
--- a/server/migractions.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/migractions.py	Fri Sep 18 14:29:53 2015 +0200
@@ -1560,12 +1560,14 @@
             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:
--- a/server/repository.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/repository.py	Fri Sep 18 14:29:53 2015 +0200
@@ -619,7 +619,7 @@
                 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)
--- a/server/rqlannotation.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/rqlannotation.py	Fri Sep 18 14:29:53 2015 +0200
@@ -195,7 +195,7 @@
     # 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()
--- a/server/sources/rql2sql.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/sources/rql2sql.py	Fri Sep 18 14:29:53 2015 +0200
@@ -1477,7 +1477,7 @@
         """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 @@
                     # 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 @@
             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)
--- a/server/test/data/schema.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/server/test/data/schema.py	Fri Sep 18 14:29:53 2015 +0200
@@ -85,7 +85,7 @@
     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)
--- a/spa2rql.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/spa2rql.py	Fri Sep 18 14:29:53 2015 +0200
@@ -148,7 +148,7 @@
         """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 = []
--- a/view.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/view.py	Fri Sep 18 14:29:53 2015 +0200
@@ -215,7 +215,7 @@
             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 @@
             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
--- a/web/facet.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/facet.py	Fri Sep 18 14:29:53 2015 +0200
@@ -82,7 +82,7 @@
         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 @@
     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 @@
         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 @@
                         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
--- a/web/http_headers.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/http_headers.py	Fri Sep 18 14:29:53 2015 +0200
@@ -362,7 +362,7 @@
 
 def parseArgs(field):
     args = split(field, Token(';'))
-    val = args.next()
+    val = next(args)
     args = [parseKeyValue(arg) for arg in args]
     return val, args
 
--- a/web/views/autoform.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/autoform.py	Fri Sep 18 14:29:53 2015 +0200
@@ -357,7 +357,7 @@
             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):
--- a/web/views/baseviews.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/baseviews.py	Fri Sep 18 14:29:53 2015 +0200
@@ -395,7 +395,7 @@
 
     @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):
--- a/web/views/boxes.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/boxes.py	Fri Sep 18 14:29:53 2015 +0200
@@ -93,7 +93,7 @@
             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)
 
--- a/web/views/cwproperties.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/cwproperties.py	Fri Sep 18 14:29:53 2015 +0200
@@ -171,7 +171,7 @@
             entity = self.cwprops_rset.get_entity(values[key], 0)
         else:
             entity = self._cw.vreg['etypes'].etype_class('CWProperty')(self._cw)
-            entity.eid = self._cw.varmaker.next()
+            entity.eid = next(self._cw.varmaker)
             entity.cw_attr_cache['pkey'] = key
             entity.cw_attr_cache['value'] = self._cw.vreg.property_value(key)
         return entity
--- a/web/views/editcontroller.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/editcontroller.py	Fri Sep 18 14:29:53 2015 +0200
@@ -93,9 +93,9 @@
 
     def update_query(self, eid):
         varmaker = rqlvar_maker()
-        var = varmaker.next()
+        var = next(varmaker)
         while var in self.kwargs:
-            var = varmaker.next()
+            var = next(varmaker)
         rql = 'SET %s WHERE X eid %%(%s)s' % (','.join(self.edited), var)
         if self.restrictions:
             rql += ', %s' % ','.join(self.restrictions)
@@ -316,7 +316,7 @@
         """handle edition for the (rschema, x) relation of the given entity
         """
         if values:
-            rqlquery.set_inlined(field.name, iter(values).next())
+            rqlquery.set_inlined(field.name, next(iter(values)))
         elif form.edited_entity.has_eid():
             self.handle_relation(form, field, values, origvalues)
 
@@ -361,7 +361,7 @@
             # In the face of ambiguity, refuse the temptation to guess.
             self._after_deletion_path = 'view', ()
         else:
-            self._after_deletion_path = iter(redirect_info).next()
+            self._after_deletion_path = next(iter(redirect_info))
         if len(eidtypes) > 1:
             self._cw.set_message(self._cw._('entities deleted'))
         else:
--- a/web/views/editforms.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/editforms.py	Fri Sep 18 14:29:53 2015 +0200
@@ -147,7 +147,7 @@
         # selector
         etype = kwargs.pop('etype', self._cw.form.get('etype'))
         entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw)
-        entity.eid = self._cw.varmaker.next()
+        entity.eid = next(self._cw.varmaker)
         self.render_form(entity)
 
     def form_title(self, entity):
@@ -199,7 +199,7 @@
         entity.complete()
         self.newentity = copy(entity)
         self.copying = entity
-        self.newentity.eid = self._cw.varmaker.next()
+        self.newentity.eid = next(self._cw.varmaker)
         self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
                % self._cw._(self.warning_message))
         super(CopyFormView, self).render_form(self.newentity)
--- a/web/views/magicsearch.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/magicsearch.py	Fri Sep 18 14:29:53 2015 +0200
@@ -86,7 +86,7 @@
             else:
                 # Only one possible translation, no ambiguity
                 if len(translation_set) == 1:
-                    relation.r_type = iter(translations[rtype]).next()
+                    relation.r_type = next(iter(translations[rtype]))
                 # More than 1 possible translation => resolve it later
                 else:
                     ambiguous_nodes[relation] = (lhs.name, translation_set)
@@ -589,7 +589,7 @@
         """
         schema = self._cw.vreg.schema
         relations = set()
-        untyped_dest_var = rqlvar_maker(defined=select.defined_vars).next()
+        untyped_dest_var = next(rqlvar_maker(defined=select.defined_vars))
         # for each solution
         # 1. find each possible relation
         # 2. for each relation:
--- a/web/views/plots.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/plots.py	Fri Sep 18 14:29:53 2015 +0200
@@ -119,7 +119,7 @@
         if req.ie_browser():
             req.add_js('excanvas.js')
         req.add_js(('jquery.flot.js', 'cubicweb.flot.js'))
-        figid = u'figure%s' % req.varmaker.next()
+        figid = u'figure%s' % next(req.varmaker)
         plotdefs = []
         plotdata = []
         self.w(u'<div id="%s" style="width: %spx; height: %spx;"></div>' %
--- a/web/views/reledit.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/reledit.py	Fri Sep 18 14:29:53 2015 +0200
@@ -259,7 +259,7 @@
         elif action == 'add':
             add_etype = self._compute_ttypes(rschema, role)[0]
             _new_entity = self._cw.vreg['etypes'].etype_class(add_etype)(self._cw)
-            _new_entity.eid = self._cw.varmaker.next()
+            _new_entity.eid = next(self._cw.varmaker)
             edit_entity = _new_entity
             # XXX see forms.py ~ 276 and entities.linked_to method
             #     is there another way?
--- a/web/views/wdoc.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/wdoc.py	Fri Sep 18 14:29:53 2015 +0200
@@ -73,7 +73,7 @@
 
 def build_toc(config):
     alltocfiles = reversed(tuple(config.locate_all_files('toc.xml')))
-    maintoc = parse(alltocfiles.next()).getroot()
+    maintoc = parse(next(alltocfiles)).getroot()
     maintoc.parent = None
     index = {}
     build_toc_index(maintoc, index)
--- a/web/views/workflow.py	Tue Sep 15 17:10:58 2015 +0200
+++ b/web/views/workflow.py	Fri Sep 18 14:29:53 2015 +0200
@@ -116,7 +116,7 @@
             'changestate', self._cw, entity=entity, transition=transition,
             redirect_path=self.redirectpath(entity), **kwargs)
         trinfo = self._cw.vreg['etypes'].etype_class('TrInfo')(self._cw)
-        trinfo.eid = self._cw.varmaker.next()
+        trinfo.eid = next(self._cw.varmaker)
         subform = self._cw.vreg['forms'].select('edition', self._cw, entity=trinfo,
                                                 mainform=False)
         subform.field_by_name('wf_info_for', 'subject').value = entity.eid