Ticket #16519: 0001-Fix-16559-Deprecate-mimetype-for-HttpResponse.patch

File 0001-Fix-16559-Deprecate-mimetype-for-HttpResponse.patch, 17.8 KB (added by Yaşar Arabacı, 13 years ago)

Fixed all necessary things, but didn't write tests.

  • django/contrib/gis/shortcuts.py

    From 73292ae949e38451287ce4068f2837cb83f3ec3e Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Ya=C5=9Far=20Arabac=C4=B1?= <yasar11732@gmail.com>
    Date: Fri, 30 Sep 2011 00:47:14 +0300
    Subject: [PATCH] Fix #16559 - Deprecate mimetype for HttpResponse
    
    I interchanged locations of mimetype and content_type
    kwargs. Using mimetype keyword argument now raises a
    DeprecatedWarning. Made required changes around all
    codebase so that content_type is used instead of mimetype
    ---
     django/contrib/gis/shortcuts.py                    |    6 +++---
     django/contrib/gis/sitemaps/views.py               |    4 ++--
     django/contrib/sitemaps/views.py                   |    4 ++--
     django/contrib/syndication/views.py                |    2 +-
     django/http/__init__.py                            |    8 ++++++--
     django/shortcuts/__init__.py                       |    2 +-
     django/template/response.py                        |   13 ++++++-------
     django/views/csrf.py                               |    2 +-
     django/views/debug.py                              |    6 +++---
     django/views/generic/date_based.py                 |   12 ++++++------
     django/views/generic/list_detail.py                |    4 ++--
     django/views/generic/simple.py                     |    2 +-
     django/views/static.py                             |    4 ++--
     tests/regressiontests/csrf_tests/tests.py          |    2 +-
     tests/regressiontests/test_client_regress/views.py |    2 +-
     15 files changed, 38 insertions(+), 35 deletions(-)
    
    diff --git a/django/contrib/gis/shortcuts.py b/django/contrib/gis/shortcuts.py
    index 9a80f4d..8bdafdf 100644
    a b def compress_kml(kml):  
    2020def render_to_kml(*args, **kwargs):
    2121    "Renders the response as KML (using the correct MIME type)."
    2222    return HttpResponse(loader.render_to_string(*args, **kwargs),
    23                         mimetype='application/vnd.google-earth.kml+xml')
     23                        content_type='application/vnd.google-earth.kml+xml')
    2424
    2525def render_to_kmz(*args, **kwargs):
    2626    """
    def render_to_kmz(*args, **kwargs):  
    2828    MIME type).
    2929    """
    3030    return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)),
    31                         mimetype='application/vnd.google-earth.kmz')
     31                        content_type='application/vnd.google-earth.kmz')
    3232
    3333
    3434def render_to_text(*args, **kwargs):
    3535    "Renders the response using the MIME type for plain text."
    3636    return HttpResponse(loader.render_to_string(*args, **kwargs),
    37                         mimetype='text/plain')
     37                        content_type='text/plain')
  • django/contrib/gis/sitemaps/views.py

    diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py
    index e4ac9f7..eb2454c 100644
    a b def index(request, sitemaps):  
    3030            for page in range(2, pages+1):
    3131                sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
    3232    xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
    33     return HttpResponse(xml, mimetype='application/xml')
     33    return HttpResponse(xml, content_type='application/xml')
    3434
    3535def sitemap(request, sitemaps, section=None):
    3636    """
    def sitemap(request, sitemaps, section=None):  
    5858        except PageNotAnInteger:
    5959            raise Http404("No page '%s'" % page)
    6060    xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
    61     return HttpResponse(xml, mimetype='application/xml')
     61    return HttpResponse(xml, content_type='application/xml')
    6262
    6363def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
    6464    """
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index d82146c..b3aaafd 100644
    a b def index(request, sitemaps,  
    2121        if pages > 1:
    2222            for page in range(2, pages+1):
    2323                sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
    24     return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype=mimetype)
     24    return TemplateResponse(request, template_name, {'sitemaps': sites}, content_type=mimetype)
    2525
    2626def sitemap(request, sitemaps, section=None,
    2727        template_name='sitemap.xml', mimetype='application/xml'):
    def sitemap(request, sitemaps, section=None,  
    4343            raise Http404("Page %s empty" % page)
    4444        except PageNotAnInteger:
    4545            raise Http404("No page '%s'" % page)
    46     return TemplateResponse(request, template_name, {'urlset': urls}, mimetype=mimetype)
    47  No newline at end of file
     46    return TemplateResponse(request, template_name, {'urlset': urls}, content_type=mimetype)
  • django/contrib/syndication/views.py

    diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
    index 8e7c1d1..6937a12 100644
    a b class Feed(object):  
    3535        except ObjectDoesNotExist:
    3636            raise Http404('Feed object does not exist.')
    3737        feedgen = self.get_feed(obj, request)
    38         response = HttpResponse(mimetype=feedgen.mime_type)
     38        response = HttpResponse(content_type=feedgen.mime_type)
    3939        feedgen.write(response, 'utf-8')
    4040        return response
    4141
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index c6bf2f1..1f57eb5 100644
    a b import datetime  
    22import os
    33import re
    44import time
     5import warnings
     6
    57from pprint import pformat
    68from urllib import urlencode, quote
    79from urlparse import urljoin
    class HttpResponse(object):  
    532534
    533535    status_code = 200
    534536
    535     def __init__(self, content='', mimetype=None, status=None,
    536             content_type=None):
     537    def __init__(self, content='', content_type=None, status=None,
     538            mimetype=None):
    537539        # _headers is a mapping of the lower-case name to the original case of
    538540        # the header (required for working with legacy systems) and the header
    539541        # value.  Both the name of the header and its value are ASCII strings.
    class HttpResponse(object):  
    541543        self._charset = settings.DEFAULT_CHARSET
    542544        if mimetype:
    543545            content_type = mimetype     # For backwards compatibility
     546            warnings.warn("Using mimetype keyword argument is deprecated, use"
     547                          " content_type instead",DeprecationWarning)
    544548        if not content_type:
    545549            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
    546550                    self._charset)
  • django/shortcuts/__init__.py

    diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
    index 9f97cae..154f224 100644
    a b def render_to_response(*args, **kwargs):  
    1616    Returns a HttpResponse whose content is filled with the result of calling
    1717    django.template.loader.render_to_string() with the passed arguments.
    1818    """
    19     httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
     19    httpresponse_kwargs = {'content_type': kwargs.pop('mimetype', None)}
    2020    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    2121
    2222def render(request, *args, **kwargs):
  • django/template/response.py

    diff --git a/django/template/response.py b/django/template/response.py
    index 990a17b..95aaa54 100644
    a b class DiscardedAttributeError(AttributeError):  
    1313class SimpleTemplateResponse(HttpResponse):
    1414    rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks']
    1515
    16     def __init__(self, template, context=None, mimetype=None, status=None,
    17             content_type=None):
     16    def __init__(self, template, context=None, content_type=None, status=None,
     17                 mimetype=None):
    1818        # It would seem obvious to call these next two members 'template' and
    1919        # 'context', but those names are reserved as part of the test Client
    2020        # API. To avoid the name collision, we use tricky-to-debug problems
    class SimpleTemplateResponse(HttpResponse):  
    2626        # content argument doesn't make sense here because it will be replaced
    2727        # with rendered template so we always pass empty string in order to
    2828        # prevent errors and provide shorter signature.
    29         super(SimpleTemplateResponse, self).__init__('', mimetype, status,
    30                                                      content_type)
     29        super(SimpleTemplateResponse, self).__init__('', content_type, status)
    3130
    3231        # _is_rendered tracks whether the template and context has been baked
    3332        # into a final response.
    class TemplateResponse(SimpleTemplateResponse):  
    149148    rendering_attrs = SimpleTemplateResponse.rendering_attrs + \
    150149        ['_request', '_current_app']
    151150
    152     def __init__(self, request, template, context=None, mimetype=None,
    153             status=None, content_type=None, current_app=None):
     151    def __init__(self, request, template, context=None, content_type=None,
     152            status=None, mimetype=None, current_app=None):
    154153        # self.request gets over-written by django.test.client.Client - and
    155154        # unlike context_data and template_name the _request should not
    156155        # be considered part of the public API.
    class TemplateResponse(SimpleTemplateResponse):  
    159158        # having to avoid needing to create the RequestContext directly
    160159        self._current_app = current_app
    161160        super(TemplateResponse, self).__init__(
    162             template, context, mimetype, status, content_type)
     161            template, context, content_type, status)
    163162
    164163    def resolve_context(self, context):
    165164        """Convert context data into a full RequestContext object
  • django/views/csrf.py

    diff --git a/django/views/csrf.py b/django/views/csrf.py
    index 80cc21d..36e1e01 100644
    a b def csrf_failure(request, reason=""):  
    9999                 'reason': reason,
    100100                 'no_referer': reason == REASON_NO_REFERER
    101101                 })
    102     return HttpResponseForbidden(t.render(c), mimetype='text/html')
     102    return HttpResponseForbidden(t.render(c), content_type='text/html')
  • django/views/debug.py

    diff --git a/django/views/debug.py b/django/views/debug.py
    index 8c77d70..04ff122 100644
    a b def technical_500_response(request, exc_type, exc_value, tb):  
    6060    """
    6161    reporter = ExceptionReporter(request, exc_type, exc_value, tb)
    6262    html = reporter.get_traceback_html()
    63     return HttpResponseServerError(html, mimetype='text/html')
     63    return HttpResponseServerError(html, content_type='text/html')
    6464
    6565# Cache for the default exception reporter filter instance.
    6666default_exception_reporter_filter = None
    def technical_404_response(request, exception):  
    412412        'request': request,
    413413        'settings': get_safe_settings(),
    414414    })
    415     return HttpResponseNotFound(t.render(c), mimetype='text/html')
     415    return HttpResponseNotFound(t.render(c), content_type='text/html')
    416416
    417417def empty_urlconf(request):
    418418    "Create an empty URLconf 404 error response."
    def empty_urlconf(request):  
    420420    c = Context({
    421421        'project_name': settings.SETTINGS_MODULE.split('.')[0]
    422422    })
    423     return HttpResponse(t.render(c), mimetype='text/html')
     423    return HttpResponse(t.render(c), content_type='text/html')
    424424
    425425#
    426426# Templates are embedded in the file so that we know the error handler will
  • django/views/generic/date_based.py

    diff --git a/django/views/generic/date_based.py b/django/views/generic/date_based.py
    index acef71a..a2023b1 100644
    a b def archive_index(request, queryset, date_field, num_latest=15,  
    5353            c[key] = value()
    5454        else:
    5555            c[key] = value
    56     return HttpResponse(t.render(c), mimetype=mimetype)
     56    return HttpResponse(t.render(c), content_type=mimetype)
    5757
    5858def archive_year(request, year, queryset, date_field, template_name=None,
    5959        template_loader=loader, extra_context=None, allow_empty=False,
    def archive_year(request, year, queryset, date_field, template_name=None,  
    101101            c[key] = value()
    102102        else:
    103103            c[key] = value
    104     return HttpResponse(t.render(c), mimetype=mimetype)
     104    return HttpResponse(t.render(c), content_type=mimetype)
    105105
    106106def archive_month(request, year, month, queryset, date_field,
    107107        month_format='%b', template_name=None, template_loader=loader,
    def archive_month(request, year, month, queryset, date_field,  
    181181            c[key] = value()
    182182        else:
    183183            c[key] = value
    184     return HttpResponse(t.render(c), mimetype=mimetype)
     184    return HttpResponse(t.render(c), content_type=mimetype)
    185185
    186186def archive_week(request, year, week, queryset, date_field,
    187187        template_name=None, template_loader=loader,
    def archive_week(request, year, week, queryset, date_field,  
    233233            c[key] = value()
    234234        else:
    235235            c[key] = value
    236     return HttpResponse(t.render(c), mimetype=mimetype)
     236    return HttpResponse(t.render(c), content_type=mimetype)
    237237
    238238def archive_day(request, year, month, day, queryset, date_field,
    239239        month_format='%b', day_format='%d', template_name=None,
    def archive_day(request, year, month, day, queryset, date_field,  
    299299            c[key] = value()
    300300        else:
    301301            c[key] = value
    302     return HttpResponse(t.render(c), mimetype=mimetype)
     302    return HttpResponse(t.render(c), content_type=mimetype)
    303303
    304304def archive_today(request, **kwargs):
    305305    """
    def object_detail(request, year, month, day, queryset, date_field,  
    370370            c[key] = value()
    371371        else:
    372372            c[key] = value
    373     response = HttpResponse(t.render(c), mimetype=mimetype)
     373    response = HttpResponse(t.render(c), content_type=mimetype)
    374374    populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
    375375    return response
  • django/views/generic/list_detail.py

    diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py
    index 22414ae..8f4509c 100644
    a b def object_list(request, queryset, paginate_by=None, page=None,  
    105105        model = queryset.model
    106106        template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
    107107    t = template_loader.get_template(template_name)
    108     return HttpResponse(t.render(c), mimetype=mimetype)
     108    return HttpResponse(t.render(c), content_type=mimetype)
    109109
    110110def object_detail(request, queryset, object_id=None, slug=None,
    111111        slug_field='slug', template_name=None, template_name_field=None,
    def object_detail(request, queryset, object_id=None, slug=None,  
    147147            c[key] = value()
    148148        else:
    149149            c[key] = value
    150     response = HttpResponse(t.render(c), mimetype=mimetype)
     150    response = HttpResponse(t.render(c), content_type=mimetype)
    151151    populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
    152152    return response
  • django/views/generic/simple.py

    diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py
    index 26df504..a63e184 100644
    a b def direct_to_template(request, template, extra_context=None, mimetype=None, **k  
    2525            dictionary[key] = value
    2626    c = RequestContext(request, dictionary)
    2727    t = loader.get_template(template)
    28     return HttpResponse(t.render(c), mimetype=mimetype)
     28    return HttpResponse(t.render(c), content_type=mimetype)
    2929
    3030def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
    3131    """
  • django/views/static.py

    diff --git a/django/views/static.py b/django/views/static.py
    index 387b7da..2e0da33 100644
    a b def serve(request, path, document_root=None, show_indexes=False):  
    5757    mimetype = mimetype or 'application/octet-stream'
    5858    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
    5959                              statobj.st_mtime, statobj.st_size):
    60         return HttpResponseNotModified(mimetype=mimetype)
     60        return HttpResponseNotModified(content_type=mimetype)
    6161    with open(fullpath, 'rb') as f:
    62         response = HttpResponse(f.read(), mimetype=mimetype)
     62        response = HttpResponse(f.read(), content_type=mimetype)
    6363    response["Last-Modified"] = http_date(statobj.st_mtime)
    6464    if stat.S_ISREG(statobj.st_mode):
    6565        response["Content-Length"] = statobj.st_size
  • tests/regressiontests/csrf_tests/tests.py

    diff --git a/tests/regressiontests/csrf_tests/tests.py b/tests/regressiontests/csrf_tests/tests.py
    index c5f9f36..0f72bee 100644
    a b from django.template import RequestContext, Template  
    1313def post_form_response():
    1414    resp = HttpResponse(content=u"""
    1515<html><body><h1>\u00a1Unicode!<form method="post"><input type="text" /></form></body></html>
    16 """, mimetype="text/html")
     16""", content_type="text/html")
    1717    return resp
    1818
    1919def post_form_view(request):
  • tests/regressiontests/test_client_regress/views.py

    diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
    index b398293..f16057b 100644
    a b def return_json_file(request):  
    8484                                cls=DjangoJSONEncoder,
    8585                                ensure_ascii=False)
    8686    response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
    87                             mimetype='application/json; charset=' + charset)
     87                            content_type='application/json; charset=' + charset)
    8888    response['Content-Disposition'] = 'attachment; filename=testfile.json'
    8989    return response
    9090
Back to Top