Commit 00752dcd by Tom Christie

Py3k cleanup

parent f4f237e3
...@@ -4,18 +4,17 @@ python: ...@@ -4,18 +4,17 @@ python:
- "2.6" - "2.6"
- "2.7" - "2.7"
- "3.2" - "3.2"
- "3.3"
env: env:
- DJANGO=https://github.com/django/django/zipball/master
- DJANGO=https://www.djangoproject.com/download/1.5c1/tarball/ - DJANGO=https://www.djangoproject.com/download/1.5c1/tarball/
- DJANGO="django==1.4.3 --use-mirrors" - DJANGO="django==1.4.3 --use-mirrors"
- DJANGO="django==1.3.5 --use-mirrors" - DJANGO="django==1.3.5 --use-mirrors"
install: install:
- pip install $DJANGO - pip install $DJANGO
- "if [[ $TRAVIS_PYTHON_VERSION != '3.2' ]]; then pip install django-filter==0.5.4 --use-mirrors; fi" - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-filter==0.5.4 --use-mirrors; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then pip install https://github.com/alex/django-filter/tarball/master; fi" - "if [[ ${TRAVIS_PYTHON_VERSION::1} == '3' ]]; then pip install https://github.com/alex/django-filter/tarball/master; fi"
- "if [[ $DJANGO == 'django==1.3.5 --use-mirrors' ]]; then pip install six --use-mirrors; fi"
- export PYTHONPATH=. - export PYTHONPATH=.
script: script:
...@@ -27,3 +26,7 @@ matrix: ...@@ -27,3 +26,7 @@ matrix:
env: DJANGO="django==1.4.3 --use-mirrors" env: DJANGO="django==1.4.3 --use-mirrors"
- python: "3.2" - python: "3.2"
env: DJANGO="django==1.3.5 --use-mirrors" env: DJANGO="django==1.3.5 --use-mirrors"
- python: "3.3"
env: DJANGO="django==1.4.3 --use-mirrors"
- python: "3.3"
env: DJANGO="django==1.3.5 --use-mirrors"
...@@ -28,7 +28,7 @@ There is also a sandbox API you can use for testing purposes, [available here][s ...@@ -28,7 +28,7 @@ There is also a sandbox API you can use for testing purposes, [available here][s
# Requirements # Requirements
* Python (2.6, 2.7) * Python (2.6, 2.7, 3.2, 3.3)
* Django (1.3, 1.4, 1.5) * Django (1.3, 1.4, 1.5)
**Optional:** **Optional:**
......
...@@ -33,7 +33,7 @@ There is also a sandbox API you can use for testing purposes, [available here][s ...@@ -33,7 +33,7 @@ There is also a sandbox API you can use for testing purposes, [available here][s
REST framework requires the following: REST framework requires the following:
* Python (2.6, 2.7) * Python (2.6, 2.7, 3.2, 3.3)
* Django (1.3, 1.4, 1.5) * Django (1.3, 1.4, 1.5)
The following packages are optional: The following packages are optional:
......
...@@ -7,11 +7,11 @@ from __future__ import unicode_literals ...@@ -7,11 +7,11 @@ from __future__ import unicode_literals
import django import django
# Try to import six from Django, fallback to six itself (1.3.x) # Try to import six from Django, fallback to included `six`.
try: try:
from django.utils import six from django.utils import six
except: except:
import six from rest_framework import six
# location of patterns, url, include changes in 1.4 onwards # location of patterns, url, include changes in 1.4 onwards
try: try:
......
...@@ -9,10 +9,11 @@ The wrapped request then offers a richer API, in particular : ...@@ -9,10 +9,11 @@ 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 rest_framework.compat import BytesIO
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 exceptions from rest_framework import exceptions
from rest_framework.compat import BytesIO
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
...@@ -20,7 +21,7 @@ def is_form_media_type(media_type): ...@@ -20,7 +21,7 @@ def is_form_media_type(media_type):
""" """
Return True if the media type is a valid form media type. Return True if the media type is a valid form media type.
""" """
base_media_type, params = parse_header(media_type.encode('iso-8859-1')) base_media_type, params = parse_header(media_type.encode(HTTP_HEADER_ENCODING))
return (base_media_type == 'application/x-www-form-urlencoded' or return (base_media_type == 'application/x-www-form-urlencoded' or
base_media_type == 'multipart/form-data') base_media_type == 'multipart/form-data')
...@@ -277,7 +278,7 @@ class Request(object): ...@@ -277,7 +278,7 @@ class Request(object):
self._CONTENT_PARAM in self._data and self._CONTENT_PARAM in self._data and
self._CONTENTTYPE_PARAM in self._data): self._CONTENTTYPE_PARAM in self._data):
self._content_type = self._data[self._CONTENTTYPE_PARAM] self._content_type = self._data[self._CONTENTTYPE_PARAM]
self._stream = BytesIO(self._data[self._CONTENT_PARAM].encode('iso-8859-1')) self._stream = BytesIO(self._data[self._CONTENT_PARAM].encode(HTTP_HEADER_ENCODING))
self._data, self._files = (Empty, Empty) self._data, self._files = (Empty, Empty)
def _parse(self): def _parse(self):
......
...@@ -5,6 +5,7 @@ See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 ...@@ -5,6 +5,7 @@ See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
""" """
from django.http.multipartparser import parse_header from django.http.multipartparser import parse_header
from rest_framework import HTTP_HEADER_ENCODING
def media_type_matches(lhs, rhs): def media_type_matches(lhs, rhs):
...@@ -47,7 +48,7 @@ class _MediaType(object): ...@@ -47,7 +48,7 @@ class _MediaType(object):
if media_type_str is None: if media_type_str is None:
media_type_str = '' media_type_str = ''
self.orig = media_type_str self.orig = media_type_str
self.full_type, self.params = parse_header(media_type_str.encode('iso-8859-1')) self.full_type, self.params = parse_header(media_type_str.encode(HTTP_HEADER_ENCODING))
self.main_type, sep, self.sub_type = self.full_type.partition('/') self.main_type, sep, self.sub_type = self.full_type.partition('/')
def match(self, other): def match(self, other):
......
...@@ -8,12 +8,12 @@ commands = {envpython} rest_framework/runtests/runtests.py ...@@ -8,12 +8,12 @@ commands = {envpython} rest_framework/runtests/runtests.py
[testenv:py3.3-django1.5] [testenv:py3.3-django1.5]
basepython = python3.3 basepython = python3.3
deps = https://www.djangoproject.com/download/1.5c1/tarball/ deps = https://www.djangoproject.com/download/1.5c1/tarball/
django-filter==0.5.4 https://github.com/alex/django-filter/archive/master.tar.gz
[testenv:py3.2-django1.5] [testenv:py3.2-django1.5]
basepython = python3.2 basepython = python3.2
deps = https://www.djangoproject.com/download/1.5c1/tarball/ deps = https://www.djangoproject.com/download/1.5c1/tarball/
django-filter==0.5.4 https://github.com/alex/django-filter/archive/master.tar.gz
[testenv:py2.7-django1.5] [testenv:py2.7-django1.5]
basepython = python2.7 basepython = python2.7
...@@ -39,10 +39,8 @@ deps = django==1.4.3 ...@@ -39,10 +39,8 @@ deps = django==1.4.3
basepython = python2.7 basepython = python2.7
deps = django==1.3.5 deps = django==1.3.5
django-filter==0.5.4 django-filter==0.5.4
six
[testenv:py2.6-django1.3] [testenv:py2.6-django1.3]
basepython = python2.6 basepython = python2.6
deps = django==1.3.5 deps = django==1.3.5
django-filter==0.5.4 django-filter==0.5.4
six
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment