Skip to content

Commit

Permalink
Imported zip from future_builtins instead of itertools.izip.
Browse files Browse the repository at this point in the history
In Python 3, itertools.izip is not available any more (behaviour
integrated in standard zip).
  • Loading branch information
claudep committed May 7, 2012
1 parent ecdd091 commit 1aae1cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions 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
Expand Down Expand Up @@ -32,7 +33,7 @@ def get_columns(self, with_aliases=False):
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
Expand Down Expand Up @@ -78,7 +79,7 @@ def get_columns(self, with_aliases=False):
])

# 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)
Expand Down Expand Up @@ -184,7 +185,7 @@ def resolve_columns(self, row, fields=()):
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.
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/gis/utils/ogrinspect.py
Expand Up @@ -5,7 +5,7 @@
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
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_kwargs_str(field_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.
mfield = field_name.lower()
if mfield[-1:] == '_': mfield += 'field'
Expand Down
8 changes: 4 additions & 4 deletions 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
Expand Down Expand Up @@ -292,15 +292,15 @@ def __init__(self, *args, **kwargs):

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.
Expand Down
6 changes: 3 additions & 3 deletions 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
Expand Down Expand Up @@ -882,7 +882,7 @@ def as_sql(self):
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:
Expand All @@ -899,7 +899,7 @@ def as_sql(self):
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):
Expand Down

0 comments on commit 1aae1cb

Please sign in to comment.