From 6c7a0ad570ab9d5ffe61b3b477b083aea9f1d080 Mon Sep 17 00:00:00 2001 From: Brishen Date: Fri, 31 Jan 2020 12:12:25 -0700 Subject: [PATCH 1/2] Represent UUID's as strings Convert UUID objects to string, otherwise pyyaml will fail to convert. --- rest_framework_yaml/encoders.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rest_framework_yaml/encoders.py b/rest_framework_yaml/encoders.py index a69dc70..0dc0587 100644 --- a/rest_framework_yaml/encoders.py +++ b/rest_framework_yaml/encoders.py @@ -6,7 +6,7 @@ import types from django.utils import six - +from uuid import UUID from .compat import ( yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList ) @@ -34,8 +34,12 @@ def represent_mapping(self, tag, mapping, flow_style=None): if not isinstance(mapping, OrderedDict): mapping.sort() for item_key, item_value in mapping: + if isinstance(item_value, UUID): + item_value = str(item_value) + node_key = self.represent_data(item_key) node_value = self.represent_data(item_value) + if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style): best_style = False if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style): From 2c9881f868f28da3f690e54ab14544dac4e85af5 Mon Sep 17 00:00:00 2001 From: Brishen Date: Fri, 31 Jan 2020 12:18:03 -0700 Subject: [PATCH 2/2] Switch from django.utils.six to six (#1) * Update compat.py * Update encoders.py * Update parsers.py * Update requirements.txt --- requirements.txt | 1 + rest_framework_yaml/compat.py | 3 +-- rest_framework_yaml/encoders.py | 2 +- rest_framework_yaml/parsers.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 96f0a23..6083d1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ wheel==0.24.0 # MkDocs for documentation previews/deploys mkdocs==0.11.1 +six==1.14.0 diff --git a/rest_framework_yaml/compat.py b/rest_framework_yaml/compat.py index 9f6c147..9ab839a 100644 --- a/rest_framework_yaml/compat.py +++ b/rest_framework_yaml/compat.py @@ -3,8 +3,7 @@ versions of django/python, and compatibility wrappers around optional packages. """ # flake8: noqa - -from django.utils import six +import six try: import yaml except ImportError: diff --git a/rest_framework_yaml/encoders.py b/rest_framework_yaml/encoders.py index 0dc0587..9d80e52 100644 --- a/rest_framework_yaml/encoders.py +++ b/rest_framework_yaml/encoders.py @@ -5,7 +5,7 @@ import decimal import types -from django.utils import six +import six from uuid import UUID from .compat import ( yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList diff --git a/rest_framework_yaml/parsers.py b/rest_framework_yaml/parsers.py index 2fbb744..8315347 100644 --- a/rest_framework_yaml/parsers.py +++ b/rest_framework_yaml/parsers.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals from django.conf import settings -from django.utils import six +import six from rest_framework.exceptions import ParseError from rest_framework.parsers import BaseParser