1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

[gsoc2009/http-wsgi-improvements] Clean up imports in django.http and django.http.charsets.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11213 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Chris Cahoon 2009-07-10 21:50:19 +00:00
parent ab67a69ec6
commit c53880e2c1
2 changed files with 7 additions and 7 deletions

View File

@ -13,7 +13,7 @@ except ImportError:
from django.utils.datastructures import MultiValueDict, ImmutableList from django.utils.datastructures import MultiValueDict, ImmutableList
from django.utils.encoding import smart_str, iri_to_uri, force_unicode from django.utils.encoding import smart_str, iri_to_uri, force_unicode
from django.http.multipartparser import MultiPartParser from django.http.multipartparser import MultiPartParser
from django.http.charsets import get_response_encoding, get_codec, UnsupportedCharset from django.http.charsets import *
from django.conf import settings from django.conf import settings
from django.core.files import uploadhandler from django.core.files import uploadhandler
from utils import * from utils import *

View File

@ -5,7 +5,7 @@ import re
from operator import itemgetter from operator import itemgetter
from django.conf import settings from django.conf import settings
CHARSET_CODECS = { _CHARSET_CODECS = {
'437': 'cp437', '437': 'cp437',
'850': 'cp850', '850': 'cp850',
'852': 'cp852', '852': 'cp852',
@ -245,7 +245,7 @@ def get_codec(charset):
codec = None codec = None
if charset: if charset:
try: try:
codec_name = CHARSET_CODECS[charset.strip().lower()] codec_name = _CHARSET_CODECS[charset.strip().lower()]
codec = codecs.lookup(codec_name) codec = codecs.lookup(codec_name)
except LookupError: except LookupError:
# The encoding is not supported in this version of Python. # The encoding is not supported in this version of Python.
@ -255,8 +255,8 @@ def get_codec(charset):
# Returns the key for the maximum value in a dictionary # Returns the key for the maximum value in a dictionary
max_dict_key = lambda l:sorted(l.iteritems(), key=itemgetter(1), reverse=True)[0][0] max_dict_key = lambda l:sorted(l.iteritems(), key=itemgetter(1), reverse=True)[0][0]
CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?') _CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?')
ACCEPT_CHARSET_RE = re.compile('(?P<charset>([\w\d-]+)|(\*))(;q=(?P<q>[01](\.\d{1,3})?))?,?') _ACCEPT_CHARSET_RE = re.compile('(?P<charset>([\w\d-]+)|(\*))(;q=(?P<q>[01](\.\d{1,3})?))?,?')
def get_response_encoding(content_type, accept_charset_header): def get_response_encoding(content_type, accept_charset_header):
""" """
Searches request headers from clients and mimetype settings (which may be set Searches request headers from clients and mimetype settings (which may be set
@ -278,7 +278,7 @@ def get_response_encoding(content_type, accept_charset_header):
codec = None codec = None
# Try to get the codec from a content-type, verify that the charset is valid. # Try to get the codec from a content-type, verify that the charset is valid.
if content_type: if content_type:
match = CONTENT_TYPE_RE.match(content_type) match = _CONTENT_TYPE_RE.match(content_type)
if match: if match:
charset = match.group(1) charset = match.group(1)
codec = get_codec(charset) codec = get_codec(charset)
@ -295,7 +295,7 @@ def get_response_encoding(content_type, accept_charset_header):
# Get list of matches for Accepted-Charsets. # Get list of matches for Accepted-Charsets.
# [{ charset : q }, { charset : q }] # [{ charset : q }, { charset : q }]
match_iterator = ACCEPT_CHARSET_RE.finditer(accept_charset_header) match_iterator = _ACCEPT_CHARSET_RE.finditer(accept_charset_header)
accept_charset = [m.groupdict() for m in match_iterator] accept_charset = [m.groupdict() for m in match_iterator]
# Remove charsets we cannot encode and whose q values are 0 # Remove charsets we cannot encode and whose q values are 0