Imported zip from future_builtins instead of itertools.izip.

In Python 3, itertools.izip is not available any more (behaviour
integrated in standard zip).
This commit is contained in:
Claude Paroz 2012-05-07 17:25:12 +02:00
parent ecdd0914b1
commit 1aae1cba99
4 changed files with 14 additions and 13 deletions

View File

@ -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.backends.util import truncate_name, typecast_timestamp
from django.db.models.sql import compiler from django.db.models.sql import compiler
from django.db.models.sql.constants import MULTI from django.db.models.sql.constants import MULTI
@ -32,7 +33,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
if self.query.select: if self.query.select:
only_load = self.deferred_to_columns() only_load = self.deferred_to_columns()
# This loop customized for GeoQuery. # 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)): if isinstance(col, (list, tuple)):
alias, column = col alias, column = col
table = self.query.alias_map[alias].table_name table = self.query.alias_map[alias].table_name
@ -78,7 +79,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
]) ])
# This loop customized for GeoQuery. # 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) r = self.get_field_select(field, table, col)
if with_aliases and col in col_aliases: if with_aliases and col in col_aliases:
c_alias = 'Col%d' % len(col_aliases) c_alias = 'Col%d' % len(col_aliases)
@ -184,7 +185,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
values = [self.query.convert_values(v, values = [self.query.convert_values(v,
self.query.extra_select_fields.get(a, None), self.query.extra_select_fields.get(a, None),
self.connection) 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): 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 # We resolve the rest of the columns if we're on Oracle or if
# the `geo_values` attribute is defined. # the `geo_values` attribute is defined.

View File

@ -5,7 +5,7 @@ models for GeoDjango and/or mapping dictionaries for use with the
Author: Travis Pinney, Dane Springmeyer, & Justin Bronn Author: Travis Pinney, Dane Springmeyer, & Justin Bronn
""" """
from itertools import izip from future_builtins import zip
# Requires GDAL to use. # Requires GDAL to use.
from django.contrib.gis.gdal import DataSource from django.contrib.gis.gdal import DataSource
from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime 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 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. # The model field name.
mfield = field_name.lower() mfield = field_name.lower()
if mfield[-1:] == '_': mfield += 'field' if mfield[-1:] == '_': mfield += 'field'

View File

@ -1,7 +1,7 @@
import copy import copy
import sys import sys
from functools import update_wrapper from functools import update_wrapper
from itertools import izip from future_builtins import zip
import django.db.models.manager # Imported to register signal handler. import django.db.models.manager # Imported to register signal handler.
from django.conf import settings from django.conf import settings
@ -292,15 +292,15 @@ class Model(object):
fields_iter = iter(self._meta.fields) fields_iter = iter(self._meta.fields)
if not kwargs: 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 # 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 # is *not* consumed. We rely on this, so don't change the order
# without changing the logic. # 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) setattr(self, field.attname, val)
else: else:
# Slower, kwargs-ready version. # 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) setattr(self, field.attname, val)
kwargs.pop(field.name, None) kwargs.pop(field.name, None)
# Maintain compatibility with existing calls. # Maintain compatibility with existing calls.

View File

@ -1,4 +1,4 @@
from itertools import izip from future_builtins import zip
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.db import transaction from django.db import transaction
@ -882,7 +882,7 @@ class SQLInsertCompiler(SQLCompiler):
placeholders = [["%s"] * len(fields)] placeholders = [["%s"] * len(fields)]
else: else:
placeholders = [ 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 for val in values
] ]
if self.return_id and self.connection.features.can_return_id_from_insert: if self.return_id and self.connection.features.can_return_id_from_insert:
@ -899,7 +899,7 @@ class SQLInsertCompiler(SQLCompiler):
else: else:
return [ return [
(" ".join(result + ["VALUES (%s)" % ", ".join(p)]), vals) (" ".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): def execute_sql(self, return_id=False):