mirror of
https://github.com/httpie/cli.git
synced 2025-02-24 13:30:51 +01:00
Work around missing object_pairs_hook
in Python 2.6
This commit is contained in:
parent
22c993bab8
commit
25b1be7c8a
@ -23,8 +23,8 @@ except ImportError:
|
|||||||
try:
|
try:
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
except ImportError:
|
except ImportError:
|
||||||
### Python 2.6 OrderedDict class, needed for headers, parameters, etc .###
|
# Python 2.6 OrderedDict class, needed for headers, parameters, etc .###
|
||||||
### <https://pypi.python.org/pypi/ordereddict/1.1>
|
# <https://pypi.python.org/pypi/ordereddict/1.1>
|
||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility
|
||||||
from UserDict import DictMixin
|
from UserDict import DictMixin
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import json
|
|
||||||
import errno
|
import errno
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import getpass
|
import getpass
|
||||||
@ -19,6 +18,7 @@ from requests.structures import CaseInsensitiveDict
|
|||||||
|
|
||||||
from httpie.compat import OrderedDict, urlsplit, str
|
from httpie.compat import OrderedDict, urlsplit, str
|
||||||
from httpie.sessions import VALID_SESSION_NAME_PATTERN
|
from httpie.sessions import VALID_SESSION_NAME_PATTERN
|
||||||
|
from httpie.utils import load_json_preserve_order
|
||||||
|
|
||||||
|
|
||||||
HTTP_POST = 'POST'
|
HTTP_POST = 'POST'
|
||||||
@ -640,7 +640,7 @@ def parse_items(items,
|
|||||||
|
|
||||||
if item.sep in SEP_GROUP_RAW_JSON_ITEMS:
|
if item.sep in SEP_GROUP_RAW_JSON_ITEMS:
|
||||||
try:
|
try:
|
||||||
value = json.loads(value, object_pairs_hook=OrderedDict)
|
value = load_json_preserve_order(value)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise ParseError('"%s": %s' % (item.orig, e))
|
raise ParseError('"%s": %s' % (item.orig, e))
|
||||||
target = data
|
target = data
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
import json
|
||||||
|
|
||||||
|
from httpie.compat import is_py26, OrderedDict
|
||||||
|
|
||||||
|
|
||||||
|
def load_json_preserve_order(s):
|
||||||
|
if is_py26:
|
||||||
|
return json.loads(s)
|
||||||
|
return json.loads(s, object_pairs_hook=OrderedDict)
|
||||||
|
|
||||||
|
|
||||||
def humanize_bytes(n, precision=2):
|
def humanize_bytes(n, precision=2):
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
"""High-level tests."""
|
"""High-level tests."""
|
||||||
|
import pytest
|
||||||
from utils import TestEnvironment, http, HTTP_OK
|
from utils import TestEnvironment, http, HTTP_OK
|
||||||
from fixtures import FILE_PATH, FILE_CONTENT
|
from fixtures import FILE_PATH, FILE_CONTENT
|
||||||
|
|
||||||
import httpie
|
import httpie
|
||||||
|
from httpie.compat import is_py26
|
||||||
|
|
||||||
|
|
||||||
class TestHTTPie:
|
class TestHTTPie:
|
||||||
@ -64,7 +67,13 @@ class TestHTTPie:
|
|||||||
assert '"User-Agent": "HTTPie' in r, r
|
assert '"User-Agent": "HTTPie' in r, r
|
||||||
assert '"Foo": "bar"' in r
|
assert '"Foo": "bar"' in r
|
||||||
|
|
||||||
def test_json_order(self, httpbin):
|
@pytest.mark.skipif(
|
||||||
r = http('PATCH', httpbin.url + '/patch', 'order:={"map":{"1":"first","2":"second"}}')
|
is_py26,
|
||||||
|
reason='the `object_pairs_hook` arg for `json.loads()` is Py>2.6 only'
|
||||||
|
)
|
||||||
|
def test_json_input_preserve_order(self, httpbin):
|
||||||
|
r = http('PATCH', httpbin.url + '/patch',
|
||||||
|
'order:={"map":{"1":"first","2":"second"}}')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json['data'] == '{"order": {"map": {"1": "first", "2": "second"}}}'
|
assert r.json['data'] == \
|
||||||
|
'{"order": {"map": {"1": "first", "2": "second"}}}'
|
||||||
|
Loading…
Reference in New Issue
Block a user