mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Cleanup imports
Mostly adding `from __future__ import unicode_literals` everywhere.
This commit is contained in:
parent
b82227e517
commit
b052c92ac3
|
@ -2,14 +2,11 @@
|
||||||
Provides a set of pluggable authentication policies.
|
Provides a set of pluggable authentication policies.
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from django.utils.encoding import DjangoUnicodeDecodeError
|
from django.utils.encoding import DjangoUnicodeDecodeError
|
||||||
from rest_framework import exceptions, HTTP_HEADER_ENCODING
|
from rest_framework import exceptions, HTTP_HEADER_ENCODING
|
||||||
from rest_framework.compat import CsrfViewMiddleware
|
from rest_framework.compat import CsrfViewMiddleware
|
||||||
from rest_framework.compat import smart_text
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.settings import api_settings
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from rest_framework.compat import six
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ def api_view(http_method_names):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
|
|
||||||
WrappedAPIView = type(
|
WrappedAPIView = type(
|
||||||
'WrappedAPIView',
|
six.PY3 and 'WrappedAPIView' or b'WrappedAPIView',
|
||||||
(APIView,),
|
(APIView,),
|
||||||
{'__doc__': func.__doc__}
|
{'__doc__': func.__doc__}
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ Handled exceptions raised by REST framework.
|
||||||
In addition Django's built in 403 and 404 exceptions are handled.
|
In addition Django's built in 403 and 404 exceptions are handled.
|
||||||
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
|
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from rest_framework.compat import django_filters
|
from rest_framework.compat import django_filters
|
||||||
|
|
||||||
FilterSet = django_filters and django_filters.FilterSet or None
|
FilterSet = django_filters and django_filters.FilterSet or None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Generic views that provide commonly needed behaviour.
|
Generic views that provide commonly needed behaviour.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from rest_framework import views, mixins
|
from rest_framework import views, mixins
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.templatetags.rest_framework import replace_query_param
|
from rest_framework.templatetags.rest_framework import replace_query_param
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ Parsers are used to parse the content of incoming HTTP requests.
|
||||||
They give us a generic way of being able to handle various media types
|
They give us a generic way of being able to handle various media types
|
||||||
on the request, such as form content or json encoded data.
|
on the request, such as form content or json encoded data.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser
|
from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser
|
||||||
from django.http.multipartparser import MultiPartParserError
|
from django.http.multipartparser import MultiPartParserError
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Provides a set of pluggable permission policies.
|
Provides a set of pluggable permission policies.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
|
SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||||
from django.core.urlresolvers import resolve, get_script_prefix
|
from django.core.urlresolvers import resolve, get_script_prefix
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
|
@ -9,7 +9,7 @@ The wrapped request then offers a richer API, in particular :
|
||||||
- full support of PUT method, including support for file uploads
|
- full support of PUT method, including support for file uploads
|
||||||
- form overloading of HTTP method, content type and content
|
- form overloading of HTTP method, content type and content
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.http.multipartparser import parse_header
|
from django.http.multipartparser import parse_header
|
||||||
from rest_framework import HTTP_HEADER_ENCODING
|
from rest_framework import HTTP_HEADER_ENCODING
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.core.handlers.wsgi import STATUS_CODE_TEXT
|
from django.core.handlers.wsgi import STATUS_CODE_TEXT
|
||||||
from django.template.response import SimpleTemplateResponse
|
from django.template.response import SimpleTemplateResponse
|
||||||
|
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Provide reverse functions that return fully qualified URLs
|
Provide reverse functions that return fully qualified URLs
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.core.urlresolvers import reverse as django_reverse
|
from django.core.urlresolvers import reverse as django_reverse
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import lazy
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import types
|
import types
|
||||||
|
|
|
@ -17,6 +17,7 @@ This module provides the `api_setting` object, that is used to access
|
||||||
REST framework settings, checking for user settings first, then falling
|
REST framework settings, checking for user settings first, then falling
|
||||||
back to the defaults.
|
back to the defaults.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import importlib
|
from django.utils import importlib
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
|
|
@ -4,6 +4,7 @@ Descriptive HTTP status codes, for code readability.
|
||||||
See RFC 2616 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
See RFC 2616 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
||||||
And RFC 6585 - http://tools.ietf.org/html/rfc6585
|
And RFC 6585 - http://tools.ietf.org/html/rfc6585
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
HTTP_100_CONTINUE = 100
|
HTTP_100_CONTINUE = 100
|
||||||
HTTP_101_SWITCHING_PROTOCOLS = 101
|
HTTP_101_SWITCHING_PROTOCOLS = 101
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
|
@ -8,7 +7,6 @@ from django.utils.safestring import SafeData, mark_safe
|
||||||
from rest_framework.compat import urlparse
|
from rest_framework.compat import urlparse
|
||||||
from rest_framework.compat import force_text
|
from rest_framework.compat import force_text
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import Client, TestCase
|
from django.test import Client, TestCase
|
||||||
|
@ -9,7 +8,6 @@ from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.authentication import TokenAuthentication, BasicAuthentication, SessionAuthentication
|
from rest_framework.authentication import TokenAuthentication, BasicAuthentication, SessionAuthentication
|
||||||
from rest_framework.compat import patterns
|
from rest_framework.compat import patterns
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework.compat import patterns, url
|
from rest_framework.compat import patterns, url
|
||||||
from rest_framework.utils.breadcrumbs import get_breadcrumbs
|
from rest_framework.utils.breadcrumbs import get_breadcrumbs
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.compat import apply_markdown
|
from rest_framework.compat import apply_markdown
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
General serializer field tests.
|
General serializer field tests.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import datetime
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.compat import BytesIO
|
from rest_framework.compat import BytesIO
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class UploadedFile(object):
|
class UploadedFile(object):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.contenttypes.generic import GenericRelation, GenericForeignKey
|
from django.contrib.contenttypes.generic import GenericRelation, GenericForeignKey
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
import json
|
import json
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
|
@ -1,35 +1,6 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
|
|
||||||
|
|
||||||
# from django.contrib.auth.models import Group
|
|
||||||
|
|
||||||
|
|
||||||
# class CustomUser(models.Model):
|
|
||||||
# """
|
|
||||||
# A custom user model, which uses a 'through' table for the foreign key
|
|
||||||
# """
|
|
||||||
# username = models.CharField(max_length=255, unique=True)
|
|
||||||
# groups = models.ManyToManyField(
|
|
||||||
# to=Group, blank=True, null=True, through='UserGroupMap'
|
|
||||||
# )
|
|
||||||
|
|
||||||
# @models.permalink
|
|
||||||
# def get_absolute_url(self):
|
|
||||||
# return ('custom_user', (), {
|
|
||||||
# 'pk': self.id
|
|
||||||
# })
|
|
||||||
|
|
||||||
|
|
||||||
# class UserGroupMap(models.Model):
|
|
||||||
# user = models.ForeignKey(to=CustomUser)
|
|
||||||
# group = models.ForeignKey(to=Group)
|
|
||||||
|
|
||||||
# @models.permalink
|
|
||||||
# def get_absolute_url(self):
|
|
||||||
# return ('user_group_map', (), {
|
|
||||||
# 'pk': self.id
|
|
||||||
# })
|
|
||||||
|
|
||||||
def foobar():
|
def foobar():
|
||||||
return 'foobar'
|
return 'foobar'
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
# from rest_framework.compat import patterns, url
|
|
||||||
# from django.forms import ModelForm
|
|
||||||
# from django.contrib.auth.models import Group, User
|
|
||||||
# from rest_framework.resources import ModelResource
|
|
||||||
# from rest_framework.views import ListOrCreateModelView, InstanceModelView
|
|
||||||
# from rest_framework.tests.models import CustomUser
|
|
||||||
# from rest_framework.tests.testcases import TestModelsTestCase
|
|
||||||
|
|
||||||
|
|
||||||
# class GroupResource(ModelResource):
|
|
||||||
# model = Group
|
|
||||||
|
|
||||||
|
|
||||||
# class UserForm(ModelForm):
|
|
||||||
# class Meta:
|
|
||||||
# model = User
|
|
||||||
# exclude = ('last_login', 'date_joined')
|
|
||||||
|
|
||||||
|
|
||||||
# class UserResource(ModelResource):
|
|
||||||
# model = User
|
|
||||||
# form = UserForm
|
|
||||||
|
|
||||||
|
|
||||||
# class CustomUserResource(ModelResource):
|
|
||||||
# model = CustomUser
|
|
||||||
|
|
||||||
# urlpatterns = patterns('',
|
|
||||||
# url(r'^users/$', ListOrCreateModelView.as_view(resource=UserResource), name='users'),
|
|
||||||
# url(r'^users/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=UserResource)),
|
|
||||||
# url(r'^customusers/$', ListOrCreateModelView.as_view(resource=CustomUserResource), name='customusers'),
|
|
||||||
# url(r'^customusers/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=CustomUserResource)),
|
|
||||||
# url(r'^groups/$', ListOrCreateModelView.as_view(resource=GroupResource), name='groups'),
|
|
||||||
# url(r'^groups/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=GroupResource)),
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
# class ModelViewTests(TestModelsTestCase):
|
|
||||||
# """Test the model views rest_framework provides"""
|
|
||||||
# urls = 'rest_framework.tests.modelviews'
|
|
||||||
|
|
||||||
# def test_creation(self):
|
|
||||||
# """Ensure that a model object can be created"""
|
|
||||||
# self.assertEqual(0, Group.objects.count())
|
|
||||||
|
|
||||||
# response = self.client.post('/groups/', {'name': 'foo'})
|
|
||||||
|
|
||||||
# self.assertEqual(response.status_code, 201)
|
|
||||||
# self.assertEqual(1, Group.objects.count())
|
|
||||||
# self.assertEqual('foo', Group.objects.all()[0].name)
|
|
||||||
|
|
||||||
# def test_creation_with_m2m_relation(self):
|
|
||||||
# """Ensure that a model object with a m2m relation can be created"""
|
|
||||||
# group = Group(name='foo')
|
|
||||||
# group.save()
|
|
||||||
# self.assertEqual(0, User.objects.count())
|
|
||||||
|
|
||||||
# response = self.client.post('/users/', {'username': 'bar', 'password': 'baz', 'groups': [group.id]})
|
|
||||||
|
|
||||||
# self.assertEqual(response.status_code, 201)
|
|
||||||
# self.assertEqual(1, User.objects.count())
|
|
||||||
|
|
||||||
# user = User.objects.all()[0]
|
|
||||||
# self.assertEqual('bar', user.username)
|
|
||||||
# self.assertEqual('baz', user.password)
|
|
||||||
# self.assertEqual(1, user.groups.count())
|
|
||||||
|
|
||||||
# group = user.groups.all()[0]
|
|
||||||
# self.assertEqual('foo', group.name)
|
|
||||||
|
|
||||||
# def test_creation_with_m2m_relation_through(self):
|
|
||||||
# """
|
|
||||||
# Ensure that a model object with a m2m relation can be created where that
|
|
||||||
# relation uses a through table
|
|
||||||
# """
|
|
||||||
# group = Group(name='foo')
|
|
||||||
# group.save()
|
|
||||||
# self.assertEqual(0, User.objects.count())
|
|
||||||
|
|
||||||
# response = self.client.post('/customusers/', {'username': 'bar', 'groups': [group.id]})
|
|
||||||
|
|
||||||
# self.assertEqual(response.status_code, 201)
|
|
||||||
# self.assertEqual(1, CustomUser.objects.count())
|
|
||||||
|
|
||||||
# user = CustomUser.objects.all()[0]
|
|
||||||
# self.assertEqual('bar', user.username)
|
|
||||||
# self.assertEqual(1, user.groups.count())
|
|
||||||
|
|
||||||
# group = user.groups.all()[0]
|
|
||||||
# self.assertEqual('foo', group.name)
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from rest_framework.negotiation import DefaultContentNegotiation
|
from rest_framework.negotiation import DefaultContentNegotiation
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
|
|
|
@ -1,136 +1,4 @@
|
||||||
# """
|
from __future__ import unicode_literals
|
||||||
# ..
|
|
||||||
# >>> from rest_framework.parsers import FormParser
|
|
||||||
# >>> from django.test.client import RequestFactory
|
|
||||||
# >>> from rest_framework.views import View
|
|
||||||
# >>> from StringIO import StringIO
|
|
||||||
# >>> from urllib import urlencode
|
|
||||||
# >>> req = RequestFactory().get('/')
|
|
||||||
# >>> some_view = View()
|
|
||||||
# >>> some_view.request = req # Make as if this request had been dispatched
|
|
||||||
#
|
|
||||||
# FormParser
|
|
||||||
# ============
|
|
||||||
#
|
|
||||||
# Data flatening
|
|
||||||
# ----------------
|
|
||||||
#
|
|
||||||
# Here is some example data, which would eventually be sent along with a post request :
|
|
||||||
#
|
|
||||||
# >>> inpt = urlencode([
|
|
||||||
# ... ('key1', 'bla1'),
|
|
||||||
# ... ('key2', 'blo1'), ('key2', 'blo2'),
|
|
||||||
# ... ])
|
|
||||||
#
|
|
||||||
# Default behaviour for :class:`parsers.FormParser`, is to return a single value for each parameter :
|
|
||||||
#
|
|
||||||
# >>> (data, files) = FormParser(some_view).parse(StringIO(inpt))
|
|
||||||
# >>> data == {'key1': 'bla1', 'key2': 'blo1'}
|
|
||||||
# True
|
|
||||||
#
|
|
||||||
# However, you can customize this behaviour by subclassing :class:`parsers.FormParser`, and overriding :meth:`parsers.FormParser.is_a_list` :
|
|
||||||
#
|
|
||||||
# >>> class MyFormParser(FormParser):
|
|
||||||
# ...
|
|
||||||
# ... def is_a_list(self, key, val_list):
|
|
||||||
# ... return len(val_list) > 1
|
|
||||||
#
|
|
||||||
# This new parser only flattens the lists of parameters that contain a single value.
|
|
||||||
#
|
|
||||||
# >>> (data, files) = MyFormParser(some_view).parse(StringIO(inpt))
|
|
||||||
# >>> data == {'key1': 'bla1', 'key2': ['blo1', 'blo2']}
|
|
||||||
# True
|
|
||||||
#
|
|
||||||
# .. note:: The same functionality is available for :class:`parsers.MultiPartParser`.
|
|
||||||
#
|
|
||||||
# Submitting an empty list
|
|
||||||
# --------------------------
|
|
||||||
#
|
|
||||||
# When submitting an empty select multiple, like this one ::
|
|
||||||
#
|
|
||||||
# <select multiple="multiple" name="key2"></select>
|
|
||||||
#
|
|
||||||
# The browsers usually strip the parameter completely. A hack to avoid this, and therefore being able to submit an empty select multiple, is to submit a value that tells the server that the list is empty ::
|
|
||||||
#
|
|
||||||
# <select multiple="multiple" name="key2"><option value="_empty"></select>
|
|
||||||
#
|
|
||||||
# :class:`parsers.FormParser` provides the server-side implementation for this hack. Considering the following posted data :
|
|
||||||
#
|
|
||||||
# >>> inpt = urlencode([
|
|
||||||
# ... ('key1', 'blo1'), ('key1', '_empty'),
|
|
||||||
# ... ('key2', '_empty'),
|
|
||||||
# ... ])
|
|
||||||
#
|
|
||||||
# :class:`parsers.FormParser` strips the values ``_empty`` from all the lists.
|
|
||||||
#
|
|
||||||
# >>> (data, files) = MyFormParser(some_view).parse(StringIO(inpt))
|
|
||||||
# >>> data == {'key1': 'blo1'}
|
|
||||||
# True
|
|
||||||
#
|
|
||||||
# Oh ... but wait a second, the parameter ``key2`` isn't even supposed to be a list, so the parser just stripped it.
|
|
||||||
#
|
|
||||||
# >>> class MyFormParser(FormParser):
|
|
||||||
# ...
|
|
||||||
# ... def is_a_list(self, key, val_list):
|
|
||||||
# ... return key == 'key2'
|
|
||||||
# ...
|
|
||||||
# >>> (data, files) = MyFormParser(some_view).parse(StringIO(inpt))
|
|
||||||
# >>> data == {'key1': 'blo1', 'key2': []}
|
|
||||||
# True
|
|
||||||
#
|
|
||||||
# Better like that. Note that you can configure something else than ``_empty`` for the empty value by setting :attr:`parsers.FormParser.EMPTY_VALUE`.
|
|
||||||
# """
|
|
||||||
# import httplib, mimetypes
|
|
||||||
# from tempfile import TemporaryFile
|
|
||||||
# from django.test import TestCase
|
|
||||||
# from django.test.client import RequestFactory
|
|
||||||
# from rest_framework.parsers import MultiPartParser
|
|
||||||
# from rest_framework.views import View
|
|
||||||
# from StringIO import StringIO
|
|
||||||
#
|
|
||||||
# def encode_multipart_formdata(fields, files):
|
|
||||||
# """For testing multipart parser.
|
|
||||||
# fields is a sequence of (name, value) elements for regular form fields.
|
|
||||||
# files is a sequence of (name, filename, value) elements for data to be uploaded as files
|
|
||||||
# Return (content_type, body)."""
|
|
||||||
# BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
|
|
||||||
# CRLF = '\r\n'
|
|
||||||
# L = []
|
|
||||||
# for (key, value) in fields:
|
|
||||||
# L.append('--' + BOUNDARY)
|
|
||||||
# L.append('Content-Disposition: form-data; name="%s"' % key)
|
|
||||||
# L.append('')
|
|
||||||
# L.append(value)
|
|
||||||
# for (key, filename, value) in files:
|
|
||||||
# L.append('--' + BOUNDARY)
|
|
||||||
# L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
|
|
||||||
# L.append('Content-Type: %s' % get_content_type(filename))
|
|
||||||
# L.append('')
|
|
||||||
# L.append(value)
|
|
||||||
# L.append('--' + BOUNDARY + '--')
|
|
||||||
# L.append('')
|
|
||||||
# body = CRLF.join(L)
|
|
||||||
# content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
|
|
||||||
# return content_type, body
|
|
||||||
#
|
|
||||||
# def get_content_type(filename):
|
|
||||||
# return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
|
|
||||||
#
|
|
||||||
#class TestMultiPartParser(TestCase):
|
|
||||||
# def setUp(self):
|
|
||||||
# self.req = RequestFactory()
|
|
||||||
# self.content_type, self.body = encode_multipart_formdata([('key1', 'val1'), ('key1', 'val2')],
|
|
||||||
# [('file1', 'pic.jpg', 'blablabla'), ('file1', 't.txt', 'blobloblo')])
|
|
||||||
#
|
|
||||||
# def test_multipartparser(self):
|
|
||||||
# """Ensure that MultiPartParser can parse multipart/form-data that contains a mix of several files and parameters."""
|
|
||||||
# post_req = RequestFactory().post('/', self.body, content_type=self.content_type)
|
|
||||||
# view = View()
|
|
||||||
# view.request = post_req
|
|
||||||
# (data, files) = MultiPartParser(view).parse(StringIO(self.body))
|
|
||||||
# self.assertEqual(data['key1'], 'val1')
|
|
||||||
# self.assertEqual(files['file1'].read(), 'blablabla')
|
|
||||||
|
|
||||||
from rest_framework.compat import StringIO
|
from rest_framework.compat import StringIO
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
General tests for relational fields.
|
General tests for relational fields.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.compat import patterns, url
|
from rest_framework.compat import patterns, url
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource
|
from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Tests for content parsing, and form-overloaded content parsing.
|
Tests for content parsing, and form-overloaded content parsing.
|
||||||
"""
|
"""
|
||||||
import json
|
from __future__ import unicode_literals
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
|
@ -21,6 +21,7 @@ from rest_framework.response import Response
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
factory = RequestFactory()
|
factory = RequestFactory()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework.compat import patterns, url, include
|
from rest_framework.compat import patterns, url, include
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from rest_framework.compat import patterns, url
|
from rest_framework.compat import patterns, url
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
|
||||||
import pickle
|
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
||||||
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
||||||
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
||||||
|
import datetime
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
class SubComment(object):
|
class SubComment(object):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Tests for the settings module"""
|
"""Tests for the settings module"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from rest_framework.settings import APISettings, DEFAULTS, IMPORT_STRINGS
|
from rest_framework.settings import APISettings, DEFAULTS, IMPORT_STRINGS
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Tests for the status module"""
|
"""Tests for the status module"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# http://djangosnippets.org/snippets/1011/
|
# http://djangosnippets.org/snippets/1011/
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db.models import loading
|
from django.db.models import loading
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
Force import of all modules in this package in order to get the standard test
|
Force import of all modules in this package in order to get the standard test
|
||||||
runner to pick up the tests. Yowzers.
|
runner to pick up the tests. Yowzers.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
|
|
||||||
modules = [filename.rsplit('.', 1)[0]
|
modules = [filename.rsplit('.', 1)[0]
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
"""
|
"""
|
||||||
Tests for the throttling implementations in the permissions module.
|
Tests for the throttling implementations in the permissions module.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.throttling import UserRateThrottle
|
from rest_framework.throttling import UserRateThrottle
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
from rest_framework.compat import patterns, url, include
|
from rest_framework.compat import patterns, url, include
|
||||||
from rest_framework.urlpatterns import format_suffix_patterns
|
from rest_framework.urlpatterns import format_suffix_patterns
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.test.client import RequestFactory, FakePayload
|
from django.test.client import RequestFactory, FakePayload
|
||||||
from django.test.client import MULTIPART_CONTENT
|
from django.test.client import MULTIPART_CONTENT
|
||||||
from rest_framework.compat import urlparse
|
from rest_framework.compat import urlparse
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import copy
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
@ -8,6 +6,7 @@ from rest_framework.decorators import api_view
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
import copy
|
||||||
|
|
||||||
factory = RequestFactory()
|
factory = RequestFactory()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import time
|
from __future__ import unicode_literals
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class BaseThrottle(object):
|
class BaseThrottle(object):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from django.core.urlresolvers import RegexURLResolver
|
||||||
from rest_framework.compat import url, include
|
from rest_framework.compat import url, include
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from django.core.urlresolvers import RegexURLResolver
|
|
||||||
|
|
||||||
|
|
||||||
def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required):
|
def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required):
|
||||||
|
|
|
@ -12,6 +12,7 @@ your authentication settings include `SessionAuthentication`.
|
||||||
url(r'^auth', include('rest_framework.urls', namespace='rest_framework'))
|
url(r'^auth', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from rest_framework.compat import patterns, url
|
from rest_framework.compat import patterns, url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.utils.xmlutils import SimplerXMLGenerator
|
from django.utils.xmlutils import SimplerXMLGenerator
|
||||||
from rest_framework.compat import StringIO
|
from rest_framework.compat import StringIO
|
||||||
from rest_framework.compat import six
|
from rest_framework.compat import six
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.core.urlresolvers import resolve, get_script_prefix
|
from django.core.urlresolvers import resolve, get_script_prefix
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
"""
|
"""
|
||||||
Helper classes for parsers.
|
Helper classes for parsers.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from django.utils.datastructures import SortedDict
|
||||||
|
from rest_framework.compat import timezone
|
||||||
|
from rest_framework.serializers import DictWithMetadata, SortedDictWithMetadata
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import types
|
import types
|
||||||
import json
|
import json
|
||||||
from django.utils.datastructures import SortedDict
|
|
||||||
from rest_framework.compat import timezone
|
|
||||||
from rest_framework.serializers import DictWithMetadata, SortedDictWithMetadata
|
|
||||||
|
|
||||||
|
|
||||||
class JSONEncoder(json.JSONEncoder):
|
class JSONEncoder(json.JSONEncoder):
|
||||||
|
|
|
@ -3,7 +3,7 @@ Handling of media types, as found in HTTP Content-Type and Accept headers.
|
||||||
|
|
||||||
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
|
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.http.multipartparser import parse_header
|
from django.http.multipartparser import parse_header
|
||||||
from rest_framework import HTTP_HEADER_ENCODING
|
from rest_framework import HTTP_HEADER_ENCODING
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Provides an APIView class that is used as the base of all class-based views.
|
Provides an APIView class that is used as the base of all class-based views.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
import re
|
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
@ -13,6 +12,7 @@ from rest_framework.compat import View, apply_markdown
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def _remove_trailing_string(content, trailing):
|
def _remove_trailing_string(content, trailing):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user