File: python3.rst

package info (click to toggle)
django-tastypie 0.13.3-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,768 kB
  • ctags: 2,614
  • sloc: python: 14,124; makefile: 83; sh: 52
file content (65 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.. _ref-python3:

================
Python 3 Support
================

As of Tastypie v0.10.0, it has been ported to support both Python 2 & Python 3
within the same codebase. This builds on top of what `six`_ & `Django`_ provide.

No changes are required for anyone running an existing Tastypie
installation. The API is completely backward-compatible, so you should be able
to run your existing software without modification.

All tests pass under both Python 2 & 3.

.. _`six`: http://pythonhosted.org/six/
.. _`Django`: https://docs.djangoproject.com/en/dev/topics/python3/#str-and-unicode-methods


Incompatibilities
=================

Oauth Is Unsupported
--------------------

Tastypie was depending on several Oauth libraries for that authentication
mechanism. Unfortunately, none of them have been ported to Python 3. They're
still usable from Python 2, but that will be blocked until the underlying
libraries port (or an alternative can be found).

Changed Requirements
--------------------

Several requirements have changed under Python 3 (mostly due to unofficial
ports). They are:

* python3-digest instead of python-digest
* python-mimeparse instead of mimeparse


Notes
=====

Request/Response Bodies
-----------------------

For explicitness, Django on Python 3 reads request bodies & sends response
bodies as **binary** data. This requires an explicit ``.decode('utf-8')`` that
was not required (but works fine) under Python 2. If you're sending or reading
the bodies from Python, you'll need to keep this in mind.


Testing
-------

If you were testing things such as the XML/JSON generated by a given
response, under Python 3.3.2+,
`hash randomization`_ is in effect, which means that the ordering of
dictionaries is no longer consistent, even on the same platform.

To mitigate this, Tastypie now tries to ensure that serialized data is sorted
alphabetically. So if you were making string assertions, you'll need to update
them for the new payloads.

.. _`hash randomization`: http://docs.python.org/3/whatsnew/3.3.html#builtin-functions-and-types