-
From 2654119fd9604f480e09bbd77e1d780a8de9d85f Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Thu, 29 Aug 2013 19:20:00 -0400
Subject: [PATCH] Fixed #20989 -- Removed useless explicit list comprehensions.
---
django/contrib/admin/filters.py | 4 ++--
django/contrib/admin/helpers.py | 2 +-
django/contrib/admin/options.py | 6 ++---
django/contrib/admin/widgets.py | 6 ++---
django/contrib/admindocs/utils.py | 2 +-
django/contrib/auth/backends.py | 4 ++--
django/contrib/auth/forms.py | 4 ++--
django/contrib/contenttypes/management.py | 4 ++--
django/contrib/gis/db/models/sql/aggregates.py | 2 +-
django/contrib/gis/feeds.py | 2 +-
django/contrib/gis/gdal/geometries.py | 10 ++++----
django/contrib/gis/geos/collections.py | 2 +-
django/contrib/gis/geos/coordseq.py | 4 ++--
django/contrib/gis/geos/polygon.py | 6 ++---
django/contrib/gis/geos/tests/test_geos.py | 6 ++---
.../contrib/gis/management/commands/ogrinspect.py | 4 ++--
django/contrib/gis/maps/google/gmap.py | 2 +-
django/contrib/gis/maps/google/overlays.py | 2 +-
django/contrib/gis/tests/geoadmin/tests.py | 2 +-
django/contrib/gis/tests/geoapp/test_feeds.py | 2 +-
django/contrib/gis/tests/geoapp/test_sitemaps.py | 2 +-
django/contrib/gis/utils/wkt.py | 10 ++++----
django/contrib/messages/storage/cookie.py | 4 ++--
django/contrib/webdesign/lorem_ipsum.py | 2 +-
django/core/cache/utils.py | 2 +-
django/core/management/__init__.py | 6 ++---
django/core/management/commands/migrate.py | 2 +-
django/core/management/sql.py | 2 +-
django/core/management/utils.py | 2 +-
django/core/management/validation.py | 2 +-
django/core/urlresolvers.py | 6 ++---
django/db/backends/__init__.py | 2 +-
django/db/backends/mysql/compiler.py | 2 +-
django/db/backends/mysql/introspection.py | 4 ++--
django/db/backends/oracle/base.py | 8 +++----
django/db/backends/oracle/introspection.py | 2 +-
django/db/backends/sqlite3/schema.py | 4 ++--
django/db/migrations/autodetector.py | 4 ++--
django/db/migrations/writer.py | 2 +-
django/db/models/base.py | 4 ++--
django/db/models/deletion.py | 4 ++--
django/db/models/options.py | 2 +-
django/db/models/query.py | 2 +-
django/db/models/sql/aggregates.py | 2 +-
django/db/models/sql/compiler.py | 8 +++----
django/db/models/sql/query.py | 14 +++++------
django/forms/fields.py | 4 ++--
django/forms/formsets.py | 6 ++---
django/forms/models.py | 6 ++---
django/forms/util.py | 4 ++--
django/template/base.py | 6 ++---
django/template/defaulttags.py | 10 ++++----
django/template/loader_tags.py | 8 +++----
django/test/_doctest.py | 6 ++---
django/utils/cache.py | 10 ++++----
django/utils/checksums.py | 4 ++--
django/utils/crypto.py | 2 +-
django/utils/datastructures.py | 2 +-
django/utils/html.py | 6 ++---
django/utils/termcolors.py | 4 ++--
django/utils/text.py | 2 +-
django/utils/translation/__init__.py | 2 +-
tests/backends/tests.py | 2 +-
tests/file_uploads/views.py | 4 ++--
tests/forms_tests/tests/test_error_messages.py | 2 +-
tests/forms_tests/tests/test_extra.py | 2 +-
tests/forms_tests/tests/test_forms.py | 6 ++---
tests/forms_tests/tests/test_formsets.py | 2 +-
tests/forms_tests/tests/test_widgets.py | 8 +++----
tests/proxy_models/tests.py | 2 +-
tests/schema/tests.py | 4 ++--
tests/servers/views.py | 4 ++--
tests/syndication/tests.py | 2 +-
tests/template_tests/templatetags/custom.py | 28 +++++++++++-----------
tests/template_tests/tests.py | 2 +-
75 files changed, 165 insertions(+), 165 deletions(-)
diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py
index 3a37de2..2a9fb2a 100644
|
a
|
b
|
FieldListFilter.register(lambda f: bool(f.choices), ChoicesFieldListFilter)
|
| 287 | 287 | class DateFieldListFilter(FieldListFilter): |
| 288 | 288 | def __init__(self, field, request, params, model, model_admin, field_path): |
| 289 | 289 | self.field_generic = '%s__' % field_path |
| 290 | | self.date_params = dict([(k, v) for k, v in params.items() |
| 291 | | if k.startswith(self.field_generic)]) |
| | 290 | self.date_params = dict((k, v) for k, v in params.items() |
| | 291 | if k.startswith(self.field_generic)) |
| 292 | 292 | |
| 293 | 293 | now = timezone.now() |
| 294 | 294 | # When time zone support is enabled, convert "now" to the user's time |
-
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index b6d5bde..af1df5e 100644
|
a
|
b
|
class Fieldline(object):
|
| 112 | 112 | yield AdminField(self.form, field, is_first=(i == 0)) |
| 113 | 113 | |
| 114 | 114 | def errors(self): |
| 115 | | return mark_safe('\n'.join([self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields]).strip('\n')) |
| | 115 | return mark_safe('\n'.join(self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields).strip('\n')) |
| 116 | 116 | |
| 117 | 117 | class AdminField(object): |
| 118 | 118 | def __init__(self, form, field, is_first): |
-
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8058683..d435675 100644
|
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
| 698 | 698 | # Avoid trying to iterate over None |
| 699 | 699 | if not class_actions: |
| 700 | 700 | continue |
| 701 | | actions.extend([self.get_action(action) for action in class_actions]) |
| | 701 | actions.extend(self.get_action(action) for action in class_actions) |
| 702 | 702 | |
| 703 | 703 | # get_action might have returned None, so filter any of those out. |
| 704 | 704 | actions = filter(None, actions) |
| 705 | 705 | |
| 706 | 706 | # Convert the actions into an OrderedDict keyed by name. |
| 707 | | actions = OrderedDict([ |
| | 707 | actions = OrderedDict( |
| 708 | 708 | (name, (func, name, desc)) |
| 709 | 709 | for func, name, desc in actions |
| 710 | | ]) |
| | 710 | ) |
| 711 | 711 | |
| 712 | 712 | return actions |
| 713 | 713 | |
-
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index 5773db6..e5b590e 100644
|
a
|
b
|
def url_params_from_lookup_dict(lookups):
|
| 119 | 119 | if callable(v): |
| 120 | 120 | v = v() |
| 121 | 121 | if isinstance(v, (tuple, list)): |
| 122 | | v = ','.join([str(x) for x in v]) |
| | 122 | v = ','.join(str(x) for x in v) |
| 123 | 123 | elif isinstance(v, bool): |
| 124 | 124 | # See django.db.fields.BooleanField.get_prep_lookup |
| 125 | 125 | v = ('0', '1')[v] |
| … |
… |
class ForeignKeyRawIdWidget(forms.TextInput):
|
| 154 | 154 | |
| 155 | 155 | params = self.url_parameters() |
| 156 | 156 | if params: |
| 157 | | url = '?' + '&'.join(['%s=%s' % (k, v) for k, v in params.items()]) |
| | 157 | url = '?' + '&'.join('%s=%s' % (k, v) for k, v in params.items()) |
| 158 | 158 | else: |
| 159 | 159 | url = '' |
| 160 | 160 | if "class" not in attrs: |
| … |
… |
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
| 199 | 199 | # The related object is registered with the same AdminSite |
| 200 | 200 | attrs['class'] = 'vManyToManyRawIdAdminField' |
| 201 | 201 | if value: |
| 202 | | value = ','.join([force_text(v) for v in value]) |
| | 202 | value = ','.join(force_text(v) for v in value) |
| 203 | 203 | else: |
| 204 | 204 | value = '' |
| 205 | 205 | return super(ManyToManyRawIdWidget, self).render(name, value, attrs) |
-
diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py
index 9be0093..c97d588 100644
|
a
|
b
|
def trim_docstring(docstring):
|
| 26 | 26 | return '' |
| 27 | 27 | # Convert tabs to spaces and split into lines |
| 28 | 28 | lines = docstring.expandtabs().splitlines() |
| 29 | | indent = min([len(line) - len(line.lstrip()) for line in lines if line.lstrip()]) |
| | 29 | indent = min(len(line) - len(line.lstrip()) for line in lines if line.lstrip()) |
| 30 | 30 | trimmed = [lines[0].lstrip()] + [line[indent:].rstrip() for line in lines[1:]] |
| 31 | 31 | return "\n".join(trimmed).strip() |
| 32 | 32 | |
-
diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
index cb79291..7304ccd 100644
|
a
|
b
|
class ModelBackend(object):
|
| 36 | 36 | user_groups_query = 'group__%s' % user_groups_field.related_query_name() |
| 37 | 37 | perms = Permission.objects.filter(**{user_groups_query: user_obj}) |
| 38 | 38 | perms = perms.values_list('content_type__app_label', 'codename').order_by() |
| 39 | | user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms]) |
| | 39 | user_obj._group_perm_cache = set("%s.%s" % (ct, name) for ct, name in perms) |
| 40 | 40 | return user_obj._group_perm_cache |
| 41 | 41 | |
| 42 | 42 | def get_all_permissions(self, user_obj, obj=None): |
| 43 | 43 | if user_obj.is_anonymous() or obj is not None: |
| 44 | 44 | return set() |
| 45 | 45 | if not hasattr(user_obj, '_perm_cache'): |
| 46 | | user_obj._perm_cache = set(["%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()]) |
| | 46 | user_obj._perm_cache = set("%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()) |
| 47 | 47 | user_obj._perm_cache.update(self.get_group_permissions(user_obj)) |
| 48 | 48 | return user_obj._perm_cache |
| 49 | 49 | |
-
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 3eba8ab..474bade 100644
|
a
|
b
|
class PasswordChangeForm(SetPasswordForm):
|
| 330 | 330 | ) |
| 331 | 331 | return old_password |
| 332 | 332 | |
| 333 | | PasswordChangeForm.base_fields = OrderedDict([ |
| | 333 | PasswordChangeForm.base_fields = OrderedDict( |
| 334 | 334 | (k, PasswordChangeForm.base_fields[k]) |
| 335 | 335 | for k in ['old_password', 'new_password1', 'new_password2'] |
| 336 | | ]) |
| | 336 | ) |
| 337 | 337 | |
| 338 | 338 | |
| 339 | 339 | class AdminPasswordChangeForm(forms.Form): |
-
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index 4278bbd..3d2fc4b 100644
|
a
|
b
|
def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
|
| 58 | 58 | # Confirm that the content type is stale before deletion. |
| 59 | 59 | if to_remove: |
| 60 | 60 | if kwargs.get('interactive', False): |
| 61 | | content_type_display = '\n'.join([ |
| | 61 | content_type_display = '\n'.join( |
| 62 | 62 | ' %s | %s' % (ct.app_label, ct.model) |
| 63 | 63 | for ct in to_remove |
| 64 | | ]) |
| | 64 | ) |
| 65 | 65 | ok_to_delete = input("""The following content types are stale and need to be deleted: |
| 66 | 66 | |
| 67 | 67 | %s |
-
diff --git a/django/contrib/gis/db/models/sql/aggregates.py b/django/contrib/gis/db/models/sql/aggregates.py
index ae848c0..a3a8f12 100644
|
a
|
b
|
class GeoAggregate(Aggregate):
|
| 32 | 32 | if hasattr(self.col, 'as_sql'): |
| 33 | 33 | field_name, params = self.col.as_sql(qn, connection) |
| 34 | 34 | elif isinstance(self.col, (list, tuple)): |
| 35 | | field_name = '.'.join([qn(c) for c in self.col]) |
| | 35 | field_name = '.'.join(qn(c) for c in self.col) |
| 36 | 36 | else: |
| 37 | 37 | field_name = self.col |
| 38 | 38 | |
-
diff --git a/django/contrib/gis/feeds.py b/django/contrib/gis/feeds.py
index d7c52bf..89bc8c5 100644
|
a
|
b
|
class GeoFeedMixin(object):
|
| 15 | 15 | a single white space. Given a tuple of coordinates, this will return |
| 16 | 16 | a unicode GeoRSS representation. |
| 17 | 17 | """ |
| 18 | | return ' '.join(['%f %f' % (coord[1], coord[0]) for coord in coords]) |
| | 18 | return ' '.join('%f %f' % (coord[1], coord[0]) for coord in coords) |
| 19 | 19 | |
| 20 | 20 | def add_georss_point(self, handler, coords, w3c_geo=False): |
| 21 | 21 | """ |
-
diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py
index c5a87f4..6f8c830 100644
|
a
|
b
|
class LineString(OGRGeometry):
|
| 575 | 575 | @property |
| 576 | 576 | def tuple(self): |
| 577 | 577 | "Returns the tuple representation of this LineString." |
| 578 | | return tuple([self[i] for i in xrange(len(self))]) |
| | 578 | return tuple(self[i] for i in xrange(len(self))) |
| 579 | 579 | coords = tuple |
| 580 | 580 | |
| 581 | 581 | def _listarr(self, func): |
| … |
… |
class Polygon(OGRGeometry):
|
| 632 | 632 | @property |
| 633 | 633 | def tuple(self): |
| 634 | 634 | "Returns a tuple of LinearRing coordinate tuples." |
| 635 | | return tuple([self[i].tuple for i in xrange(self.geom_count)]) |
| | 635 | return tuple(self[i].tuple for i in xrange(self.geom_count)) |
| 636 | 636 | coords = tuple |
| 637 | 637 | |
| 638 | 638 | @property |
| 639 | 639 | def point_count(self): |
| 640 | 640 | "The number of Points in this Polygon." |
| 641 | 641 | # Summing up the number of points in each ring of the Polygon. |
| 642 | | return sum([self[i].point_count for i in xrange(self.geom_count)]) |
| | 642 | return sum(self[i].point_count for i in xrange(self.geom_count)) |
| 643 | 643 | |
| 644 | 644 | @property |
| 645 | 645 | def centroid(self): |
| … |
… |
class GeometryCollection(OGRGeometry):
|
| 686 | 686 | def point_count(self): |
| 687 | 687 | "The number of Points in this Geometry Collection." |
| 688 | 688 | # Summing up the number of points in each geometry in this collection |
| 689 | | return sum([self[i].point_count for i in xrange(self.geom_count)]) |
| | 689 | return sum(self[i].point_count for i in xrange(self.geom_count)) |
| 690 | 690 | |
| 691 | 691 | @property |
| 692 | 692 | def tuple(self): |
| 693 | 693 | "Returns a tuple representation of this Geometry Collection." |
| 694 | | return tuple([self[i].tuple for i in xrange(self.geom_count)]) |
| | 694 | return tuple(self[i].tuple for i in xrange(self.geom_count)) |
| 695 | 695 | coords = tuple |
| 696 | 696 | |
| 697 | 697 | # Multiple Geometry types. |
-
diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py
index 83153f8..70cb4e1 100644
|
a
|
b
|
class GeometryCollection(GEOSGeometry):
|
| 82 | 82 | @property |
| 83 | 83 | def kml(self): |
| 84 | 84 | "Returns the KML for this Geometry Collection." |
| 85 | | return '<MultiGeometry>%s</MultiGeometry>' % ''.join([g.kml for g in self]) |
| | 85 | return '<MultiGeometry>%s</MultiGeometry>' % ''.join(g.kml for g in self) |
| 86 | 86 | |
| 87 | 87 | @property |
| 88 | 88 | def tuple(self): |
-
diff --git a/django/contrib/gis/geos/coordseq.py b/django/contrib/gis/geos/coordseq.py
index acf34f7..b28fb0c 100644
|
a
|
b
|
class GEOSCoordSeq(GEOSBase):
|
| 147 | 147 | if self.hasz: substr = '%s,%s,%s ' |
| 148 | 148 | else: substr = '%s,%s,0 ' |
| 149 | 149 | return '<coordinates>%s</coordinates>' % \ |
| 150 | | ''.join([substr % self[i] for i in xrange(len(self))]).strip() |
| | 150 | ''.join(substr % self[i] for i in xrange(len(self))).strip() |
| 151 | 151 | |
| 152 | 152 | @property |
| 153 | 153 | def tuple(self): |
| 154 | 154 | "Returns a tuple version of this coordinate sequence." |
| 155 | 155 | n = self.size |
| 156 | 156 | if n == 1: return self[0] |
| 157 | | else: return tuple([self[i] for i in xrange(n)]) |
| | 157 | else: return tuple(self[i] for i in xrange(n)) |
-
diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py
index c50f549..53dfd67 100644
|
a
|
b
|
class Polygon(GEOSGeometry):
|
| 159 | 159 | @property |
| 160 | 160 | def tuple(self): |
| 161 | 161 | "Gets the tuple for each ring in this Polygon." |
| 162 | | return tuple([self[i].tuple for i in xrange(len(self))]) |
| | 162 | return tuple(self[i].tuple for i in xrange(len(self))) |
| 163 | 163 | coords = tuple |
| 164 | 164 | |
| 165 | 165 | @property |
| 166 | 166 | def kml(self): |
| 167 | 167 | "Returns the KML representation of this Polygon." |
| 168 | | inner_kml = ''.join(["<innerBoundaryIs>%s</innerBoundaryIs>" % self[i+1].kml |
| 169 | | for i in xrange(self.num_interior_rings)]) |
| | 168 | inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i+1].kml |
| | 169 | for i in xrange(self.num_interior_rings)) |
| 170 | 170 | return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml) |
-
diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
index 87aba72..f3a96cc 100644
|
a
|
b
|
class GEOSTest(unittest.TestCase, TestDataMixin):
|
| 838 | 838 | # Creating a GeometryCollection WKT string composed of other |
| 839 | 839 | # collections and polygons. |
| 840 | 840 | coll = [mp.wkt for mp in self.geometries.multipolygons if mp.valid] |
| 841 | | coll.extend([mls.wkt for mls in self.geometries.multilinestrings]) |
| 842 | | coll.extend([p.wkt for p in self.geometries.polygons]) |
| 843 | | coll.extend([mp.wkt for mp in self.geometries.multipoints]) |
| | 841 | coll.extend(mls.wkt for mls in self.geometries.multilinestrings) |
| | 842 | coll.extend(p.wkt for p in self.geometries.polygons) |
| | 843 | coll.extend(mp.wkt for mp in self.geometries.multipoints) |
| 844 | 844 | gc_wkt = 'GEOMETRYCOLLECTION(%s)' % ','.join(coll) |
| 845 | 845 | |
| 846 | 846 | # Should construct ok from WKT |
-
diff --git a/django/contrib/gis/management/commands/ogrinspect.py b/django/contrib/gis/management/commands/ogrinspect.py
index 85118e3..1270432 100644
|
a
|
b
|
class Command(LabelCommand):
|
| 113 | 113 | rev_mapping = dict((v, k) for k, v in mapping_dict.items()) |
| 114 | 114 | output.extend(['', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name, |
| 115 | 115 | '%s_mapping = {' % model_name.lower()]) |
| 116 | | output.extend([" '%s' : '%s'," % (rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields]) |
| 117 | | output.extend([" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}']) |
| | 116 | output.extend(" '%s' : '%s'," % (rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields) |
| | 117 | output.extend(" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}') |
| 118 | 118 | return '\n'.join(output) + '\n' |
-
diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py
index ff65626..95cf2c9 100644
|
a
|
b
|
class GoogleMap(object):
|
| 150 | 150 | @property |
| 151 | 151 | def icons(self): |
| 152 | 152 | "Returns a sequence of GIcon objects in this map." |
| 153 | | return set([marker.icon for marker in self.markers if marker.icon]) |
| | 153 | return set(marker.icon for marker in self.markers if marker.icon) |
| 154 | 154 | |
| 155 | 155 | class GoogleMapSet(GoogleMap): |
| 156 | 156 | |
-
diff --git a/django/contrib/gis/maps/google/overlays.py b/django/contrib/gis/maps/google/overlays.py
index b82d967..674f02d 100644
|
a
|
b
|
class GOverlayBase(object):
|
| 61 | 61 | |
| 62 | 62 | def latlng_from_coords(self, coords): |
| 63 | 63 | "Generates a JavaScript array of GLatLng objects for the given coordinates." |
| 64 | | return '[%s]' % ','.join(['new GLatLng(%s,%s)' % (y, x) for x, y in coords]) |
| | 64 | return '[%s]' % ','.join('new GLatLng(%s,%s)' % (y, x) for x, y in coords) |
| 65 | 65 | |
| 66 | 66 | def add_event(self, event): |
| 67 | 67 | "Attaches a GEvent to the overlay object." |
-
diff --git a/django/contrib/gis/tests/geoadmin/tests.py b/django/contrib/gis/tests/geoadmin/tests.py
index 295c1de..ebeb223 100644
|
a
|
b
|
class GeoAdminTest(TestCase):
|
| 23 | 23 | def test_ensure_geographic_media(self): |
| 24 | 24 | geoadmin = admin.site._registry[City] |
| 25 | 25 | admin_js = geoadmin.media.render_js() |
| 26 | | self.assertTrue(any([geoadmin.openlayers_url in js for js in admin_js])) |
| | 26 | self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js)) |
| 27 | 27 | |
| 28 | 28 | def test_olmap_OSM_rendering(self): |
| 29 | 29 | geoadmin = admin.site._registry[City] |
-
diff --git a/django/contrib/gis/tests/geoapp/test_feeds.py b/django/contrib/gis/tests/geoapp/test_feeds.py
index 9c7b572..fac8161 100644
|
a
|
b
|
class GeoFeedTest(TestCase):
|
| 28 | 28 | |
| 29 | 29 | def assertChildNodes(self, elem, expected): |
| 30 | 30 | "Taken from syndication/tests.py." |
| 31 | | actual = set([n.nodeName for n in elem.childNodes]) |
| | 31 | actual = set(n.nodeName for n in elem.childNodes) |
| 32 | 32 | expected = set(expected) |
| 33 | 33 | self.assertEqual(actual, expected) |
| 34 | 34 | |
-
diff --git a/django/contrib/gis/tests/geoapp/test_sitemaps.py b/django/contrib/gis/tests/geoapp/test_sitemaps.py
index bb68039..92d70e1 100644
|
a
|
b
|
class GeoSitemapTest(TestCase):
|
| 32 | 32 | |
| 33 | 33 | def assertChildNodes(self, elem, expected): |
| 34 | 34 | "Taken from syndication/tests.py." |
| 35 | | actual = set([n.nodeName for n in elem.childNodes]) |
| | 35 | actual = set(n.nodeName for n in elem.childNodes) |
| 36 | 36 | expected = set(expected) |
| 37 | 37 | self.assertEqual(actual, expected) |
| 38 | 38 | |
-
diff --git a/django/contrib/gis/utils/wkt.py b/django/contrib/gis/utils/wkt.py
index d60eed3..bd85591 100644
|
a
|
b
|
def precision_wkt(geom, prec):
|
| 30 | 30 | coord_fmt = ' '.join([num_fmt, num_fmt]) |
| 31 | 31 | |
| 32 | 32 | def formatted_coords(coords): |
| 33 | | return ','.join([coord_fmt % c[:2] for c in coords]) |
| | 33 | return ','.join(coord_fmt % c[:2] for c in coords) |
| 34 | 34 | |
| 35 | 35 | def formatted_poly(poly): |
| 36 | | return ','.join(['(%s)' % formatted_coords(r) for r in poly]) |
| | 36 | return ','.join('(%s)' % formatted_coords(r) for r in poly) |
| 37 | 37 | |
| 38 | 38 | def formatted_geom(g): |
| 39 | 39 | gtype = str(g.geom_type).upper() |
| … |
… |
def precision_wkt(geom, prec):
|
| 47 | 47 | elif gtype == 'MULTIPOINT': |
| 48 | 48 | yield formatted_coords(g.coords) |
| 49 | 49 | elif gtype == 'MULTIPOLYGON': |
| 50 | | yield ','.join(['(%s)' % formatted_poly(p) for p in g]) |
| | 50 | yield ','.join('(%s)' % formatted_poly(p) for p in g) |
| 51 | 51 | elif gtype == 'GEOMETRYCOLLECTION': |
| 52 | | yield ','.join([''.join([wkt for wkt in formatted_geom(child)]) for child in g]) |
| | 52 | yield ','.join(''.join(wkt for wkt in formatted_geom(child)) for child in g) |
| 53 | 53 | else: |
| 54 | 54 | raise TypeError |
| 55 | 55 | yield ')' |
| 56 | 56 | |
| 57 | | return ''.join([wkt for wkt in formatted_geom(geom)]) |
| | 57 | return ''.join(wkt for wkt in formatted_geom(geom)) |
-
diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
index 8c394d2..b6c3384 100644
|
a
|
b
|
class MessageDecoder(json.JSONDecoder):
|
| 38 | 38 | return Message(*obj[2:]) |
| 39 | 39 | return [self.process_messages(item) for item in obj] |
| 40 | 40 | if isinstance(obj, dict): |
| 41 | | return dict([(key, self.process_messages(value)) |
| 42 | | for key, value in six.iteritems(obj)]) |
| | 41 | return dict((key, self.process_messages(value)) |
| | 42 | for key, value in six.iteritems(obj)) |
| 43 | 43 | return obj |
| 44 | 44 | |
| 45 | 45 | def decode(self, s, **kwargs): |
-
diff --git a/django/contrib/webdesign/lorem_ipsum.py b/django/contrib/webdesign/lorem_ipsum.py
index 01d8f22..36680c8 100644
|
a
|
b
|
def paragraph():
|
| 62 | 62 | |
| 63 | 63 | The paragraph consists of between 1 and 4 sentences, inclusive. |
| 64 | 64 | """ |
| 65 | | return ' '.join([sentence() for i in range(random.randint(1, 4))]) |
| | 65 | return ' '.join(sentence() for i in range(random.randint(1, 4))) |
| 66 | 66 | |
| 67 | 67 | def paragraphs(count, common=True): |
| 68 | 68 | """ |
-
diff --git a/django/core/cache/utils.py b/django/core/cache/utils.py
index b9806cc..dd9ad4a 100644
|
a
|
b
|
TEMPLATE_FRAGMENT_KEY_TEMPLATE = 'template.cache.%s.%s'
|
| 10 | 10 | def make_template_fragment_key(fragment_name, vary_on=None): |
| 11 | 11 | if vary_on is None: |
| 12 | 12 | vary_on = () |
| 13 | | key = ':'.join([urlquote(var) for var in vary_on]) |
| | 13 | key = ':'.join(urlquote(var) for var in vary_on) |
| 14 | 14 | args = hashlib.md5(force_bytes(key)) |
| 15 | 15 | return TEMPLATE_FRAGMENT_KEY_TEMPLATE % (fragment_name, args.hexdigest()) |
-
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 708cfc2..7a7a7bb 100644
|
a
|
b
|
def get_commands():
|
| 114 | 114 | for app_name in apps: |
| 115 | 115 | try: |
| 116 | 116 | path = find_management_module(app_name) |
| 117 | | _commands.update(dict([(name, app_name) |
| 118 | | for name in find_commands(path)])) |
| | 117 | _commands.update(dict((name, app_name) |
| | 118 | for name in find_commands(path))) |
| 119 | 119 | except ImportError: |
| 120 | 120 | pass # No management module - ignore this app |
| 121 | 121 | |
| … |
… |
class ManagementUtility(object):
|
| 336 | 336 | options = [opt for opt in options if opt[0] not in prev_opts] |
| 337 | 337 | |
| 338 | 338 | # filter options by current input |
| 339 | | options = sorted([(k, v) for k, v in options if k.startswith(curr)]) |
| | 339 | options = sorted((k, v) for k, v in options if k.startswith(curr)) |
| 340 | 340 | for option in options: |
| 341 | 341 | opt_label = option[0] |
| 342 | 342 | # append '=' to options which require args |
-
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index dbec389..9899be7 100644
|
a
|
b
|
class Command(BaseCommand):
|
| 164 | 164 | for app_name, model_list in all_models |
| 165 | 165 | ) |
| 166 | 166 | |
| 167 | | create_models = set([x for x in itertools.chain(*manifest.values())]) |
| | 167 | create_models = set(itertools.chain(*manifest.values())) |
| 168 | 168 | emit_pre_migrate_signal(create_models, self.verbosity, self.interactive, connection.alias) |
| 169 | 169 | |
| 170 | 170 | # Create the tables for each model |
-
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 2e977c0..379def2 100644
|
a
|
b
|
def sql_create(app, style, connection):
|
| 29 | 29 | app_models = models.get_models(app, include_auto_created=True) |
| 30 | 30 | final_output = [] |
| 31 | 31 | tables = connection.introspection.table_names() |
| 32 | | known_models = set([model for model in connection.introspection.installed_models(tables) if model not in app_models]) |
| | 32 | known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models) |
| 33 | 33 | pending_references = {} |
| 34 | 34 | |
| 35 | 35 | for model in app_models: |
-
diff --git a/django/core/management/utils.py b/django/core/management/utils.py
index d1052d5..bc00720 100644
|
a
|
b
|
def handle_extensions(extensions=('html',), ignored=('py',)):
|
| 52 | 52 | for i, ext in enumerate(ext_list): |
| 53 | 53 | if not ext.startswith('.'): |
| 54 | 54 | ext_list[i] = '.%s' % ext_list[i] |
| 55 | | return set([x for x in ext_list if x.strip('.') not in ignored]) |
| | 55 | return set(x for x in ext_list if x.strip('.') not in ignored) |
| 56 | 56 | |
| 57 | 57 | def find_command(cmd, path=None, pathext=None): |
| 58 | 58 | if path is None: |
-
diff --git a/django/core/management/validation.py b/django/core/management/validation.py
index 10f6621..1c23871 100644
|
a
|
b
|
def get_validation_errors(outfile, app=None):
|
| 161 | 161 | for rel_field in f.foreign_related_fields: |
| 162 | 162 | has_unique_field = has_unique_field or rel_field.unique |
| 163 | 163 | if not has_unique_field: |
| 164 | | e.add(opts, "Field combination '%s' under model '%s' must have a unique=True constraint" % (','.join([rel_field.name for rel_field in f.foreign_related_fields]), f.rel.to.__name__)) |
| | 164 | e.add(opts, "Field combination '%s' under model '%s' must have a unique=True constraint" % (','.join(rel_field.name for rel_field in f.foreign_related_fields), f.rel.to.__name__)) |
| 165 | 165 | else: |
| 166 | 166 | if not f.foreign_related_fields[0].unique: |
| 167 | 167 | e.add(opts, "Field '%s' under model '%s' must have a unique=True constraint." % (f.foreign_related_fields[0].name, f.rel.to.__name__)) |
-
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 9e086a4..1422bf7 100644
|
a
|
b
|
class ResolverMatch(object):
|
| 62 | 62 | |
| 63 | 63 | @property |
| 64 | 64 | def view_name(self): |
| 65 | | return ':'.join([ x for x in [ self.namespace, self.url_name ] if x ]) |
| | 65 | return ':'.join(filter(bool, (self.namespace, self.url_name))) |
| 66 | 66 | |
| 67 | 67 | def __getitem__(self, index): |
| 68 | 68 | return (self.func, self.args, self.kwargs)[index] |
| … |
… |
class RegexURLResolver(LocaleRegexProvider):
|
| 274 | 274 | for matches, pat, defaults in pattern.reverse_dict.getlist(name): |
| 275 | 275 | new_matches = [] |
| 276 | 276 | for piece, p_args in parent: |
| 277 | | new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches]) |
| | 277 | new_matches.extend((piece + suffix, p_args + args) for (suffix, args) in matches) |
| 278 | 278 | lookups.appendlist(name, (new_matches, p_pattern + pat, dict(defaults, **pattern.default_kwargs))) |
| 279 | 279 | for namespace, (prefix, sub_pattern) in pattern.namespace_dict.items(): |
| 280 | 280 | namespaces[namespace] = (p_pattern + prefix, sub_pattern) |
| … |
… |
class RegexURLResolver(LocaleRegexProvider):
|
| 321 | 321 | except Resolver404 as e: |
| 322 | 322 | sub_tried = e.args[0].get('tried') |
| 323 | 323 | if sub_tried is not None: |
| 324 | | tried.extend([[pattern] + t for t in sub_tried]) |
| | 324 | tried.extend([pattern] + t for t in sub_tried) |
| 325 | 325 | else: |
| 326 | 326 | tried.append([pattern]) |
| 327 | 327 | else: |
-
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 6274d5b..0c1c329 100644
|
a
|
b
|
class BaseDatabaseIntrospection(object):
|
| 1255 | 1255 | if not router.allow_migrate(self.connection.alias, model): |
| 1256 | 1256 | continue |
| 1257 | 1257 | tables.add(model._meta.db_table) |
| 1258 | | tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many]) |
| | 1258 | tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many) |
| 1259 | 1259 | tables = list(tables) |
| 1260 | 1260 | if only_existing: |
| 1261 | 1261 | existing_tables = self.table_names() |
-
diff --git a/django/db/backends/mysql/compiler.py b/django/db/backends/mysql/compiler.py
index b7d1d7b..ee7fbe2 100644
|
a
|
b
|
class SQLCompiler(compiler.SQLCompiler):
|
| 20 | 20 | def as_subquery_condition(self, alias, columns, qn): |
| 21 | 21 | qn2 = self.connection.ops.quote_name |
| 22 | 22 | sql, params = self.as_sql() |
| 23 | | return '(%s) IN (%s)' % (', '.join(['%s.%s' % (qn(alias), qn2(column)) for column in columns]), sql), params |
| | 23 | return '(%s) IN (%s)' % (', '.join('%s.%s' % (qn(alias), qn2(column)) for column in columns), sql), params |
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler): |
-
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index d7a2905..6e3b8d4 100644
|
a
|
b
|
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
| 54 | 54 | SELECT column_name, numeric_precision, numeric_scale FROM information_schema.columns |
| 55 | 55 | WHERE table_name = %s AND table_schema = DATABASE() |
| 56 | 56 | AND data_type='decimal'""", [table_name]) |
| 57 | | numeric_map = dict([(line[0], tuple([int(n) for n in line[1:]])) for line in cursor.fetchall()]) |
| | 57 | numeric_map = dict((line[0], tuple(int(n) for n in line[1:])) for line in cursor.fetchall()) |
| 58 | 58 | |
| 59 | 59 | cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)) |
| 60 | 60 | return [FieldInfo(*((force_text(line[0]),) |
| … |
… |
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
| 69 | 69 | Returns a dictionary of {field_name: field_index} for the given table. |
| 70 | 70 | Indexes are 0-based. |
| 71 | 71 | """ |
| 72 | | return dict([(d[0], i) for i, d in enumerate(self.get_table_description(cursor, table_name))]) |
| | 72 | return dict((d[0], i) for i, d in enumerate(self.get_table_description(cursor, table_name))) |
| 73 | 73 | |
| 74 | 74 | def get_relations(self, cursor, table_name): |
| 75 | 75 | """ |
-
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index a842199..a6ff26d 100644
|
a
|
b
|
class FormatStylePlaceholderCursor(object):
|
| 860 | 860 | def fetchmany(self, size=None): |
| 861 | 861 | if size is None: |
| 862 | 862 | size = self.arraysize |
| 863 | | return tuple([_rowfactory(r, self.cursor) |
| 864 | | for r in self.cursor.fetchmany(size)]) |
| | 863 | return tuple(_rowfactory(r, self.cursor) |
| | 864 | for r in self.cursor.fetchmany(size)) |
| 865 | 865 | |
| 866 | 866 | def fetchall(self): |
| 867 | | return tuple([_rowfactory(r, self.cursor) |
| 868 | | for r in self.cursor.fetchall()]) |
| | 867 | return tuple(_rowfactory(r, self.cursor) |
| | 868 | for r in self.cursor.fetchall()) |
| 869 | 869 | |
| 870 | 870 | def var(self, *args): |
| 871 | 871 | return VariableWrapper(self.cursor.var(*args)) |
-
diff --git a/django/db/backends/oracle/introspection.py b/django/db/backends/oracle/introspection.py
index 70c38c8..9e6e29d 100644
|
a
|
b
|
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
| 66 | 66 | Returns a dictionary of {field_name: field_index} for the given table. |
| 67 | 67 | Indexes are 0-based. |
| 68 | 68 | """ |
| 69 | | return dict([(d[0], i) for i, d in enumerate(self.get_table_description(cursor, table_name))]) |
| | 69 | return dict((d[0], i) for i, d in enumerate(self.get_table_description(cursor, table_name))) |
| 70 | 70 | |
| 71 | 71 | def get_relations(self, cursor, table_name): |
| 72 | 72 | """ |
-
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index 19bffc7..d5c8d10 100644
|
a
|
b
|
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
| 57 | 57 | field_maps = list(mapping.items()) |
| 58 | 58 | self.execute("INSERT INTO %s (%s) SELECT %s FROM %s;" % ( |
| 59 | 59 | self.quote_name(temp_model._meta.db_table), |
| 60 | | ', '.join([x for x, y in field_maps]), |
| 61 | | ', '.join([y for x, y in field_maps]), |
| | 60 | ', '.join(x for x, y in field_maps), |
| | 61 | ', '.join(y for x, y in field_maps), |
| 62 | 62 | self.quote_name(model._meta.db_table), |
| 63 | 63 | )) |
| 64 | 64 | # Delete the old table |
-
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 334c26d..294f801 100644
|
a
|
b
|
class MigrationAutodetector(object):
|
| 145 | 145 | old_model_state = self.from_state.models[app_label, model_name] |
| 146 | 146 | new_model_state = self.to_state.models[app_label, model_name] |
| 147 | 147 | # New fields |
| 148 | | old_field_names = set([x for x, y in old_model_state.fields]) |
| 149 | | new_field_names = set([x for x, y in new_model_state.fields]) |
| | 148 | old_field_names = set(x for x, y in old_model_state.fields) |
| | 149 | new_field_names = set(x for x, y in new_model_state.fields) |
| 150 | 150 | for field_name in new_field_names - old_field_names: |
| 151 | 151 | field = new_model_state.get_field_by_name(field_name) |
| 152 | 152 | # Scan to see if this is actually a rename! |
-
diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py
index 753aeac..75a44a8 100644
|
a
|
b
|
class MigrationWriter(object):
|
| 104 | 104 | imports.update(k_imports) |
| 105 | 105 | imports.update(v_imports) |
| 106 | 106 | strings.append((k_string, v_string)) |
| 107 | | return "{%s}" % (", ".join(["%s: %s" % (k, v) for k, v in strings])), imports |
| | 107 | return "{%s}" % (", ".join("%s: %s" % (k, v) for k, v in strings)), imports |
| 108 | 108 | # Datetimes |
| 109 | 109 | elif isinstance(value, (datetime.datetime, datetime.date)): |
| 110 | 110 | return repr(value), set(["import datetime"]) |
-
diff --git a/django/db/models/base.py b/django/db/models/base.py
index d63017c..aaf525f 100644
|
a
|
b
|
class ModelBase(type):
|
| 159 | 159 | new_fields = new_class._meta.local_fields + \ |
| 160 | 160 | new_class._meta.local_many_to_many + \ |
| 161 | 161 | new_class._meta.virtual_fields |
| 162 | | field_names = set([f.name for f in new_fields]) |
| | 162 | field_names = set(f.name for f in new_fields) |
| 163 | 163 | |
| 164 | 164 | # Basic setup for proxy models. |
| 165 | 165 | if is_proxy: |
| … |
… |
class ModelBase(type):
|
| 321 | 321 | |
| 322 | 322 | # Give the class a docstring -- its definition. |
| 323 | 323 | if cls.__doc__ is None: |
| 324 | | cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields])) |
| | 324 | cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join(f.attname for f in opts.fields)) |
| 325 | 325 | |
| 326 | 326 | if hasattr(cls, 'get_absolute_url'): |
| 327 | 327 | cls.get_absolute_url = update_wrapper(curry(get_absolute_url, opts, cls.get_absolute_url), |
-
diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
index f4c64f7..769e5b9 100644
|
a
|
b
|
class Collector(object):
|
| 234 | 234 | found = True |
| 235 | 235 | if not found: |
| 236 | 236 | return |
| 237 | | self.data = OrderedDict([(model, self.data[model]) |
| 238 | | for model in sorted_models]) |
| | 237 | self.data = OrderedDict((model, self.data[model]) |
| | 238 | for model in sorted_models) |
| 239 | 239 | |
| 240 | 240 | def delete(self): |
| 241 | 241 | # sort instance collections |
-
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 14f73c3..fbbddff 100644
|
a
|
b
|
class Options(object):
|
| 318 | 318 | cache.append((field, model)) |
| 319 | 319 | else: |
| 320 | 320 | cache.append((field, parent)) |
| 321 | | cache.extend([(f, None) for f in self.local_fields]) |
| | 321 | cache.extend((f, None) for f in self.local_fields) |
| 322 | 322 | self._field_cache = tuple(cache) |
| 323 | 323 | self._field_name_cache = [x for x, _ in cache] |
| 324 | 324 | |
-
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 5947a85..5fb7ede 100644
|
a
|
b
|
class ValuesListQuerySet(ValuesQuerySet):
|
| 1206 | 1206 | |
| 1207 | 1207 | for row in self.query.get_compiler(self.db).results_iter(): |
| 1208 | 1208 | data = dict(zip(names, row)) |
| 1209 | | yield tuple([data[f] for f in fields]) |
| | 1209 | yield tuple(data[f] for f in fields) |
| 1210 | 1210 | |
| 1211 | 1211 | def _clone(self, *args, **kwargs): |
| 1212 | 1212 | clone = super(ValuesListQuerySet, self)._clone(*args, **kwargs) |
-
diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py
index 9fc5fe8..3cda4d2 100644
|
a
|
b
|
class Aggregate(object):
|
| 77 | 77 | if hasattr(self.col, 'as_sql'): |
| 78 | 78 | field_name, params = self.col.as_sql(qn, connection) |
| 79 | 79 | elif isinstance(self.col, (list, tuple)): |
| 80 | | field_name = '.'.join([qn(c) for c in self.col]) |
| | 80 | field_name = '.'.join(qn(c) for c in self.col) |
| 81 | 81 | else: |
| 82 | 82 | field_name = self.col |
| 83 | 83 | |
-
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 5dda379..1c6e80b 100644
|
a
|
b
|
class SQLCompiler(object):
|
| 718 | 718 | loaded_fields = self.query.get_loaded_field_names().get(self.query.model, set()) or self.query.select |
| 719 | 719 | aggregate_start = len(self.query.extra_select) + len(loaded_fields) |
| 720 | 720 | aggregate_end = aggregate_start + len(self.query.aggregate_select) |
| 721 | | row = tuple(row[:aggregate_start]) + tuple([ |
| | 721 | row = tuple(row[:aggregate_start]) + tuple( |
| 722 | 722 | self.query.resolve_aggregate(value, aggregate, self.connection) |
| 723 | 723 | for (alias, aggregate), value |
| 724 | 724 | in zip(self.query.aggregate_select.items(), row[aggregate_start:aggregate_end]) |
| 725 | | ]) + tuple(row[aggregate_end:]) |
| | 725 | ) + tuple(row[aggregate_end:]) |
| 726 | 726 | |
| 727 | 727 | yield row |
| 728 | 728 | |
| … |
… |
class SQLInsertCompiler(SQLCompiler):
|
| 827 | 827 | |
| 828 | 828 | has_fields = bool(self.query.fields) |
| 829 | 829 | fields = self.query.fields if has_fields else [opts.pk] |
| 830 | | result.append('(%s)' % ', '.join([qn(f.column) for f in fields])) |
| | 830 | result.append('(%s)' % ', '.join(qn(f.column) for f in fields)) |
| 831 | 831 | |
| 832 | 832 | if has_fields: |
| 833 | 833 | params = values = [ |
| … |
… |
class SQLUpdateCompiler(SQLCompiler):
|
| 1007 | 1007 | # selecting from the updating table (e.g. MySQL). |
| 1008 | 1008 | idents = [] |
| 1009 | 1009 | for rows in query.get_compiler(self.using).execute_sql(MULTI): |
| 1010 | | idents.extend([r[0] for r in rows]) |
| | 1010 | idents.extend(r[0] for r in rows) |
| 1011 | 1011 | self.query.add_filter(('pk__in', idents)) |
| 1012 | 1012 | self.query.related_ids = idents |
| 1013 | 1013 | else: |
-
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index ae67b6f..d8f2a8a 100644
|
a
|
b
|
class Query(object):
|
| 371 | 371 | if result is None: |
| 372 | 372 | result = [None for q in query.aggregate_select.items()] |
| 373 | 373 | |
| 374 | | return dict([ |
| | 374 | return dict( |
| 375 | 375 | (alias, self.resolve_aggregate(val, aggregate, connection=connections[using])) |
| 376 | 376 | for (alias, aggregate), val |
| 377 | 377 | in zip(query.aggregate_select.items(), result) |
| 378 | | ]) |
| | 378 | ) |
| 379 | 379 | |
| 380 | 380 | def get_count(self, using): |
| 381 | 381 | """ |
| … |
… |
class Query(object):
|
| 1757 | 1757 | """ |
| 1758 | 1758 | Callback used by get_deferred_field_names(). |
| 1759 | 1759 | """ |
| 1760 | | target[model] = set([f.name for f in fields]) |
| | 1760 | target[model] = set(f.name for f in fields) |
| 1761 | 1761 | |
| 1762 | 1762 | def set_aggregate_mask(self, names): |
| 1763 | 1763 | "Set the mask of aggregates that will actually be returned by the SELECT" |
| … |
… |
class Query(object):
|
| 1792 | 1792 | if self._aggregate_select_cache is not None: |
| 1793 | 1793 | return self._aggregate_select_cache |
| 1794 | 1794 | elif self.aggregate_select_mask is not None: |
| 1795 | | self._aggregate_select_cache = OrderedDict([ |
| | 1795 | self._aggregate_select_cache = OrderedDict( |
| 1796 | 1796 | (k, v) for k, v in self.aggregates.items() |
| 1797 | 1797 | if k in self.aggregate_select_mask |
| 1798 | | ]) |
| | 1798 | ) |
| 1799 | 1799 | return self._aggregate_select_cache |
| 1800 | 1800 | else: |
| 1801 | 1801 | return self.aggregates |
| … |
… |
class Query(object):
|
| 1805 | 1805 | if self._extra_select_cache is not None: |
| 1806 | 1806 | return self._extra_select_cache |
| 1807 | 1807 | elif self.extra_select_mask is not None: |
| 1808 | | self._extra_select_cache = OrderedDict([ |
| | 1808 | self._extra_select_cache = OrderedDict( |
| 1809 | 1809 | (k, v) for k, v in self.extra.items() |
| 1810 | 1810 | if k in self.extra_select_mask |
| 1811 | | ]) |
| | 1811 | ) |
| 1812 | 1812 | return self._extra_select_cache |
| 1813 | 1813 | else: |
| 1814 | 1814 | return self.extra |
-
diff --git a/django/forms/fields.py b/django/forms/fields.py
index e995187..8abb1b3 100644
|
a
|
b
|
class MultipleChoiceField(ChoiceField):
|
| 874 | 874 | data = [] |
| 875 | 875 | if len(initial) != len(data): |
| 876 | 876 | return True |
| 877 | | initial_set = set([force_text(value) for value in initial]) |
| 878 | | data_set = set([force_text(value) for value in data]) |
| | 877 | initial_set = set(force_text(value) for value in initial) |
| | 878 | data_set = set(force_text(value) for value in data) |
| 879 | 879 | return data_set != initial_set |
| 880 | 880 | |
| 881 | 881 | |
-
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 8a379ff..e46a440 100644
|
a
|
b
|
class BaseFormSet(object):
|
| 380 | 380 | # XXX: there is no semantic division between forms here, there |
| 381 | 381 | # probably should be. It might make sense to render each form as a |
| 382 | 382 | # table row with each field as a td. |
| 383 | | forms = ' '.join([form.as_table() for form in self]) |
| | 383 | forms = ' '.join(form.as_table() for form in self) |
| 384 | 384 | return mark_safe('\n'.join([six.text_type(self.management_form), forms])) |
| 385 | 385 | |
| 386 | 386 | def as_p(self): |
| 387 | 387 | "Returns this formset rendered as HTML <p>s." |
| 388 | | forms = ' '.join([form.as_p() for form in self]) |
| | 388 | forms = ' '.join(form.as_p() for form in self) |
| 389 | 389 | return mark_safe('\n'.join([six.text_type(self.management_form), forms])) |
| 390 | 390 | |
| 391 | 391 | def as_ul(self): |
| 392 | 392 | "Returns this formset rendered as HTML <li>s." |
| 393 | | forms = ' '.join([form.as_ul() for form in self]) |
| | 393 | forms = ' '.join(form.as_ul() for form in self) |
| 394 | 394 | return mark_safe('\n'.join([six.text_type(self.management_form), forms])) |
| 395 | 395 | |
| 396 | 396 | def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, |
-
diff --git a/django/forms/models.py b/django/forms/models.py
index 9df97d6..f292606 100644
|
a
|
b
|
class ModelMultipleChoiceField(ModelChoiceField):
|
| 1181 | 1181 | params={'pk': pk}, |
| 1182 | 1182 | ) |
| 1183 | 1183 | qs = self.queryset.filter(**{'%s__in' % key: value}) |
| 1184 | | pks = set([force_text(getattr(o, key)) for o in qs]) |
| | 1184 | pks = set(force_text(getattr(o, key)) for o in qs) |
| 1185 | 1185 | for val in value: |
| 1186 | 1186 | if force_text(val) not in pks: |
| 1187 | 1187 | raise ValidationError( |
| … |
… |
class ModelMultipleChoiceField(ModelChoiceField):
|
| 1208 | 1208 | data = [] |
| 1209 | 1209 | if len(initial) != len(data): |
| 1210 | 1210 | return True |
| 1211 | | initial_set = set([force_text(value) for value in self.prepare_value(initial)]) |
| 1212 | | data_set = set([force_text(value) for value in data]) |
| | 1211 | initial_set = set(force_text(value) for value in self.prepare_value(initial)) |
| | 1212 | data_set = set(force_text(value) for value in data) |
| 1213 | 1213 | return data_set != initial_set |
| 1214 | 1214 | |
| 1215 | 1215 | |
-
diff --git a/django/forms/util.py b/django/forms/util.py
index 3c77249..320a74e 100644
|
a
|
b
|
class ErrorDict(dict):
|
| 49 | 49 | )) |
| 50 | 50 | |
| 51 | 51 | def as_text(self): |
| 52 | | return '\n'.join(['* %s\n%s' % (k, '\n'.join([' * %s' % force_text(i) for i in v])) for k, v in self.items()]) |
| | 52 | return '\n'.join('* %s\n%s' % (k, '\n'.join(' * %s' % force_text(i) for i in v)) for k, v in self.items()) |
| 53 | 53 | |
| 54 | 54 | @python_2_unicode_compatible |
| 55 | 55 | class ErrorList(list): |
| … |
… |
class ErrorList(list):
|
| 69 | 69 | |
| 70 | 70 | def as_text(self): |
| 71 | 71 | if not self: return '' |
| 72 | | return '\n'.join(['* %s' % force_text(e) for e in self]) |
| | 72 | return '\n'.join('* %s' % force_text(e) for e in self) |
| 73 | 73 | |
| 74 | 74 | def __repr__(self): |
| 75 | 75 | return repr([force_text(e) for e in self]) |
-
diff --git a/django/template/base.py b/django/template/base.py
index 382b85a..67af5b1 100644
|
a
|
b
|
class VariableDoesNotExist(Exception):
|
| 88 | 88 | self.params = params |
| 89 | 89 | |
| 90 | 90 | def __str__(self): |
| 91 | | return self.msg % tuple([force_text(p, errors='replace') |
| 92 | | for p in self.params]) |
| | 91 | return self.msg % tuple(force_text(p, errors='replace') |
| | 92 | for p in self.params) |
| 93 | 93 | |
| 94 | 94 | class InvalidTemplateLibrary(Exception): |
| 95 | 95 | pass |
| … |
… |
def parse_bits(parser, bits, params, varargs, varkw, defaults,
|
| 1012 | 1012 | # Some positional arguments were not supplied |
| 1013 | 1013 | raise TemplateSyntaxError( |
| 1014 | 1014 | "'%s' did not receive value(s) for the argument(s): %s" % |
| 1015 | | (name, ", ".join(["'%s'" % p for p in unhandled_params]))) |
| | 1015 | (name, ", ".join("'%s'" % p for p in unhandled_params))) |
| 1016 | 1016 | return args, kwargs |
| 1017 | 1017 | |
| 1018 | 1018 | def generic_tag_compiler(parser, token, params, varargs, varkw, defaults, |
-
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 2a3af9b..a7af7d7 100644
|
a
|
b
|
class ForNode(Node):
|
| 205 | 205 | # don't want to leave any vars from the previous loop on the |
| 206 | 206 | # context. |
| 207 | 207 | context.pop() |
| 208 | | return mark_safe(''.join([force_text(n) for n in nodelist])) |
| | 208 | return mark_safe(''.join(force_text(n) for n in nodelist)) |
| 209 | 209 | |
| 210 | 210 | class IfChangedNode(Node): |
| 211 | 211 | child_nodelists = ('nodelist_true', 'nodelist_false') |
| … |
… |
class URLNode(Node):
|
| 410 | 410 | def render(self, context): |
| 411 | 411 | from django.core.urlresolvers import reverse, NoReverseMatch |
| 412 | 412 | args = [arg.resolve(context) for arg in self.args] |
| 413 | | kwargs = dict([(smart_text(k, 'ascii'), v.resolve(context)) |
| 414 | | for k, v in self.kwargs.items()]) |
| | 413 | kwargs = dict((smart_text(k, 'ascii'), v.resolve(context)) |
| | 414 | for k, v in self.kwargs.items()) |
| 415 | 415 | |
| 416 | 416 | view_name = self.view_name.resolve(context) |
| 417 | 417 | |
| … |
… |
class WithNode(Node):
|
| 502 | 502 | return "<WithNode>" |
| 503 | 503 | |
| 504 | 504 | def render(self, context): |
| 505 | | values = dict([(key, val.resolve(context)) for key, val in |
| 506 | | six.iteritems(self.extra_context)]) |
| | 505 | values = dict((key, val.resolve(context)) for key, val in |
| | 506 | six.iteritems(self.extra_context)) |
| 507 | 507 | with context.push(**values): |
| 508 | 508 | return self.nodelist.render(context) |
| 509 | 509 | |
-
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index d7908ac..d104d69 100644
|
a
|
b
|
class ExtendsNode(Node):
|
| 112 | 112 | # The ExtendsNode has to be the first non-text node. |
| 113 | 113 | if not isinstance(node, TextNode): |
| 114 | 114 | if not isinstance(node, ExtendsNode): |
| 115 | | blocks = dict([(n.name, n) for n in |
| 116 | | compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) |
| | 115 | blocks = dict((n.name, n) for n in |
| | 116 | compiled_parent.nodelist.get_nodes_by_type(BlockNode)) |
| 117 | 117 | block_context.add_blocks(blocks) |
| 118 | 118 | break |
| 119 | 119 | |
| … |
… |
class BaseIncludeNode(Node):
|
| 128 | 128 | super(BaseIncludeNode, self).__init__(*args, **kwargs) |
| 129 | 129 | |
| 130 | 130 | def render_template(self, template, context): |
| 131 | | values = dict([(name, var.resolve(context)) for name, var |
| 132 | | in six.iteritems(self.extra_context)]) |
| | 131 | values = dict((name, var.resolve(context)) for name, var |
| | 132 | in six.iteritems(self.extra_context)) |
| 133 | 133 | if self.isolated_context: |
| 134 | 134 | return template.render(context.new(values)) |
| 135 | 135 | with context.push(**values): |
-
diff --git a/django/test/_doctest.py b/django/test/_doctest.py
index 50d772c..6e8662a 100644
|
a
|
b
|
class DocTestParser:
|
| 598 | 598 | # If all lines begin with the same indentation, then strip it. |
| 599 | 599 | min_indent = self._min_indent(string) |
| 600 | 600 | if min_indent > 0: |
| 601 | | string = '\n'.join([l[min_indent:] for l in string.split('\n')]) |
| | 601 | string = '\n'.join(l[min_indent:] for l in string.split('\n')) |
| 602 | 602 | |
| 603 | 603 | output = [] |
| 604 | 604 | charno, lineno = 0, 0 |
| … |
… |
class DocTestParser:
|
| 670 | 670 | source_lines = m.group('source').split('\n') |
| 671 | 671 | self._check_prompt_blank(source_lines, indent, name, lineno) |
| 672 | 672 | self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno) |
| 673 | | source = '\n'.join([sl[indent+4:] for sl in source_lines]) |
| | 673 | source = '\n'.join(sl[indent+4:] for sl in source_lines) |
| 674 | 674 | |
| 675 | 675 | # Divide want into lines; check that it's properly indented; and |
| 676 | 676 | # then strip the indentation. Spaces before the last newline should |
| … |
… |
class DocTestParser:
|
| 681 | 681 | del want_lines[-1] # forget final newline & spaces after it |
| 682 | 682 | self._check_prefix(want_lines, ' '*indent, name, |
| 683 | 683 | lineno + len(source_lines)) |
| 684 | | want = '\n'.join([wl[indent:] for wl in want_lines]) |
| | 684 | want = '\n'.join(wl[indent:] for wl in want_lines) |
| 685 | 685 | |
| 686 | 686 | # If `want` contains a traceback message, then extract it. |
| 687 | 687 | m = self._EXCEPTION_RE.match(want) |
-
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 45f93b9..7a77f91 100644
|
a
|
b
|
def patch_cache_control(response, **kwargs):
|
| 76 | 76 | |
| 77 | 77 | for (k, v) in kwargs.items(): |
| 78 | 78 | cc[k.replace('_', '-')] = v |
| 79 | | cc = ', '.join([dictvalue(el) for el in cc.items()]) |
| | 79 | cc = ', '.join(dictvalue(el) for el in cc.items()) |
| 80 | 80 | response['Cache-Control'] = cc |
| 81 | 81 | |
| 82 | 82 | def get_max_age(response): |
| … |
… |
def get_max_age(response):
|
| 86 | 86 | """ |
| 87 | 87 | if not response.has_header('Cache-Control'): |
| 88 | 88 | return |
| 89 | | cc = dict([_to_tuple(el) for el in |
| 90 | | cc_delim_re.split(response['Cache-Control'])]) |
| | 89 | cc = dict(_to_tuple(el) for el in |
| | 90 | cc_delim_re.split(response['Cache-Control'])) |
| 91 | 91 | if 'max-age' in cc: |
| 92 | 92 | try: |
| 93 | 93 | return int(cc['max-age']) |
| … |
… |
def patch_vary_headers(response, newheaders):
|
| 144 | 144 | else: |
| 145 | 145 | vary_headers = [] |
| 146 | 146 | # Use .lower() here so we treat headers as case-insensitive. |
| 147 | | existing_headers = set([header.lower() for header in vary_headers]) |
| | 147 | existing_headers = set(header.lower() for header in vary_headers) |
| 148 | 148 | additional_headers = [newheader for newheader in newheaders |
| 149 | 149 | if newheader.lower() not in existing_headers] |
| 150 | 150 | response['Vary'] = ', '.join(vary_headers + additional_headers) |
| … |
… |
def has_vary_header(response, header_query):
|
| 156 | 156 | if not response.has_header('Vary'): |
| 157 | 157 | return False |
| 158 | 158 | vary_headers = cc_delim_re.split(response['Vary']) |
| 159 | | existing_headers = set([header.lower() for header in vary_headers]) |
| | 159 | existing_headers = set(header.lower() for header in vary_headers) |
| 160 | 160 | return header_query.lower() in existing_headers |
| 161 | 161 | |
| 162 | 162 | def _i18n_cache_key_suffix(request, cache_key): |
-
diff --git a/django/utils/checksums.py b/django/utils/checksums.py
index 8617e22..94c0029 100644
|
a
|
b
|
def luhn(candidate):
|
| 17 | 17 | if not isinstance(candidate, six.string_types): |
| 18 | 18 | candidate = str(candidate) |
| 19 | 19 | try: |
| 20 | | evens = sum([int(c) for c in candidate[-1::-2]]) |
| 21 | | odds = sum([LUHN_ODD_LOOKUP[int(c)] for c in candidate[-2::-2]]) |
| | 20 | evens = sum(int(c) for c in candidate[-1::-2]) |
| | 21 | odds = sum(LUHN_ODD_LOOKUP[int(c)] for c in candidate[-2::-2]) |
| 22 | 22 | return ((evens + odds) % 10 == 0) |
| 23 | 23 | except ValueError: # Raised if an int conversion fails |
| 24 | 24 | return False |
-
diff --git a/django/utils/crypto.py b/django/utils/crypto.py
index 15db972..3c15b8b 100644
|
a
|
b
|
def get_random_string(length=12,
|
| 73 | 73 | time.time(), |
| 74 | 74 | settings.SECRET_KEY)).encode('utf-8') |
| 75 | 75 | ).digest()) |
| 76 | | return ''.join([random.choice(allowed_chars) for i in range(length)]) |
| | 76 | return ''.join(random.choice(allowed_chars) for i in range(length)) |
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | def constant_time_compare(val1, val2): |
-
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 29228bd..f4f694f 100644
|
a
|
b
|
class SortedDict(dict):
|
| 231 | 231 | Replaces the normal dict.__repr__ with a version that returns the keys |
| 232 | 232 | in their sorted order. |
| 233 | 233 | """ |
| 234 | | return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in six.iteritems(self)]) |
| | 234 | return '{%s}' % ', '.join('%r: %r' % (k, v) for k, v in six.iteritems(self)) |
| 235 | 235 | |
| 236 | 236 | def clear(self): |
| 237 | 237 | super(SortedDict, self).clear() |
-
diff --git a/django/utils/html.py b/django/utils/html.py
index 89e790d..46750d9 100644
|
a
|
b
|
simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net
|
| 32 | 32 | simple_email_re = re.compile(r'^\S+@\S+\.\S+$') |
| 33 | 33 | link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+') |
| 34 | 34 | html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) |
| 35 | | hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL) |
| | 35 | hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join(re.escape(x) for x in DOTS), re.DOTALL) |
| 36 | 36 | trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z') |
| 37 | 37 | |
| 38 | 38 | |
| … |
… |
def format_html(format_string, *args, **kwargs):
|
| 81 | 81 | of str.format or % interpolation to build up small HTML fragments. |
| 82 | 82 | """ |
| 83 | 83 | args_safe = map(conditional_escape, args) |
| 84 | | kwargs_safe = dict([(k, conditional_escape(v)) for (k, v) in |
| 85 | | six.iteritems(kwargs)]) |
| | 84 | kwargs_safe = dict((k, conditional_escape(v)) for (k, v) in |
| | 85 | six.iteritems(kwargs)) |
| 86 | 86 | return mark_safe(format_string.format(*args_safe, **kwargs_safe)) |
| 87 | 87 | |
| 88 | 88 | def format_html_join(sep, format_string, args_generator): |
-
diff --git a/django/utils/termcolors.py b/django/utils/termcolors.py
index 95d0d17..8c66e33 100644
|
a
|
b
|
termcolors.py
|
| 5 | 5 | from django.utils import six |
| 6 | 6 | |
| 7 | 7 | color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') |
| 8 | | foreground = dict([(color_names[x], '3%s' % x) for x in range(8)]) |
| 9 | | background = dict([(color_names[x], '4%s' % x) for x in range(8)]) |
| | 8 | foreground = dict((color_names[x], '3%s' % x) for x in range(8)) |
| | 9 | background = dict((color_names[x], '4%s' % x) for x in range(8)) |
| 10 | 10 | |
| 11 | 11 | RESET = '0' |
| 12 | 12 | opt_dict = {'bold': '1', 'underscore': '4', 'blink': '5', 'reverse': '7', 'conceal': '8'} |
-
diff --git a/django/utils/text.py b/django/utils/text.py
index 7bb8e7e..e89f7df 100644
|
a
|
b
|
def get_text_list(list_, last_word=ugettext_lazy('or')):
|
| 238 | 238 | if len(list_) == 1: return force_text(list_[0]) |
| 239 | 239 | return '%s %s %s' % ( |
| 240 | 240 | # Translators: This string is used as a separator between list elements |
| 241 | | _(', ').join([force_text(i) for i in list_][:-1]), |
| | 241 | _(', ').join(force_text(i) for i in list_[:-1]), |
| 242 | 242 | force_text(last_word), force_text(list_[-1])) |
| 243 | 243 | get_text_list = allow_lazy(get_text_list, six.text_type) |
| 244 | 244 | |
-
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index 10a6cd6..ba9baab 100644
|
a
|
b
|
def _string_concat(*strings):
|
| 179 | 179 | Lazy variant of string concatenation, needed for translations that are |
| 180 | 180 | constructed from multiple parts. |
| 181 | 181 | """ |
| 182 | | return ''.join([force_text(s) for s in strings]) |
| | 182 | return ''.join(force_text(s) for s in strings) |
| 183 | 183 | string_concat = lazy(_string_concat, six.text_type) |
| 184 | 184 | |
| 185 | 185 | def get_language_info(lang_code): |
-
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index d6e3f5c..64f9099 100644
|
a
|
b
|
class OracleChecks(unittest.TestCase):
|
| 79 | 79 | # than 4000 chars and read it properly |
| 80 | 80 | c = connection.cursor() |
| 81 | 81 | c.execute('CREATE TABLE ltext ("TEXT" NCLOB)') |
| 82 | | long_str = ''.join([six.text_type(x) for x in xrange(4000)]) |
| | 82 | long_str = ''.join(six.text_type(x) for x in xrange(4000)) |
| 83 | 83 | c.execute('INSERT INTO ltext VALUES (%s)', [long_str]) |
| 84 | 84 | c.execute('SELECT text FROM ltext') |
| 85 | 85 | row = c.fetchone() |
-
diff --git a/tests/file_uploads/views.py b/tests/file_uploads/views.py
index 8d20a9c..1940987 100644
|
a
|
b
|
def file_upload_echo(request):
|
| 89 | 89 | """ |
| 90 | 90 | Simple view to echo back info about uploaded files for tests. |
| 91 | 91 | """ |
| 92 | | r = dict([(k, f.name) for k, f in request.FILES.items()]) |
| | 92 | r = dict((k, f.name) for k, f in request.FILES.items()) |
| 93 | 93 | return HttpResponse(json.dumps(r)) |
| 94 | 94 | |
| 95 | 95 | def file_upload_echo_content(request): |
| 96 | 96 | """ |
| 97 | 97 | Simple view to echo back the content of uploaded files for tests. |
| 98 | 98 | """ |
| 99 | | r = dict([(k, f.read().decode('utf-8')) for k, f in request.FILES.items()]) |
| | 99 | r = dict((k, f.read().decode('utf-8')) for k, f in request.FILES.items()) |
| 100 | 100 | return HttpResponse(json.dumps(r)) |
| 101 | 101 | |
| 102 | 102 | def file_upload_quota(request): |
-
diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py
index f063829..2b1bec1 100644
|
a
|
b
|
class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
|
| 221 | 221 | |
| 222 | 222 | def as_divs(self): |
| 223 | 223 | if not self: return '' |
| 224 | | return mark_safe('<div class="error">%s</div>' % ''.join(['<p>%s</p>' % e for e in self])) |
| | 224 | return mark_safe('<div class="error">%s</div>' % ''.join('<p>%s</p>' % e for e in self)) |
| 225 | 225 | |
| 226 | 226 | # This form should print errors the default way. |
| 227 | 227 | form1 = TestForm({'first_name': 'John'}) |
-
diff --git a/tests/forms_tests/tests/test_extra.py b/tests/forms_tests/tests/test_extra.py
index b86245a..2118668 100644
|
a
|
b
|
class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
|
| 723 | 723 | |
| 724 | 724 | def as_divs(self): |
| 725 | 725 | if not self: return '' |
| 726 | | return '<div class="errorlist">%s</div>' % ''.join(['<div class="error">%s</div>' % force_text(e) for e in self]) |
| | 726 | return '<div class="errorlist">%s</div>' % ''.join('<div class="error">%s</div>' % force_text(e) for e in self) |
| 727 | 727 | |
| 728 | 728 | class CommentForm(Form): |
| 729 | 729 | name = CharField(max_length=50, required=False) |
-
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 1c72d17..06ee321 100644
|
a
|
b
|
class FormsTestCase(TestCase):
|
| 437 | 437 | name = ChoiceField(choices=[('john', 'John'), ('paul', 'Paul'), ('george', 'George'), ('ringo', 'Ringo')], widget=RadioSelect) |
| 438 | 438 | |
| 439 | 439 | f = BeatleForm(auto_id=False) |
| 440 | | self.assertHTMLEqual('\n'.join([str(bf) for bf in f['name']]), """<label><input type="radio" name="name" value="john" /> John</label> |
| | 440 | self.assertHTMLEqual('\n'.join(str(bf) for bf in f['name']), """<label><input type="radio" name="name" value="john" /> John</label> |
| 441 | 441 | <label><input type="radio" name="name" value="paul" /> Paul</label> |
| 442 | 442 | <label><input type="radio" name="name" value="george" /> George</label> |
| 443 | 443 | <label><input type="radio" name="name" value="ringo" /> Ringo</label>""") |
| 444 | | self.assertHTMLEqual('\n'.join(['<div>%s</div>' % bf for bf in f['name']]), """<div><label><input type="radio" name="name" value="john" /> John</label></div> |
| | 444 | self.assertHTMLEqual('\n'.join('<div>%s</div>' % bf for bf in f['name']), """<div><label><input type="radio" name="name" value="john" /> John</label></div> |
| 445 | 445 | <div><label><input type="radio" name="name" value="paul" /> Paul</label></div> |
| 446 | 446 | <div><label><input type="radio" name="name" value="george" /> George</label></div> |
| 447 | 447 | <div><label><input type="radio" name="name" value="ringo" /> Ringo</label></div>""") |
| … |
… |
class FormsTestCase(TestCase):
|
| 452 | 452 | name = CharField() |
| 453 | 453 | |
| 454 | 454 | f = BeatleForm(auto_id=False) |
| 455 | | self.assertHTMLEqual('\n'.join([str(bf) for bf in f['name']]), '<input type="text" name="name" />') |
| | 455 | self.assertHTMLEqual('\n'.join(str(bf) for bf in f['name']), '<input type="text" name="name" />') |
| 456 | 456 | |
| 457 | 457 | def test_forms_with_multiple_choice(self): |
| 458 | 458 | # MultipleChoiceField is a special case, as its data is required to be a list: |
-
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index 41577e6..6372f2a 100644
|
a
|
b
|
class FormsFormsetTestCase(TestCase):
|
| 900 | 900 | } |
| 901 | 901 | formset = AnotherChoiceFormSet(data, auto_id=False, prefix='choices') |
| 902 | 902 | self.assertTrue(formset.is_valid()) |
| 903 | | self.assertTrue(all([form.is_valid_called for form in formset.forms])) |
| | 903 | self.assertTrue(all(form.is_valid_called for form in formset.forms)) |
| 904 | 904 | |
| 905 | 905 | def test_hard_limit_on_instantiated_forms(self): |
| 906 | 906 | """A formset has a hard limit on the number of forms instantiated.""" |
-
diff --git a/tests/forms_tests/tests/test_widgets.py b/tests/forms_tests/tests/test_widgets.py
index 3f11771..7f23b1a 100644
|
a
|
b
|
beatle J R Ringo False""")
|
| 640 | 640 | # You can create your own custom renderers for RadioSelect to use. |
| 641 | 641 | class MyRenderer(RadioFieldRenderer): |
| 642 | 642 | def render(self): |
| 643 | | return '<br />\n'.join([six.text_type(choice) for choice in self]) |
| | 643 | return '<br />\n'.join(six.text_type(choice) for choice in self) |
| 644 | 644 | w = RadioSelect(renderer=MyRenderer) |
| 645 | 645 | self.assertHTMLEqual(w.render('beatle', 'G', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))), """<label><input type="radio" name="beatle" value="J" /> John</label><br /> |
| 646 | 646 | <label><input type="radio" name="beatle" value="P" /> Paul</label><br /> |
| … |
… |
beatle J R Ringo False""")
|
| 835 | 835 | |
| 836 | 836 | def test_subwidget(self): |
| 837 | 837 | # Each subwidget tag gets a separate ID when the widget has an ID specified |
| 838 | | self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" /> |
| | 838 | self.assertHTMLEqual("\n".join(c.tag() for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))), """<input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" /> |
| 839 | 839 | <input type="checkbox" name="letters" value="b" id="abc_1" /> |
| 840 | 840 | <input checked="checked" type="checkbox" name="letters" value="c" id="abc_2" />""") |
| 841 | 841 | |
| 842 | 842 | # Each subwidget tag does not get an ID if the widget does not have an ID specified |
| 843 | | self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple().subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" /> |
| | 843 | self.assertHTMLEqual("\n".join(c.tag() for c in CheckboxSelectMultiple().subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))), """<input checked="checked" type="checkbox" name="letters" value="a" /> |
| 844 | 844 | <input type="checkbox" name="letters" value="b" /> |
| 845 | 845 | <input checked="checked" type="checkbox" name="letters" value="c" />""") |
| 846 | 846 | |
| 847 | 847 | # The id_for_label property of the subwidget should return the ID that is used on the subwidget's tag |
| 848 | | self.assertHTMLEqual("\n".join(['<input type="checkbox" name="letters" value="%s" id="%s" />' % (c.choice_value, c.id_for_label) for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', [], choices=zip(list('abc'), list('ABC')))]), """<input type="checkbox" name="letters" value="a" id="abc_0" /> |
| | 848 | self.assertHTMLEqual("\n".join('<input type="checkbox" name="letters" value="%s" id="%s" />' % (c.choice_value, c.id_for_label) for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', [], choices=zip(list('abc'), list('ABC')))), """<input type="checkbox" name="letters" value="a" id="abc_0" /> |
| 849 | 849 | <input type="checkbox" name="letters" value="b" id="abc_1" /> |
| 850 | 850 | <input type="checkbox" name="letters" value="c" id="abc_2" />""") |
| 851 | 851 | |
-
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index f0c0d04..f9cb132 100644
|
a
|
b
|
class ProxyModelTests(TestCase):
|
| 79 | 79 | Person.objects.create(name="Foo McBar") |
| 80 | 80 | MyPerson.objects.create(name="Bazza del Frob") |
| 81 | 81 | LowerStatusPerson.objects.create(status="low", name="homer") |
| 82 | | pp = sorted([mpp.name for mpp in MyPersonProxy.objects.all()]) |
| | 82 | pp = sorted(mpp.name for mpp in MyPersonProxy.objects.all()) |
| 83 | 83 | self.assertEqual(pp, ['Bazza del Frob', 'Foo McBar', 'homer']) |
| 84 | 84 | |
| 85 | 85 | def test_proxy_included_in_ancestors(self): |
-
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index c376497..7c21b58 100644
|
a
|
b
|
class SchemaTests(TransactionTestCase):
|
| 42 | 42 | "table": connection.ops.quote_name(field.rel.through._meta.db_table), |
| 43 | 43 | }) |
| 44 | 44 | except DatabaseError as e: |
| 45 | | if any([s in str(e).lower() for s in self.no_table_strings]): |
| | 45 | if any(s in str(e).lower() for s in self.no_table_strings): |
| 46 | 46 | pass |
| 47 | 47 | else: |
| 48 | 48 | raise |
| … |
… |
class SchemaTests(TransactionTestCase):
|
| 53 | 53 | "table": connection.ops.quote_name(model._meta.db_table), |
| 54 | 54 | }) |
| 55 | 55 | except DatabaseError as e: |
| 56 | | if any([s in str(e).lower() for s in self.no_table_strings]): |
| | 56 | if any(s in str(e).lower() for s in self.no_table_strings): |
| 57 | 57 | pass |
| 58 | 58 | else: |
| 59 | 59 | raise |
-
diff --git a/tests/servers/views.py b/tests/servers/views.py
index 00baf4b..eb7c6c6 100644
|
a
|
b
|
def example_view(request):
|
| 8 | 8 | |
| 9 | 9 | def model_view(request): |
| 10 | 10 | people = Person.objects.all() |
| 11 | | return HttpResponse('\n'.join([person.name for person in people])) |
| | 11 | return HttpResponse('\n'.join(person.name for person in people)) |
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | def create_model_instance(request): |
| … |
… |
def create_model_instance(request):
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | def environ_view(request): |
| 21 | | return HttpResponse("\n".join(["%s: %r" % (k, v) for k, v in request.environ.items()])) |
| | 21 | return HttpResponse("\n".join("%s: %r" % (k, v) for k, v in request.environ.items())) |
-
diff --git a/tests/syndication/tests.py b/tests/syndication/tests.py
index 8bc6b04..79004aa 100644
|
a
|
b
|
class FeedTestCase(TestCase):
|
| 15 | 15 | fixtures = ['feeddata.json'] |
| 16 | 16 | |
| 17 | 17 | def assertChildNodes(self, elem, expected): |
| 18 | | actual = set([n.nodeName for n in elem.childNodes]) |
| | 18 | actual = set(n.nodeName for n in elem.childNodes) |
| 19 | 19 | expected = set(expected) |
| 20 | 20 | self.assertEqual(actual, expected) |
| 21 | 21 | |
-
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py
index 32035ab..5e96ca8 100644
|
a
|
b
|
simple_one_default.anything = "Expected simple_one_default __dict__"
|
| 64 | 64 | @register.simple_tag |
| 65 | 65 | def simple_unlimited_args(one, two='hi', *args): |
| 66 | 66 | """Expected simple_unlimited_args __doc__""" |
| 67 | | return "simple_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)])) |
| | 67 | return "simple_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args))) |
| 68 | 68 | simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__" |
| 69 | 69 | |
| 70 | 70 | @register.simple_tag |
| 71 | 71 | def simple_only_unlimited_args(*args): |
| 72 | 72 | """Expected simple_only_unlimited_args __doc__""" |
| 73 | | return "simple_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args]) |
| | 73 | return "simple_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args) |
| 74 | 74 | simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dict__" |
| 75 | 75 | |
| 76 | 76 | @register.simple_tag |
| … |
… |
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
| 79 | 79 | # Sort the dictionary by key to guarantee the order for testing. |
| 80 | 80 | sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0)) |
| 81 | 81 | return "simple_unlimited_args_kwargs - Expected result: %s / %s" % ( |
| 82 | | ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]), |
| 83 | | ', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg]) |
| | 82 | ', '.join(six.text_type(arg) for arg in [one, two] + list(args)), |
| | 83 | ', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg) |
| 84 | 84 | ) |
| 85 | 85 | simple_unlimited_args_kwargs.anything = "Expected simple_unlimited_args_kwargs __dict__" |
| 86 | 86 | |
| … |
… |
inclusion_one_default_from_template.anything = "Expected inclusion_one_default_f
|
| 191 | 191 | @register.inclusion_tag('inclusion.html') |
| 192 | 192 | def inclusion_unlimited_args(one, two='hi', *args): |
| 193 | 193 | """Expected inclusion_unlimited_args __doc__""" |
| 194 | | return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))} |
| | 194 | return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))} |
| 195 | 195 | inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__" |
| 196 | 196 | |
| 197 | 197 | @register.inclusion_tag(get_template('inclusion.html')) |
| 198 | 198 | def inclusion_unlimited_args_from_template(one, two='hi', *args): |
| 199 | 199 | """Expected inclusion_unlimited_args_from_template __doc__""" |
| 200 | | return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))} |
| | 200 | return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))} |
| 201 | 201 | inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__" |
| 202 | 202 | |
| 203 | 203 | @register.inclusion_tag('inclusion.html') |
| 204 | 204 | def inclusion_only_unlimited_args(*args): |
| 205 | 205 | """Expected inclusion_only_unlimited_args __doc__""" |
| 206 | | return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))} |
| | 206 | return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))} |
| 207 | 207 | inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__" |
| 208 | 208 | |
| 209 | 209 | @register.inclusion_tag(get_template('inclusion.html')) |
| 210 | 210 | def inclusion_only_unlimited_args_from_template(*args): |
| 211 | 211 | """Expected inclusion_only_unlimited_args_from_template __doc__""" |
| 212 | | return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))} |
| | 212 | return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))} |
| 213 | 213 | inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__" |
| 214 | 214 | |
| 215 | 215 | @register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True) |
| … |
… |
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
| 230 | 230 | # Sort the dictionary by key to guarantee the order for testing. |
| 231 | 231 | sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0)) |
| 232 | 232 | return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % ( |
| 233 | | ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]), |
| 234 | | ', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg]) |
| | 233 | ', '.join(six.text_type(arg) for arg in [one, two] + list(args)), |
| | 234 | ', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg) |
| 235 | 235 | )} |
| 236 | 236 | inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__" |
| 237 | 237 | |
| … |
… |
assignment_one_default.anything = "Expected assignment_one_default __dict__"
|
| 286 | 286 | @register.assignment_tag |
| 287 | 287 | def assignment_unlimited_args(one, two='hi', *args): |
| 288 | 288 | """Expected assignment_unlimited_args __doc__""" |
| 289 | | return "assignment_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)])) |
| | 289 | return "assignment_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args))) |
| 290 | 290 | assignment_unlimited_args.anything = "Expected assignment_unlimited_args __dict__" |
| 291 | 291 | |
| 292 | 292 | @register.assignment_tag |
| 293 | 293 | def assignment_only_unlimited_args(*args): |
| 294 | 294 | """Expected assignment_only_unlimited_args __doc__""" |
| 295 | | return "assignment_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args]) |
| | 295 | return "assignment_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args) |
| 296 | 296 | assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_args __dict__" |
| 297 | 297 | |
| 298 | 298 | @register.assignment_tag |
| … |
… |
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
| 301 | 301 | # Sort the dictionary by key to guarantee the order for testing. |
| 302 | 302 | sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0)) |
| 303 | 303 | return "assignment_unlimited_args_kwargs - Expected result: %s / %s" % ( |
| 304 | | ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]), |
| 305 | | ', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg]) |
| | 304 | ', '.join(six.text_type(arg) for arg in [one, two] + list(args)), |
| | 305 | ', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg) |
| 306 | 306 | ) |
| 307 | 307 | assignment_unlimited_args_kwargs.anything = "Expected assignment_unlimited_args_kwargs __dict__" |
| 308 | 308 | |
-
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index e9c0a0f..2eb1b5e 100644
|
a
|
b
|
class TemplateTests(TransRealMixin, TestCase):
|
| 473 | 473 | template_tests.update(filter_tests) |
| 474 | 474 | |
| 475 | 475 | cache_loader = setup_test_template_loader( |
| 476 | | dict([(name, t[0]) for name, t in six.iteritems(template_tests)]), |
| | 476 | dict((name, t[0]) for name, t in six.iteritems(template_tests)), |
| 477 | 477 | use_cached_loader=True, |
| 478 | 478 | ) |
| 479 | 479 | |