Commit de0f7d37 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: modernize -f xrange_six.

Jérome: slightly adjusted manually to just use range where it does not
make a significant difference (for example in test)
parent 96224c90
......@@ -16,6 +16,7 @@
"""
from DateTime import DateTime
from Products.CMFActivity.ActiveResult import ActiveResult
from six.moves import range
active_result = ActiveResult()
portal = context.getPortalObject()
activate = portal.portal_activities.activate
......@@ -54,7 +55,7 @@ if catalog_uid_list is None:
'tag': tag,
'fixit': fixit,
}
for _ in xrange(activity_count):
for _ in range(activity_count):
if len(catalog_uid_list) == 0:
result_list.append('No more uids to check, stop spawning activities.')
break
......
from Products.ERP5Type.Core.Workflow import ValidationFailed
from Products.ERP5Type.Message import Message
from six.moves import range
# Check new catalog or catalog is the same as previous archive
# Check date
......@@ -25,7 +26,7 @@ if archive.getStopDateRangeMax() is not None:
if len(previous_archive_list) > 0:
# Check the date
for x in xrange(len(previous_archive_list)):
for x in range(len(previous_archive_list)):
previous_archive = previous_archive_list[x]
# find a previous archive which was not for current catalog
if previous_archive.getStopDateRangeMax() is not None:
......@@ -40,7 +41,7 @@ else:
if len(previous_archive_list) > 0:
# Check the date
for x in xrange(len(previous_archive_list)):
for x in range(len(previous_archive_list)):
previous_archive = previous_archive_list[x]
# find a previous archive which was not for current catalog
if previous_archive.getStopDateRangeMax() is not None:
......
......@@ -2,6 +2,7 @@ from __future__ import print_function
from BTrees.LOBTree import LOBTree
from persistent import Persistent
import itertools
from six.moves import range
# Maximum memory to allocate for sparse-induced padding.
MAX_PADDING_CHUNK = 2 ** 20
......@@ -419,22 +420,22 @@ if __name__ == '__main__':
check(data, 36, 0, 36, '01ABC56789ABcDEFGHIJKL\x00NOPQRSTUVWXYZ', [0, 10, 20, 23, 33])
data = BTreeData(max_chunk_size=10)
for x in xrange(255):
for x in range(255):
data.write('%02x' % x, x * 2)
check(data, 510, 0, 10, '0001020304', [x * 2 for x in xrange(255)])
check(data, 510, 0, 10, '0001020304', [x * 2 for x in range(255)])
defragment_generator = data.defragment(batch_size=2)
defragment_generator.next()
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in xrange(2, 255)])
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in range(2, 255)])
opaque = defragment_generator.next()
defragment_generator.close()
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in xrange(4, 255)])
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in range(4, 255)])
defragment_generator = data.defragment(batch_size=2, resume_at=opaque)
defragment_generator.next()
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in xrange(5, 255)])
check(data, 510, 0, 10, '0001020304', [0] + [x * 2 for x in range(5, 255)])
defragment_generator.send(10)
check(data, 510, 0, 10, '0001020304', [0, 10, 20] + [x * 2 for x in xrange(13, 255)])
check(data, 510, 0, 10, '0001020304', [0, 10, 20] + [x * 2 for x in range(13, 255)])
defragment_generator.next()
check(data, 510, 0, 10, '0001020304', [0, 10, 20, 30, 40] + [x * 2 for x in xrange(23, 255)])
check(data, 510, 0, 10, '0001020304', [0, 10, 20, 30, 40] + [x * 2 for x in range(23, 255)])
for _ in defragment_generator:
pass
check(data, 510, 0, 10, '0001020304', [x * 10 for x in xrange(51)])
check(data, 510, 0, 10, '0001020304', [x * 10 for x in range(51)])
from Products.PythonScripts.standard import Object
from six.moves import range
request = container.REQUEST
portal = context.getPortalObject()
state_item_list=[x[1] for x in portal.ERP5Site_getWorkflowStateItemList(
......@@ -32,7 +33,7 @@ unassigned_dic['ticket_type']=portal.Base_translateString("Unassigned")
#Return index of uid into the list and append if not exists
def createReturnLine(uid, list_):
for i in xrange(len(list_)):
for i in range(len(list_)):
if list[i]['uid']==uid:
return i
new_dic=default_dic.copy()
......
......@@ -39,6 +39,7 @@ getPreferredCategoryChildItemListMethodId.
# It is much simpler if only "empty_category=False" case is handled.
from Products.ERP5Type.Cache import CachingMethod
from AccessControl import getSecurityManager
from six.moves import range
portal = context.getPortalObject()
checkPermission = portal.portal_membership.checkPermission
portal_preferences = portal.portal_preferences
......@@ -67,7 +68,7 @@ def getResourceItemList():
def getCategoryTitle_(category, depth):
result = []
append = result.append
for _ in xrange(depth + 1):
for _ in range(depth + 1):
append(getattr(category, accessor_id)())
category = category.getParentValue()
return '/'.join(result[::-1])
......
from six.moves import range
def cleanString(str):
clean_item = str
if clean_item.find('"') != -1:
......@@ -51,7 +52,7 @@ for line in iter(import_file.readline, ""):
csv_data_list = splitCsvLine(line)
attribute_value_dict = dict([(csv_property_list[x], csv_data_list[x]) \
for x in xrange(len(csv_property_list))])
for x in range(len(csv_property_list))])
method(priority=4, activity="SQLQueue").Base_importCsvLine(attribute_value_dict)
redirect_url = '%s?%s' % ( context.absolute_url()+'/'+'view', 'portal_status_message=Importing+CSV+file.')
......
......@@ -42,6 +42,7 @@ from erp5.component.module.WorkingCopy import \
NotAWorkingCopyError, NotVersionedError, VcsConflictError
from erp5.component.module.SubversionClient import newSubversionClient
from six import string_types as basestring
from six.moves import range
# XXX This does not work with concurrent processes/threads accessing the
# same working copy...
......@@ -390,7 +391,7 @@ class BusinessTemplateWorkingCopy(BusinessTemplateFolder):
prefix_length = len(os.path.join('.', ''))
for dirpath, dirnames, filenames in os.walk('.'):
dirpath = dirpath[prefix_length:]
for i in xrange(len(dirnames) - 1, -1, -1):
for i in range(len(dirnames) - 1, -1, -1):
d = dirnames[i]
if d[0] == '.':
# Ignore hidden directories (in particular '.svn')
......
......@@ -42,6 +42,7 @@ from ZTUtils import make_query
from Products.ERP5.Document.BusinessTemplate import BusinessTemplateFolder
from Products.ERP5Type.Utils import simple_decorator
from six import string_types as basestring
from six.moves import range
@simple_decorator
def selfcached(func):
......@@ -406,7 +407,7 @@ class BusinessTemplateWorkingCopy(BusinessTemplateFolder):
prefix_length = len(os.path.join(self.path, ''))
for dirpath, dirnames, filenames in os.walk(self.path):
dirpath = dirpath[prefix_length:]
for i in xrange(len(dirnames) - 1, -1, -1):
for i in range(len(dirnames) - 1, -1, -1):
d = dirnames[i]
if d[0] != '.':
d = os.path.join(dirpath, d)
......
......@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions
from Acquisition import Implicit
from BTrees.OOBTree import OOBTree
from warnings import warn
from six.moves import range
ACTIVITY_GROUPING_COUNT = 200
......@@ -172,7 +173,7 @@ class UrlRegistryTool(BaseTool):
object_list_len = len(object_list)
portal_activities = portal.portal_activities
object_path_list = [x.path for x in object_list]
for i in xrange(0, object_list_len, ACTIVITY_GROUPING_COUNT):
for i in range(0, object_list_len, ACTIVITY_GROUPING_COUNT):
current_path_list = object_path_list[i:i+ACTIVITY_GROUPING_COUNT]
portal_activities.activate(activity='SQLQueue', priority=3)\
.callMethodOnObjectList(current_path_list,
......
from six.moves import range
portal = context.getPortalObject()
batch_size = 100
priority = 1
......@@ -28,7 +29,7 @@ else:
object_list_len = len(payment_relative_url_list)
activate = portal.portal_activities.activate
for i in xrange(0, object_list_len, batch_size):
for i in range(0, object_list_len, batch_size):
current_path_list = payment_relative_url_list[i:i+batch_size]
activate(activity='SQLQueue', activate_kw=activate_kw,).callMethodOnObjectList(
current_path_list,
......
from Products.ERP5Form.Report import ReportSection
from six.moves import range
request = context.REQUEST
object_dict = {} # it contains required temp object to display the listbox
......@@ -79,7 +82,7 @@ project_relative_url_dict = {}
def fillDictWithParentAndChildRelativeUrls(my_dict, document_url):
if my_dict.get(document_url) is None:
splitted_document_url = document_url.split('/')
for x in xrange(0, len(splitted_document_url)):
for x in range(0, len(splitted_document_url)):
my_dict['/'.join(splitted_document_url[0:x+1])] = 1
......@@ -193,7 +196,6 @@ portal.portal_selections.setListboxDisplayMode(request, 'ReportTreeMode',
selection_name=selection_name)
result = []
from Products.ERP5Form.Report import ReportSection
project_dict = {}
for project_relative_url in project_relative_url_dict.keys():
......
......@@ -3,6 +3,7 @@
import random
import string
import json
from six.moves import range
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
......@@ -18,7 +19,7 @@ if user_quantity is None:
"error_message": "Parameter 'user_quantity' is required.",
"password" : None })
password = ''.join(random.choice(string.digits + string.ascii_letters) for i in xrange(10))
password = ''.join(random.choice(string.digits + string.ascii_letters) for i in range(10))
# check erp5_scalability_test business template is present
configurator = portal.business_configuration_module.default_standard_configuration
......
......@@ -5,6 +5,7 @@
# random password is given by parameter
from DateTime import DateTime
import json
from six.moves import range
now = DateTime()
portal = context.getPortalObject()
......@@ -19,7 +20,7 @@ try:
return json.dumps({"status_code" : 1, "error_message": error_message, "password" : None })
organisation = organisation.getObject().getRelativeUrl()
for i in xrange(0, int(user_quantity)):
for i in range(0, int(user_quantity)):
user_id = "scalability_user_%i" % i
person = portal_catalog.getResultValue(
portal_type="Person",
......
from Products.ERP5Type.Errors import ProgrammingError
from six.moves import range
zTrimInventoryCacheFromDateOnCatalog = getattr(context, 'SimulationTool_zTrimInventoryCacheFromDateOnCatalog', None)
if zTrimInventoryCacheFromDateOnCatalog is None:
return
min_date = None
for loop_item in xrange(len(uid)):
for loop_item in range(len(uid)):
if not isInventoryMovement[loop_item] and isMovement[loop_item] and getResourceUid[loop_item]:
if getDestinationUid[loop_item] and getStopDate[loop_item]:
if min_date:
......
from Products.ERP5Form.Report import ReportSection
from six.moves import range
portal = context.getPortalObject()
request = container.REQUEST
......@@ -22,7 +23,7 @@ try:
# split in chunks
batch_size = 1000
for uid_list in [all_uid_list[x:x+batch_size] for x in xrange(0, len(all_uid_list), batch_size)]:
for uid_list in [all_uid_list[x:x+batch_size] for x in range(0, len(all_uid_list), batch_size)]:
report_section_list.append(
ReportSection(form_id='DeliveryModule_viewDeliveryLineList',
path=context.getPhysicalPath(),
......
"""Returns a list of temp base objects"""
from Products.ERP5Type.Document import newTempBase
from six.moves import range
portal_object = context.getPortalObject()
return [newTempBase(portal_object, str(x), a=x, b=x) for x in xrange(10)]
return [newTempBase(portal_object, str(x), a=x, b=x) for x in range(10)]
"""Returns a list of temp base objects"""
from Products.ERP5Type.Document import newTempBase
from six.moves import range
portal_object = context.getPortalObject()
limit = kw.get('limit')
......@@ -9,7 +10,7 @@ size = list_lines or limit
result_list = []
result_list_append = result_list.append
for i in xrange(7):
for i in range(7):
if list_start < i + 1<= list_start + size:
caption = str(i)
result_list_append(newTempBase(portal_object, caption, a='A' + caption, b='B' + caption))
......
"""Return a list of Report Section"""
from Products.ERP5Form.Report import ReportSection
from six.moves import range
kw = {
'path': context.getPhysicalPath(),
'form_id': 'Foo_viewDummyListBox',
......@@ -8,4 +9,4 @@ kw = {
# 'selection_params': {},
'temporary_selection': False,
}
return [ReportSection(**kw) for _ in xrange(3)]
return [ReportSection(**kw) for _ in range(3)]
"""Reset report selections"""
from six.moves import range
manage_deleteSelection = context.getPortalObject().portal_selections.manage_deleteSelection
for index in xrange(3):
for index in range(3):
try:
manage_deleteSelection('x%s_foo_dummy_listbox_selection' % (index, ))
except KeyError:
......
......@@ -53,6 +53,7 @@
multiple sites on a single ERP5Site instance.
"""
from zExceptions import Unauthorized
from six.moves import range
if document is None: document = context
crumb_list = []
......@@ -69,7 +70,7 @@ is_web_section_default_document = bool(context.REQUEST.get('is_web_section_defau
if is_web_section_default_document:
last_breadcrumb_offset = 2
for chain_index in xrange(0, chain_list_length):
for chain_index in range(0, chain_list_length):
try:
crumb = chain_list[chain_index]
if chain_index == 0:
......
from six.moves import range
# -*- coding: utf-8 -*-
def createSPL(result, browser):
"""
......@@ -44,7 +45,7 @@ def createSPL(result, browser):
# Use fast input
result("Open fast input", browser.open(spl_url+'/Delivery_checkConsistencyForDeliveryFastInputDialog'))
for i in xrange(1,10):
for i in range(1,10):
browser.mainForm.getControl(name='field_listbox_title_new_%s' %(i,)).value = 'Luxury %s' %(i,)
browser.mainForm.getControl(name='field_listbox_quantity_new_%s' %(i,)).value = '%s' %(i,)
result("Update fast input", browser.mainForm.submitDialogUpdate(sleep=(10, 30)))
......
......@@ -30,11 +30,11 @@
from __future__ import print_function
from __future__ import absolute_import
from six.moves import input, xrange
import threading
from .AdvancedSearchTextDetector import AdvancedSearchTextDetector
from .AdvancedSearchTextParser import AdvancedSearchTextParser
from .lexer import ParserOrLexerError
from six.moves import range
if __name__ == '__main__':
DEBUG = 1
......@@ -137,7 +137,7 @@ if __name__ == '__main__':
return False
other_query_list = other.query_list[:]
for my_query in self.query_list:
for other_index in xrange(len(other_query_list)):
for other_index in range(len(other_query_list)):
other_query = other_query_list[other_index]
if my_query == other_query:
other_query_list.pop(other_index)
......
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