Permalink
Browse files

[py3] Fixed access to dict keys/values/items.

  • Loading branch information...
1 parent fa3f0aa commit ee191715eae73362768184aa95206cf61bac5d38 @aaugustin aaugustin committed Jul 20, 2012
Showing with 187 additions and 155 deletions.
  1. +1 −1 django/conf/__init__.py
  2. +2 −2 django/contrib/admin/helpers.py
  3. +3 −3 django/contrib/admin/options.py
  4. +4 −3 django/contrib/admin/sites.py
  5. +2 −1 django/contrib/admin/templatetags/admin_list.py
  6. +3 −2 django/contrib/admindocs/views.py
  7. +2 −1 django/contrib/auth/admin.py
  8. +2 −1 django/contrib/auth/tests/forms.py
  9. +3 −2 django/contrib/contenttypes/management.py
  10. +3 −5 django/contrib/databrowse/datastructures.py
  11. +1 −1 django/contrib/databrowse/plugins/calendars.py
  12. +1 −1 django/contrib/databrowse/plugins/fieldchoices.py
  13. +4 −3 django/contrib/formtools/wizard/storage/base.py
  14. +4 −4 django/contrib/formtools/wizard/views.py
  15. +3 −1 django/contrib/gis/db/backends/mysql/operations.py
  16. +1 −1 django/contrib/gis/db/backends/oracle/operations.py
  17. +2 −2 django/contrib/gis/db/backends/postgis/operations.py
  18. +1 −1 django/contrib/gis/db/backends/spatialite/operations.py
  19. +3 −2 django/contrib/gis/db/models/query.py
  20. +3 −2 django/contrib/gis/db/models/sql/compiler.py
  21. +2 −1 django/contrib/gis/geometry/test_data.py
  22. +1 −1 django/contrib/gis/measure.py
  23. +2 −1 django/contrib/gis/sitemaps/views.py
  24. +2 −1 django/contrib/messages/storage/cookie.py
  25. +10 −9 django/contrib/sessions/tests.py
  26. +2 −1 django/contrib/sitemaps/views.py
  27. +2 −1 django/contrib/staticfiles/finders.py
  28. +3 −2 django/core/management/__init__.py
  29. +1 −3 django/core/management/commands/diffsettings.py
  30. +3 −2 django/core/serializers/__init__.py
  31. +2 −1 django/core/serializers/python.py
  32. +1 −1 django/core/urlresolvers.py
  33. +1 −1 django/core/validators.py
  34. +2 −1 django/db/backends/mysql/introspection.py
  35. +2 −2 django/db/models/base.py
  36. +13 −12 django/db/models/deletion.py
  37. +4 −4 django/db/models/fields/related.py
  38. +3 −2 django/db/models/loading.py
  39. +8 −9 django/db/models/options.py
  40. +10 −10 django/db/models/query.py
  41. +3 −2 django/db/models/query_utils.py
  42. +4 −3 django/db/models/sql/compiler.py
  43. +13 −12 django/db/models/sql/query.py
  44. +3 −2 django/db/models/sql/subqueries.py
  45. +1 −1 django/forms/extras/widgets.py
  46. +3 −3 django/forms/forms.py
  47. +2 −1 django/forms/models.py
  48. +1 −2 django/forms/widgets.py
  49. +1 −1 django/template/base.py
  50. +3 −2 django/template/defaulttags.py
  51. +3 −2 django/template/loader_tags.py
  52. +1 −1 django/templatetags/i18n.py
  53. +4 −3 django/utils/dateparse.py
  54. +1 −1 django/utils/dictconfig.py
  55. +1 −1 django/utils/functional.py
  56. +1 −1 django/utils/html.py
  57. +3 −1 django/utils/termcolors.py
  58. +1 −1 django/views/debug.py
  59. +2 −1 django/views/generic/base.py
  60. +5 −4 tests/modeltests/timezones/tests.py
  61. +2 −1 tests/regressiontests/aggregation_regress/tests.py
  62. +2 −1 tests/regressiontests/db_typecasts/tests.py
  63. +3 −3 tests/regressiontests/templates/templatetags/custom.py
  64. +2 −1 tests/regressiontests/templates/tests.py
View
@@ -158,7 +158,7 @@ def __getattr__(self, name):
return getattr(self.default_settings, name)
def __dir__(self):
- return self.__dict__.keys() + dir(self.default_settings)
+ return list(six.iterkeys(self.__dict__)) + dir(self.default_settings)
# For Python < 2.6:
__members__ = property(lambda self: self.__dir__())
@@ -325,11 +325,11 @@ class AdminErrorList(forms.util.ErrorList):
"""
def __init__(self, form, inline_formsets):
if form.is_bound:
- self.extend(form.errors.values())
+ self.extend(list(six.itervalues(form.errors)))
for inline_formset in inline_formsets:
self.extend(inline_formset.non_form_errors())
for errors_in_inline_form in inline_formset.errors:
- self.extend(errors_in_inline_form.values())
+ self.extend(list(six.itervalues(errors_in_inline_form)))
def normalize_fieldsets(fieldsets):
"""
@@ -425,7 +425,7 @@ def get_fieldsets(self, request, obj=None):
if self.declared_fieldsets:
return self.declared_fieldsets
form = self.get_form(request, obj)
- fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
+ fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj))
return [(None, {'fields': fields})]
def get_form(self, request, obj=None, **kwargs):
@@ -608,7 +608,7 @@ def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
tuple (name, description).
"""
choices = [] + default_choices
- for func, name, description in self.get_actions(request).itervalues():
+ for func, name, description in six.itervalues(self.get_actions(request)):
choice = (name, description % model_format_dict(self.opts))
choices.append(choice)
return choices
@@ -1415,7 +1415,7 @@ def get_fieldsets(self, request, obj=None):
if self.declared_fieldsets:
return self.declared_fieldsets
form = self.get_formset(request, obj).form
- fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
+ fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj))
return [(None, {'fields': fields})]
def queryset(self, request):
@@ -10,6 +10,7 @@
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template.response import TemplateResponse
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
@@ -133,7 +134,7 @@ def actions(self):
"""
Get all the enabled actions as an iterable of (name, func).
"""
- return self._actions.iteritems()
+ return six.iteritems(self._actions)
def has_permission(self, request):
"""
@@ -239,7 +240,7 @@ def wrapper(*args, **kwargs):
)
# Add in each model's views.
- for model, model_admin in self._registry.iteritems():
+ for model, model_admin in six.iteritems(self._registry):
urlpatterns += patterns('',
url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
include(model_admin.urls))
@@ -370,7 +371,7 @@ def index(self, request, extra_context=None):
}
# Sort the apps alphabetically.
- app_list = app_dict.values()
+ app_list = list(six.itervalues(app_dict))
app_list.sort(key=lambda x: x['name'])
# Sort the models alphabetically within each app.
@@ -12,6 +12,7 @@
from django.utils import formats
from django.utils.html import format_html
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
from django.utils.encoding import smart_unicode, force_unicode
@@ -125,7 +126,7 @@ def result_headers(cl):
if i in ordering_field_columns:
sorted = True
order_type = ordering_field_columns.get(i).lower()
- sort_priority = ordering_field_columns.keys().index(i) + 1
+ sort_priority = list(six.iterkeys(ordering_field_columns)).index(i) + 1
th_classes.append('sorted %sending' % order_type)
new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type]
@@ -14,6 +14,7 @@
from django.contrib.admindocs import utils
from django.contrib.sites.models import Site
from django.utils.importlib import import_module
+from django.utils import six
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
@@ -48,7 +49,7 @@ def template_tag_index(request):
load_all_installed_template_libraries()
tags = []
- app_libs = template.libraries.items()
+ app_libs = list(six.iteritems(template.libraries))
builtin_libs = [(None, lib) for lib in template.builtins]
for module_name, library in builtin_libs + app_libs:
for tag_name, tag_func in library.tags.items():
@@ -83,7 +84,7 @@ def template_filter_index(request):
load_all_installed_template_libraries()
filters = []
- app_libs = template.libraries.items()
+ app_libs = list(six.iteritems(template.libraries))
builtin_libs = [(None, lib) for lib in template.builtins]
for module_name, library in builtin_libs + app_libs:
for filter_name, filter_func in library.filters.items():
@@ -12,6 +12,7 @@
from django.utils.html import escape
from django.utils.decorators import method_decorator
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.translation import ugettext, ugettext_lazy as _
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
@@ -128,7 +129,7 @@ def user_change_password(self, request, id, form_url=''):
else:
form = self.change_password_form(user)
- fieldsets = [(None, {'fields': form.base_fields.keys()})]
+ fieldsets = [(None, {'fields': list(six.iterkeys(form.base_fields))})]
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
context = {
@@ -9,6 +9,7 @@
from django.test import TestCase
from django.test.utils import override_settings
from django.utils.encoding import force_unicode
+from django.utils import six
from django.utils import translation
from django.utils.translation import ugettext as _
@@ -203,7 +204,7 @@ def test_success(self):
def test_field_order(self):
# Regression test - check the order of fields:
user = User.objects.get(username='testclient')
- self.assertEqual(PasswordChangeForm(user, {}).fields.keys(),
+ self.assertEqual(list(six.iterkeys(PasswordChangeForm(user, {}).fields)),
['old_password', 'new_password1', 'new_password2'])
@@ -1,6 +1,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import get_apps, get_models, signals
from django.utils.encoding import smart_unicode
+from django.utils import six
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
"""
@@ -24,7 +25,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
)
to_remove = [
ct
- for (model_name, ct) in content_types.iteritems()
+ for (model_name, ct) in six.iteritems(content_types)
if model_name not in app_models
]
@@ -34,7 +35,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
app_label=app_label,
model=model_name,
)
- for (model_name, model) in app_models.iteritems()
+ for (model_name, model) in six.iteritems(app_models)
if model_name not in content_types
])
if verbosity >= 2:
@@ -17,7 +17,7 @@ class EasyModel(object):
def __init__(self, site, model):
self.site = site
self.model = model
- self.model_list = site.registry.keys()
+ self.model_list = list(site.registry.keys())
self.verbose_name = model._meta.verbose_name
self.verbose_name_plural = model._meta.verbose_name_plural
@@ -176,8 +176,6 @@ def urls(self):
for plugin_name, plugin in self.model.model_databrowse().plugins.items():
urls = plugin.urls(plugin_name, self)
if urls is not None:
- #plugin_urls.append(urls)
- values = self.values()
return zip(self.values(), urls)
if self.field.rel:
m = EasyModel(self.model.site, self.field.rel.to)
@@ -196,10 +194,10 @@ def urls(self):
url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value))
lst.append((value, url))
elif isinstance(self.field, models.URLField):
- val = self.values()[0]
+ val = list(self.values())[0]
lst = [(val, iri_to_uri(val))]
else:
- lst = [(self.values()[0], None)]
+ lst = [(list(self.values())[0], None)]
return lst
class EasyQuerySet(QuerySet):
@@ -96,7 +96,7 @@ def model_view(self, request, model_databrowse, url):
def homepage_view(self, request):
easy_model = EasyModel(self.site, self.model)
- field_list = self.fields.values()
+ field_list = list(self.fields.values())
field_list.sort(key=lambda k:k.verbose_name)
return render_to_response('databrowse/calendar_homepage.html', {
'root_url': self.site.root_url,
@@ -63,7 +63,7 @@ def model_view(self, request, model_databrowse, url):
def homepage_view(self, request):
easy_model = EasyModel(self.site, self.model)
- field_list = self.fields.values()
+ field_list = list(self.fields.values())
field_list.sort(key=lambda k: k.verbose_name)
return render_to_response('databrowse/fieldchoice_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
@@ -2,6 +2,7 @@
from django.utils.datastructures import MultiValueDict
from django.utils.encoding import smart_str
from django.utils.functional import lazy_property
+from django.utils import six
from django.contrib.formtools.wizard.storage.exceptions import NoFileStorageConfigured
@@ -72,9 +73,9 @@ def get_step_files(self, step):
raise NoFileStorageConfigured
files = {}
- for field, field_dict in wizard_files.iteritems():
+ for field, field_dict in six.iteritems(wizard_files):
field_dict = dict((smart_str(k), v)
- for k, v in field_dict.iteritems())
+ for k, v in six.iteritems(field_dict))
tmp_name = field_dict.pop('tmp_name')
files[field] = UploadedFile(
file=self.file_storage.open(tmp_name), **field_dict)
@@ -87,7 +88,7 @@ def set_step_files(self, step, files):
if step not in self.data[self.step_files_key]:
self.data[self.step_files_key][step] = {}
- for field, field_file in (files or {}).iteritems():
+ for field, field_file in six.iteritems(files or {}):
tmp_filename = self.file_storage.save(field_file.name, field_file)
file_dict = {
'tmp_name': tmp_filename,
@@ -44,7 +44,7 @@ def __repr__(self):
@property
def all(self):
"Returns the names of all steps/forms."
- return self._wizard.get_form_list().keys()
+ return list(six.iterkeys(self._wizard.get_form_list()))
@property
def count(self):
@@ -164,14 +164,14 @@ def get_initkwargs(cls, form_list, initial_dict=None,
init_form_list[six.text_type(i)] = form
# walk through the new created list of forms
- for form in init_form_list.itervalues():
+ for form in six.itervalues(init_form_list):
if issubclass(form, formsets.BaseFormSet):
# if the element is based on BaseFormSet (FormSet/ModelFormSet)
# we need to override the form variable.
form = form.form
# check if any form contains a FileField, if yes, we need a
# file_storage added to the wizardview (by subclassing).
- for field in form.base_fields.itervalues():
+ for field in six.itervalues(form.base_fields):
if (isinstance(field, forms.FileField) and
not hasattr(cls, 'file_storage')):
raise NoFileStorageConfigured
@@ -196,7 +196,7 @@ def get_form_list(self):
could use data from other (maybe previous forms).
"""
form_list = SortedDict()
- for form_key, form_class in self.form_list.iteritems():
+ for form_key, form_class in six.iteritems(self.form_list):
# try to fetch the value from condition list, by default, the form
# gets passed to the new list.
condition = self.condition_dict.get(form_key, True)
@@ -3,6 +3,8 @@
from django.contrib.gis.db.backends.adapter import WKTAdapter
from django.contrib.gis.db.backends.base import BaseSpatialOperations
+from django.utils import six
+
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
@@ -30,7 +32,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
'within' : 'MBRWithin',
}
- gis_terms = dict([(term, None) for term in geometry_functions.keys() + ['isnull']])
+ gis_terms = dict([(term, None) for term in list(six.iterkeys(geometry_functions)) + ['isnull']])
def geo_db_type(self, f):
return f.geom_type
@@ -128,7 +128,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
geometry_functions.update(distance_functions)
gis_terms = ['isnull']
- gis_terms += geometry_functions.keys()
+ gis_terms += list(six.iterkeys(geometry_functions))
gis_terms = dict([(term, None) for term in gis_terms])
truncate_params = {'relate' : None}
@@ -217,8 +217,8 @@ def get_dist_ops(operator):
# Creating a dictionary lookup of all GIS terms for PostGIS.
gis_terms = ['isnull']
- gis_terms += self.geometry_operators.keys()
- gis_terms += self.geometry_functions.keys()
+ gis_terms += list(six.iterkeys(self.geometry_operators))
+ gis_terms += list(six.iterkeys(self.geometry_functions))
self.gis_terms = dict([(term, None) for term in gis_terms])
self.area = prefix + 'Area'
@@ -131,7 +131,7 @@ def __init__(self, connection):
# Creating the GIS terms dictionary.
gis_terms = ['isnull']
- gis_terms += self.geometry_functions.keys()
+ gis_terms += list(six.iterkeys(self.geometry_functions))
self.gis_terms = dict([(term, None) for term in gis_terms])
if version >= (2, 4, 0):
@@ -1,5 +1,6 @@
from django.db import connections
from django.db.models.query import QuerySet, ValuesQuerySet, ValuesListQuerySet
+from django.utils import six
from django.contrib.gis.db.models import aggregates
from django.contrib.gis.db.models.fields import get_srid_info, PointField, LineStringField
@@ -25,7 +26,7 @@ def values_list(self, *fields, **kwargs):
flat = kwargs.pop('flat', False)
if kwargs:
raise TypeError('Unexpected keyword arguments to values_list: %s'
- % (kwargs.keys(),))
+ % (list(six.iterkeys(kwargs)),))
if flat and len(fields) > 1:
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
return self._clone(klass=GeoValuesListQuerySet, setup=True, flat=flat,
@@ -531,7 +532,7 @@ def _spatial_attribute(self, att, settings, field_name=None, model_att=None):
if settings.get('setup', True):
default_args, geo_field = self._spatial_setup(att, desc=settings['desc'], field_name=field_name,
geo_field_type=settings.get('geo_field_type', None))
- for k, v in default_args.iteritems(): settings['procedure_args'].setdefault(k, v)
+ for k, v in six.iteritems(default_args): settings['procedure_args'].setdefault(k, v)
else:
geo_field = settings['geo_field']
@@ -3,6 +3,7 @@
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
+from django.utils import six
SQLCompiler = compiler.SQLCompiler
@@ -24,7 +25,7 @@ def get_columns(self, with_aliases=False):
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
result = ['(%s) AS %s' % (self.get_extra_select_format(alias) % col[0], qn2(alias))
- for alias, col in self.query.extra_select.iteritems()]
+ for alias, col in six.iteritems(self.query.extra_select)]
aliases = set(self.query.extra_select.keys())
if with_aliases:
col_aliases = aliases.copy()
@@ -170,7 +171,7 @@ def resolve_columns(self, row, fields=()):
objects.
"""
values = []
- aliases = self.query.extra_select.keys()
+ aliases = list(six.iterkeys(self.query.extra_select))
# Have to set a starting row number offset that is used for
# determining the correct starting row index -- needed for
Oops, something went wrong.

0 comments on commit ee19171

Please sign in to comment.