From 1aae1cba99b0f8232527742d64b120e4d902c68d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 7 May 2012 17:25:12 +0200 Subject: [PATCH] Imported zip from future_builtins instead of itertools.izip. In Python 3, itertools.izip is not available any more (behaviour integrated in standard zip). --- django/contrib/gis/db/models/sql/compiler.py | 9 +++++---- django/contrib/gis/utils/ogrinspect.py | 4 ++-- django/db/models/base.py | 8 ++++---- django/db/models/sql/compiler.py | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/django/contrib/gis/db/models/sql/compiler.py b/django/contrib/gis/db/models/sql/compiler.py index ca5a43a28a..ebaee60bd0 100644 --- a/django/contrib/gis/db/models/sql/compiler.py +++ b/django/contrib/gis/db/models/sql/compiler.py @@ -1,4 +1,5 @@ -from itertools import izip +from future_builtins import zip + from django.db.backends.util import truncate_name, typecast_timestamp from django.db.models.sql import compiler from django.db.models.sql.constants import MULTI @@ -32,7 +33,7 @@ class GeoSQLCompiler(compiler.SQLCompiler): if self.query.select: only_load = self.deferred_to_columns() # This loop customized for GeoQuery. - for col, field in izip(self.query.select, self.query.select_fields): + for col, field in zip(self.query.select, self.query.select_fields): if isinstance(col, (list, tuple)): alias, column = col table = self.query.alias_map[alias].table_name @@ -78,7 +79,7 @@ class GeoSQLCompiler(compiler.SQLCompiler): ]) # This loop customized for GeoQuery. - for (table, col), field in izip(self.query.related_select_cols, self.query.related_select_fields): + for (table, col), field in zip(self.query.related_select_cols, self.query.related_select_fields): r = self.get_field_select(field, table, col) if with_aliases and col in col_aliases: c_alias = 'Col%d' % len(col_aliases) @@ -184,7 +185,7 @@ class GeoSQLCompiler(compiler.SQLCompiler): values = [self.query.convert_values(v, self.query.extra_select_fields.get(a, None), self.connection) - for v, a in izip(row[rn_offset:index_start], aliases)] + for v, a in zip(row[rn_offset:index_start], aliases)] if self.connection.ops.oracle or getattr(self.query, 'geo_values', False): # We resolve the rest of the columns if we're on Oracle or if # the `geo_values` attribute is defined. diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py index a99989978e..a9a0362eef 100644 --- a/django/contrib/gis/utils/ogrinspect.py +++ b/django/contrib/gis/utils/ogrinspect.py @@ -5,7 +5,7 @@ models for GeoDjango and/or mapping dictionaries for use with the Author: Travis Pinney, Dane Springmeyer, & Justin Bronn """ -from itertools import izip +from future_builtins import zip # Requires GDAL to use. from django.contrib.gis.gdal import DataSource from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime @@ -165,7 +165,7 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non yield 'class %s(models.Model):' % model_name - for field_name, width, precision, field_type in izip(ogr_fields, layer.field_widths, layer.field_precisions, layer.field_types): + for field_name, width, precision, field_type in zip(ogr_fields, layer.field_widths, layer.field_precisions, layer.field_types): # The model field name. mfield = field_name.lower() if mfield[-1:] == '_': mfield += 'field' diff --git a/django/db/models/base.py b/django/db/models/base.py index 7df4f6d732..4b6683baae 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1,7 +1,7 @@ import copy import sys from functools import update_wrapper -from itertools import izip +from future_builtins import zip import django.db.models.manager # Imported to register signal handler. from django.conf import settings @@ -292,15 +292,15 @@ class Model(object): fields_iter = iter(self._meta.fields) if not kwargs: - # The ordering of the izip calls matter - izip throws StopIteration + # The ordering of the zip calls matter - zip throws StopIteration # when an iter throws it. So if the first iter throws it, the second # is *not* consumed. We rely on this, so don't change the order # without changing the logic. - for val, field in izip(args, fields_iter): + for val, field in zip(args, fields_iter): setattr(self, field.attname, val) else: # Slower, kwargs-ready version. - for val, field in izip(args, fields_iter): + for val, field in zip(args, fields_iter): setattr(self, field.attname, val) kwargs.pop(field.name, None) # Maintain compatibility with existing calls. diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index f864fd74e6..69b508fe97 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1,4 +1,4 @@ -from itertools import izip +from future_builtins import zip from django.core.exceptions import FieldError from django.db import transaction @@ -882,7 +882,7 @@ class SQLInsertCompiler(SQLCompiler): placeholders = [["%s"] * len(fields)] else: placeholders = [ - [self.placeholder(field, v) for field, v in izip(fields, val)] + [self.placeholder(field, v) for field, v in zip(fields, val)] for val in values ] if self.return_id and self.connection.features.can_return_id_from_insert: @@ -899,7 +899,7 @@ class SQLInsertCompiler(SQLCompiler): else: return [ (" ".join(result + ["VALUES (%s)" % ", ".join(p)]), vals) - for p, vals in izip(placeholders, params) + for p, vals in zip(placeholders, params) ] def execute_sql(self, return_id=False):