From cb6aa1035bf900e9f124e91c0521f7081ba105e3 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 31 Aug 2005 16:27:59 +0000 Subject: [PATCH] Fixed #407 -- Code no longer assumes request.META['REMOTE_ADDR'] exists. Thanks, sune.kirkeby@gmail.com git-svn-id: http://code.djangoproject.com/svn/django/trunk@580 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/comments/views/comments.py | 2 +- django/core/handlers/base.py | 4 ++-- django/core/xheaders.py | 2 +- django/middleware/doc.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 8798c05a01..324ba0f0c9 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -204,7 +204,7 @@ def post_comment(request): new_data = request.POST.copy() new_data['content_type_id'] = content_type_id new_data['object_id'] = object_id - new_data['ip_address'] = request.META['REMOTE_ADDR'] + new_data['ip_address'] = request.META.get('REMOTE_ADDR') new_data['is_public'] = comments.IS_PUBLIC in option_list response = HttpResponse() manipulator = PublicCommentManipulator(request.user, diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index c0e22dbb6a..00149ff791 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -79,7 +79,7 @@ class BaseHandler: if DEBUG: return self.get_technical_error_response() else: - subject = 'Database error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) + subject = 'Database error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) message = "%s\n\n%s" % (self._get_traceback(), request) mail_admins(subject, message, fail_silently=True) return self.get_friendly_error_response(request, resolver) @@ -89,7 +89,7 @@ class BaseHandler: if DEBUG: return self.get_technical_error_response() else: - subject = 'Coding error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) + subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) try: request_repr = repr(request) except: diff --git a/django/core/xheaders.py b/django/core/xheaders.py index 80210a25a0..98d2586b75 100644 --- a/django/core/xheaders.py +++ b/django/core/xheaders.py @@ -17,6 +17,6 @@ def populate_xheaders(request, response, package, python_module_name, object_id) within the INTERNAL_IPS setting. """ from django.conf.settings import INTERNAL_IPS - if request.META['REMOTE_ADDR'] in INTERNAL_IPS: + if request.META.get('REMOTE_ADDR') in INTERNAL_IPS: response['X-Object-Type'] = "%s.%s" % (package, python_module_name) response['X-Object-Id'] = str(object_id) diff --git a/django/middleware/doc.py b/django/middleware/doc.py index 8f648e0665..9345dbfcef 100644 --- a/django/middleware/doc.py +++ b/django/middleware/doc.py @@ -12,7 +12,7 @@ class XViewMiddleware: with an x-header indicating the view function. This is used by the documentation module to lookup the view function for an arbitrary page. """ - if request.META['REQUEST_METHOD'] == 'HEAD' and request.META['REMOTE_ADDR'] in settings.INTERNAL_IPS: + if request.META['REQUEST_METHOD'] == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: response = httpwrappers.HttpResponse() response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__) return response