# Python
from collections import OrderedDict
import json
import yaml

# Django
from django.conf import settings
from django.utils import six
from django.utils.translation import ugettext_lazy as _

# Django REST Framework
from rest_framework import parsers
from rest_framework.exceptions import ParseError


class OrderedDictLoader(yaml.SafeLoader):
    """
    This yaml loader is used to deal with current pyYAML (3.12) not supporting
    custom object pairs hook. Remove it when new version adds that support.
    """

    def construct_mapping(self, node, deep=False):
        if isinstance(node, yaml.nodes.MappingNode):
            self.flatten_mapping(node)
        else:
            raise yaml.constructor.ConstructorError(
                None, None,
                "expected a mapping node, but found %s" % node.id,
                node.start_mark
            )
        mapping = OrderedDict()
        for key_node, value_node in node.value:
            key = self.construct_object(key_node, deep=deep)
            try:
                hash(key)
            except TypeError as exc:
                raise yaml.constructor.ConstructorError(
                    "while constructing a mapping", node.start_mark,
                    "found unacceptable key (%s)" % exc, key_node.start_mark
                )
            value = self.construct_object(value_node, deep=deep)
            mapping[key] = value
        return mapping


class JSONParser(parsers.JSONParser):
    """
    Parses JSON-serialized data, preserving order of dictionary keys.
    """

    def parse(self, stream, media_type=None, parser_context=None):
        """
        Parses the incoming bytestream as JSON and returns the resulting data.
        """
        parser_context = parser_context or {}
        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)

        try:
            data = stream.read().decode(encoding)
            if not data:
                return {}
            obj = json.loads(data, object_pairs_hook=OrderedDict)
            if not isinstance(obj, dict) and obj is not None:
                raise ParseError(_('JSON parse error - not a JSON object'))
            return obj
        except ValueError as exc:
            raise ParseError(_('JSON parse error - %s\nPossible cause: trailing comma.' % six.text_type(exc)))

@@ -53,20 +53,8 @@
 json
-%0Aimport yaml
 %0A%0A# 
@@ -293,1138 +293,8 @@
 r%0A%0A%0A
-class OrderedDictLoader(yaml.SafeLoader):%0A    %22%22%22%0A    This yaml loader is used to deal with current pyYAML (3.12) not supporting%0A    custom object pairs hook. Remove it when new version adds that support.%0A    %22%22%22%0A%0A    def construct_mapping(self, node, deep=False):%0A        if isinstance(node, yaml.nodes.MappingNode):%0A            self.flatten_mapping(node)%0A        else:%0A            raise yaml.constructor.ConstructorError(%0A                None, None,%0A                %22expected a mapping node, but found %25s%22 %25 node.id,%0A                node.start_mark%0A            )%0A        mapping = OrderedDict()%0A        for key_node, value_node in node.value:%0A            key = self.construct_object(key_node, deep=deep)%0A            try:%0A                hash(key)%0A            except TypeError as exc:%0A                raise yaml.constructor.ConstructorError(%0A                    %22while constructing a mapping%22, node.start_mark,%0A                    %22found unacceptable key (%25s)%22 %25 exc, key_node.start_mark%0A                )%0A            value = self.construct_object(value_node, deep=deep)%0A            mapping%5Bkey%5D = value%0A        return mapping%0A%0A%0A
 clas

Remove unused code, OrderedDictLoader