diff --git a/djangorestframework/response.py b/djangorestframework/response.py index 4664e0799..65173200d 100644 --- a/djangorestframework/response.py +++ b/djangorestframework/response.py @@ -11,15 +11,18 @@ by specifying an ``_accept=`` parameter in the URL. Also, `Response` will ignore from Internet Explorer user agents and use a sensible browser `Accept` header instead. """ + +import re from django.template.response import SimpleTemplateResponse from django.core.handlers.wsgi import STATUS_CODE_TEXT - from djangorestframework.settings import api_settings from djangorestframework.utils.mediatypes import order_by_precedence -from djangorestframework.utils import MSIE_USER_AGENT_REGEX from djangorestframework import status +MSIE_USER_AGENT_REGEX = re.compile(r'^Mozilla/[0-9]+\.[0-9]+ \([^)]*; MSIE [0-9]+\.[0-9]+[a-z]?;[^)]*\)(?!.* Opera )') + + class NotAcceptable(Exception): pass diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index ef611a16a..bb5bb6d7e 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -1,6 +1,5 @@ from django.utils.encoding import smart_unicode from django.utils.xmlutils import SimplerXMLGenerator -from django.core.urlresolvers import resolve from djangorestframework.compat import StringIO from djangorestframework.compat import RequestFactory as DjangoRequestFactory @@ -9,38 +8,6 @@ from djangorestframework.request import Request import re import xml.etree.ElementTree as ET -MSIE_USER_AGENT_REGEX = re.compile(r'^Mozilla/[0-9]+\.[0-9]+ \([^)]*; MSIE [0-9]+\.[0-9]+[a-z]?;[^)]*\)(?!.* Opera )') - - -def as_tuple(obj): - """ - Given an object which may be a list/tuple, another object, or None, - return that object in list form. - - IE: - If the object is already a list/tuple just return it. - If the object is not None, return it in a list with a single element. - If the object is None return an empty list. - """ - if obj is None: - return () - elif isinstance(obj, list): - return tuple(obj) - elif isinstance(obj, tuple): - return obj - return (obj,) - - -def url_resolves(url): - """ - Return True if the given URL is mapped to a view in the urlconf, False otherwise. - """ - try: - resolve(url) - except Exception: - return False - return True - # From xml2dict class XML2Dict(object): diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 319ce5f95..84dd3dfa1 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -30,4 +30,3 @@ def get_breadcrumbs(url): return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list) return breadcrumbs_recursive(url, []) -