Ticket #22840: 22840-django-patch-six-integer-types.patch

File 22840-django-patch-six-integer-types.patch, 12.8 KB (added by bowlofkashi, 10 years ago)

Patch for #22840

  • django/contrib/admin/checks.py

    From b054609dbf7c773f4dcbecda078a140764b8a690 Mon Sep 17 00:00:00 2001
    From: bowlofkashi <bowlofkashi@bestmail.us>
    Date: Sat, 21 Jun 2014 15:04:45 -0500
    Subject: [PATCH 1/2] Change occurrences of isinstance(..., int) to
     isinstance(..., six.integer_types)
    
    ---
     django/contrib/admin/checks.py           | 10 +++++-----
     django/contrib/admin/options.py          |  2 +-
     django/contrib/gis/gdal/datasource.py    |  2 +-
     django/contrib/gis/gdal/driver.py        |  2 +-
     django/contrib/gis/gdal/geomtype.py      |  4 ++--
     django/contrib/gis/gdal/srs.py           |  2 +-
     django/contrib/gis/geos/geometry.py      |  2 +-
     django/contrib/gis/utils/layermapping.py |  4 ++--
     django/contrib/gis/utils/wkt.py          |  2 +-
     django/core/checks/messages.py           |  2 +-
     django/db/models/sql/compiler.py         |  2 +-
     django/utils/dictconfig.py               |  2 +-
     django/utils/numberformat.py             |  2 +-
     django/utils/translation/__init__.py     |  2 +-
     django/views/i18n.py                     |  2 +-
     15 files changed, 21 insertions(+), 21 deletions(-)
    
    diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
    index 3350625..04a2c00 100644
    a b class ModelAdminChecks(BaseModelAdminChecks):  
    735735    def _check_list_per_page(self, cls, model):
    736736        """ Check that list_per_page is an integer. """
    737737
    738         if not isinstance(cls.list_per_page, int):
     738        if not isinstance(cls.list_per_page, six.integer_types):
    739739            return must_be('an integer', option='list_per_page', obj=cls, id='admin.E118')
    740740        else:
    741741            return []
    class ModelAdminChecks(BaseModelAdminChecks):  
    743743    def _check_list_max_show_all(self, cls, model):
    744744        """ Check that list_max_show_all is an integer. """
    745745
    746         if not isinstance(cls.list_max_show_all, int):
     746        if not isinstance(cls.list_max_show_all, six.integer_types):
    747747            return must_be('an integer', option='list_max_show_all', obj=cls, id='admin.E119')
    748748        else:
    749749            return []
    class InlineModelAdminChecks(BaseModelAdminChecks):  
    898898    def _check_extra(self, cls):
    899899        """ Check that extra is an integer. """
    900900
    901         if not isinstance(cls.extra, int):
     901        if not isinstance(cls.extra, six.integer_types):
    902902            return must_be('an integer', option='extra', obj=cls, id='admin.E203')
    903903        else:
    904904            return []
    class InlineModelAdminChecks(BaseModelAdminChecks):  
    908908
    909909        if cls.max_num is None:
    910910            return []
    911         elif not isinstance(cls.max_num, int):
     911        elif not isinstance(cls.max_num, six.integer_types):
    912912            return must_be('an integer', option='max_num', obj=cls, id='admin.E204')
    913913        else:
    914914            return []
    class InlineModelAdminChecks(BaseModelAdminChecks):  
    918918
    919919        if cls.min_num is None:
    920920            return []
    921         elif not isinstance(cls.min_num, int):
     921        elif not isinstance(cls.min_num, six.integer_types):
    922922            return must_be('an integer', option='min_num', obj=cls, id='admin.E205')
    923923        else:
    924924            return []
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index e01cdd0..f027373 100644
    a b class ModelAdmin(BaseModelAdmin):  
    993993        a string rather than the usual level number.
    994994        """
    995995
    996         if not isinstance(level, int):
     996        if not isinstance(level, six.integer_types):
    997997            # attempt to get the level if passed a string
    998998            try:
    999999                level = getattr(messages.constants, level.upper())
  • django/contrib/gis/gdal/datasource.py

    diff --git a/django/contrib/gis/gdal/datasource.py b/django/contrib/gis/gdal/datasource.py
    index 864f50a..71b52d7 100644
    a b class DataSource(GDALBase):  
    110110            l = capi.get_layer_by_name(self.ptr, force_bytes(index))
    111111            if not l:
    112112                raise OGRIndexError('invalid OGR Layer name given: "%s"' % index)
    113         elif isinstance(index, int):
     113        elif isinstance(index, six.integer_types):
    114114            if index < 0 or index >= self.layer_count:
    115115                raise OGRIndexError('index out of range')
    116116            l = capi.get_layer(self._ptr, index)
  • django/contrib/gis/gdal/driver.py

    diff --git a/django/contrib/gis/gdal/driver.py b/django/contrib/gis/gdal/driver.py
    index 58f736b..ca2ccde 100644
    a b class Driver(GDALBase):  
    3939
    4040            # Attempting to get the OGR driver by the string name.
    4141            dr = capi.get_driver_by_name(force_bytes(name))
    42         elif isinstance(dr_input, int):
     42        elif isinstance(dr_input, six.integer_types):
    4343            self._register()
    4444            dr = capi.get_driver(dr_input)
    4545        elif isinstance(dr_input, c_void_p):
  • django/contrib/gis/gdal/geomtype.py

    diff --git a/django/contrib/gis/gdal/geomtype.py b/django/contrib/gis/gdal/geomtype.py
    index 1b5e079..d34bc22 100644
    a b class OGRGeomType(object):  
    4141            num = self._str_types.get(type_input, None)
    4242            if num is None:
    4343                raise OGRException('Invalid OGR String Type "%s"' % type_input)
    44         elif isinstance(type_input, int):
     44        elif isinstance(type_input, six.integer_types):
    4545            if type_input not in self._types:
    4646                raise OGRException('Invalid OGR Integer Type: %d' % type_input)
    4747            num = type_input
    class OGRGeomType(object):  
    6464            return self.num == other.num
    6565        elif isinstance(other, six.string_types):
    6666            return self.name.lower() == other.lower()
    67         elif isinstance(other, int):
     67        elif isinstance(other, six.integer_types):
    6868            return self.num == other
    6969        else:
    7070            return False
  • django/contrib/gis/gdal/srs.py

    diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py
    index 65989f5..0316c44 100644
    a b class SpatialReference(GDALBase):  
    138138        The attribute value for the given target node (e.g. 'PROJCS'). The index
    139139        keyword specifies an index of the child node to return.
    140140        """
    141         if not isinstance(target, six.string_types) or not isinstance(index, int):
     141        if not isinstance(target, six.string_types) or not isinstance(index, six.integer_types):
    142142            raise TypeError
    143143        return capi.get_attr_value(self.ptr, force_bytes(target), index)
    144144
  • django/contrib/gis/geos/geometry.py

    diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
    index 3cee800..0d27f34 100644
    a b class GEOSGeometry(GEOSBase, ListMixin):  
    100100    def _post_init(self, srid):
    101101        "Helper routine for performing post-initialization setup."
    102102        # Setting the SRID, if given.
    103         if srid and isinstance(srid, int):
     103        if srid and isinstance(srid, six.integer_types):
    104104            self.srid = srid
    105105
    106106        # Setting the class type (e.g., Point, Polygon, etc.)
  • django/contrib/gis/utils/layermapping.py

    diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py
    index ead2f17..cdce704 100644
    a b class LayerMapping(object):  
    511511
    512512        # Setting the progress interval, if requested.
    513513        if progress:
    514             if progress is True or not isinstance(progress, int):
     514            if progress is True or not isinstance(progress, six.integer_types):
    515515                progress_interval = 1000
    516516            else:
    517517                progress_interval = progress
    class LayerMapping(object):  
    589589            _save = self.transaction_decorator(_save)
    590590
    591591        nfeat = self.layer.num_feat
    592         if step and isinstance(step, int) and step < nfeat:
     592        if step and isinstance(step, six.integer_types) and step < nfeat:
    593593            # Incremental saving is requested at the given interval (step)
    594594            if default_range:
    595595                raise LayerMapError('The `step` keyword may not be used in conjunction with the `fid_range` keyword.')
  • django/contrib/gis/utils/wkt.py

    diff --git a/django/contrib/gis/utils/wkt.py b/django/contrib/gis/utils/wkt.py
    index 65f2082..0457516 100644
    a b def precision_wkt(geom, prec):  
    2121    If the precision is a string, it must be valid Python format string
    2222    (e.g., '%20.7f') -- thus, you should know what you're doing.
    2323    """
    24     if isinstance(prec, int):
     24    if isinstance(prec, six.integer_types):
    2525        num_fmt = '%%.%df' % prec
    2626    elif isinstance(prec, six.string_types):
    2727        num_fmt = prec
  • django/core/checks/messages.py

    diff --git a/django/core/checks/messages.py b/django/core/checks/messages.py
    index 2528d11..c44a42c 100644
    a b CRITICAL = 50  
    1616class CheckMessage(object):
    1717
    1818    def __init__(self, level, msg, hint=None, obj=None, id=None):
    19         assert isinstance(level, int), "The first argument should be level."
     19        assert isinstance(level, six.integer_types), "The first argument should be level."
    2020        self.level = level
    2121        self.msg = msg
    2222        self.hint = hint
  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index 59b31dc..513774f 100644
    a b class SQLCompiler(object):  
    398398            if field == '?':
    399399                result.append(self.connection.ops.random_function_sql())
    400400                continue
    401             if isinstance(field, int):
     401            if isinstance(field, six.integer_types):
    402402                if field < 0:
    403403                    order = desc
    404404                    field = -field
  • django/utils/dictconfig.py

    diff --git a/django/utils/dictconfig.py b/django/utils/dictconfig.py
    index e2c7a43..b84ae1d 100644
    a b try:  
    4848    from logging import _checkLevel
    4949except ImportError:
    5050    def _checkLevel(level):
    51         if isinstance(level, int):
     51        if isinstance(level, six.integer_types):
    5252            rv = level
    5353        elif str(level) == level:
    5454            if level not in logging._levelNames:
  • django/utils/numberformat.py

    diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
    index 6a31237..4fa55f3 100644
    a b def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='',  
    1818    use_grouping = use_grouping or force_grouping
    1919    use_grouping = use_grouping and grouping > 0
    2020    # Make the common case fast
    21     if isinstance(number, int) and not use_grouping and not decimal_pos:
     21    if isinstance(number, six.integer_types) and not use_grouping and not decimal_pos:
    2222        return mark_safe(six.text_type(number))
    2323    # sign
    2424    sign = ''
  • django/utils/translation/__init__.py

    diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
    index 6be6645..0318247 100644
    a b pgettext_lazy = lazy(pgettext, six.text_type)  
    100100
    101101
    102102def lazy_number(func, resultclass, number=None, **kwargs):
    103     if isinstance(number, int):
     103    if isinstance(number, six.integer_types):
    104104        kwargs['number'] = number
    105105        proxy = lazy(func, resultclass)(**kwargs)
    106106    else:
  • django/views/i18n.py

    diff --git a/django/views/i18n.py b/django/views/i18n.py
    index 7724a2e..2f2da91 100644
    a b def get_formats():  
    6262            result[attr] = get_format(attr)
    6363    formats = {}
    6464    for k, v in result.items():
    65         if isinstance(v, (six.string_types, int)):
     65        if isinstance(v, (six.string_types, six.integer_types)):
    6666            formats[k] = smart_text(v)
    6767        elif isinstance(v, (tuple, list)):
    6868            formats[k] = [smart_text(value) for value in v]
  • django/contrib/admin/checks.py

    -- 
    2.0.0
    
    
    From 77174b14f90b765b37e11045882fa6e84830304f Mon Sep 17 00:00:00 2001
    From: bowlofkashi <bowlofkashi@bestmail.us>
    Date: Sat, 21 Jun 2014 15:30:17 -0500
    Subject: [PATCH 2/2] Added missing 'from django.utils import six'
    
    ---
     django/contrib/admin/checks.py | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
    index 04a2c00..6a8684c 100644
    a b from django.db import models  
    99from django.db.models.fields import FieldDoesNotExist
    1010from django.forms.models import BaseModelForm, _get_foreign_key, BaseModelFormSet
    1111
     12from django.utils import six
    1213
    1314def check_admin_app(**kwargs):
    1415    from django.contrib.admin.sites import site
Back to Top