forked from jpadilla/django-rest-framework-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompat.py
38 lines (34 loc) · 1.14 KB
/
compat.py
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
"""
The `compat` module provides support for backwards compatibility with older
versions of django/python, and compatibility wrappers around optional packages.
"""
# flake8: noqa
from django.utils import six
try:
import yaml
except ImportError:
yaml = represent_text = None
else:
if six.PY3:
yaml_represent_text = yaml.representer.SafeRepresenter.represent_str
else:
yaml_represent_text = yaml.representer.SafeRepresenter.represent_unicode
# OrderedDict only available in Python 2.7.
# This will always be the case in Django 1.7 and above, as these versions
# no longer support Python 2.6.
# For Django <= 1.6 and Python 2.6 fall back to SortedDict.
try:
from collections import OrderedDict
except:
from django.utils.datastructures import SortedDict as OrderedDict
try:
# Note: Hyperlink is private(?) API from DRF 3
from rest_framework.relations import Hyperlink
except ImportError:
Hyperlink = None
try:
# Note: ReturnDict and ReturnList are private API from DRF 3
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
except ImportError:
ReturnDict = None
ReturnList = None