[py3k] import range from six.moves

Related to #266382.

authorRémi Cardona <remi.cardona@free.fr>
changeset461e0bbf10f1
branchdefault
phasepublic
hiddenno
parent revision#9c5c11cff6f3 [debian] require python >= 2.6
child revision#9af61103a375 [py3k] except as
files modified by this revision
__init__.py
ftiquery.py
sqlgen.py
sqlserver2005.py
test/unittest_db.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@free.fr>
# Date 1405973788 -7200
# Mon Jul 21 22:16:28 2014 +0200
# Node ID 461e0bbf10f19332bb18b40af6b054c2b16c89b1
# Parent 9c5c11cff6f3b5acfe46ccad52a74b2a40581bea
[py3k] import range from six.moves

Related to #266382.

diff --git a/__init__.py b/__init__.py
@@ -42,10 +42,11 @@
1  import threading
2  import logging
3  from datetime import datetime, time, date
4  from warnings import warn
5 
6 +from six.moves import range
7  from logilab.common.modutils import load_module_from_name
8  from logilab.common.date import todate, todatetime, utcdatetime, utctime
9  from logilab.common.deprecation import deprecated
10 
11  _LOGGER = logging.getLogger('logilab.database')
@@ -968,11 +969,11 @@
12          :needwrap: boolean, True if the query must be wrapped in a subquery
13          :has_limit_or_offset: not used (sqlserver helper needs this)
14          """
15          sql += '\nORDER BY %s' % ','.join(sortterms)
16          if sortterms and needwrap:
17 -            selection = ['T1.C%s' % i for i in xrange(len(selection))]
18 +            selection = ['T1.C%s' % i for i in range(len(selection))]
19              sql = 'SELECT %s FROM (%s) AS T1' % (','.join(selection), sql)
20          return sql
21 
22 
23      def sql_rename_col(self, table, column, newname, coltype, null_allowed):
diff --git a/ftiquery.py b/ftiquery.py
@@ -19,10 +19,11 @@
24  """Query objects for Generic Indexer.
25 
26  """
27  __docformat__ = "restructuredtext en"
28 
29 +from six.moves import range
30  from logilab.database.fti import StopWord, tokenize
31 
32  class Query(object):
33      """ a query is the object manipulated by the indexer
34      the query parser'll call add_word and add_phrase on this object accoring to
diff --git a/sqlgen.py b/sqlgen.py
@@ -18,10 +18,12 @@
35  """Help to generate SQL strings usable by the Python DB-API.
36 
37  """
38  __docformat__ = "restructuredtext en"
39 
40 +from six.moves import range
41 +
42  # SQLGenerator ################################################################
43 
44  class SQLExpression(object):
45      """Use this class when you need direct SQL expression in statements
46      generated by SQLGenerator. Arguments:
diff --git a/sqlserver2005.py b/sqlserver2005.py
@@ -25,10 +25,12 @@
47  import os
48  import sys
49  import shutil
50  from warnings import warn
51 
52 +from six.moves import range
53 +
54  from logilab import database as db
55  from logilab.database.sqlserver import _PyodbcAdapter, _AdodbapiAdapter
56 
57  class _PyodbcSqlServer2005Adapter(_PyodbcAdapter):
58      driver = "SQL Server Native Client 10.0"
@@ -216,11 +218,11 @@
59                                sql_add_limit_offset
60          """
61          if has_limit_or_offset:
62              return sql
63          if sortterms and needwrap:
64 -            selection = ['T1.C%s' % i for i in xrange(len(selection))]
65 +            selection = ['T1.C%s' % i for i in range(len(selection))]
66              renamed_sortterms = []
67              for term in sortterms:
68                  split = term.split()
69                  split[0] = 'T1.C%s' % (int(split[0])-1)
70                  renamed_sortterms.append(' '.join(split))
diff --git a/test/unittest_db.py b/test/unittest_db.py
@@ -20,10 +20,11 @@
71  """
72  from __future__ import with_statement
73 
74  import socket
75 
76 +from six.moves import range
77  from logilab.common.testlib import TestCase, unittest_main
78  from logilab.common.shellutils import getlogin
79  from logilab.database import *
80  from logilab.database import _PREFERED_DRIVERS as PREFERED_DRIVERS
81  from logilab.database.postgres import _PGAdvFuncHelper
@@ -277,11 +278,11 @@
82          cursor.close()
83          self.cnx.close()
84 
85      def blob(self):
86          cursor = self.cnx.cursor()
87 -        data_length = xrange(400*1024-10, 400*1024+10)
88 +        data_length = range(400*1024-10, 400*1024+10)
89          for length in data_length:
90              data = buffer('\x00'*length)
91              print "inserting string of length", len(data)
92              cursor.execute('insert into TestBlob(id, data) VALUES(%(id)s, %(data)s)',
93                             {'id': length, 'data': data})
@@ -290,11 +291,11 @@
94          print '%d rows in table' % (cursor.fetchone()[0])
95          cursor.close()
96 
97      def large_string(self):
98          cursor = self.cnx.cursor()
99 -        data_length = xrange(400*1024-10, 400*1024+10)
100 +        data_length = range(400*1024-10, 400*1024+10)
101          for length in data_length:
102              data = '1'*length
103              print "inserting string of length", len(data)
104              cursor.execute('insert into TestLargeString(id, data) VALUES(%(id)s, %(data)s)',
105                             {'id': length, 'data': data})