mirror of
https://github.com/httpie/cli.git
synced 2025-08-14 01:18:22 +02:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ce02ebbd5 | |||
8a7f4c0d6e | |||
f29c458611 | |||
2d7df0afb4 | |||
16a7d0a719 | |||
0cffda86f6 | |||
f42ee6da85 | |||
deeb7cbbac | |||
12f2fb4a92 | |||
489bd64295 | |||
2036337a53 | |||
36de166b28 |
@ -225,7 +225,7 @@ Before a pull requests is submitted, it's a good idea to run the existing suite
|
|||||||
Changelog
|
Changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* `0.2.3 <https://github.com/jkbr/httpie/compare/0.2.2...0.2.3>`_ (2012-06-24)
|
* `0.2.5 <https://github.com/jkbr/httpie/compare/0.2.2...0.2.5>`_ (2012-07-17)
|
||||||
* Unicode characters in prettified JSON now don't get escaped to improve readability.
|
* Unicode characters in prettified JSON now don't get escaped to improve readability.
|
||||||
* --auth now prompts for a password if only a username provided.
|
* --auth now prompts for a password if only a username provided.
|
||||||
* Added support for request payloads from a file path with automatic ``Content-Type`` (``http URL @/path``).
|
* Added support for request payloads from a file path with automatic ``Content-Type`` (``http URL @/path``).
|
||||||
|
@ -3,5 +3,5 @@ HTTPie - cURL for humans.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
__author__ = 'Jakub Roztocil'
|
__author__ = 'Jakub Roztocil'
|
||||||
__version__ = '0.2.3'
|
__version__ = '0.2.5'
|
||||||
__licence__ = 'BSD'
|
__licence__ = 'BSD'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pygments
|
import pygments
|
||||||
@ -18,6 +19,8 @@ FORMATTER = (Terminal256Formatter
|
|||||||
if '256color' in os.environ.get('TERM', '')
|
if '256color' in os.environ.get('TERM', '')
|
||||||
else TerminalFormatter)
|
else TerminalFormatter)
|
||||||
|
|
||||||
|
application_content_type_re = re.compile(r'application/(.+\+)(json|xml)$')
|
||||||
|
|
||||||
|
|
||||||
class PrettyHttp(object):
|
class PrettyHttp(object):
|
||||||
|
|
||||||
@ -33,12 +36,18 @@ class PrettyHttp(object):
|
|||||||
|
|
||||||
def body(self, content, content_type):
|
def body(self, content, content_type):
|
||||||
content_type = content_type.split(';')[0]
|
content_type = content_type.split(';')[0]
|
||||||
|
application_match = re.match(application_content_type_re, content_type)
|
||||||
|
if application_match:
|
||||||
|
# Strip vendor and extensions from Content-Type
|
||||||
|
vendor, extension = application_match.groups()
|
||||||
|
content_type = content_type.replace(vendor, '')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_for_mimetype(content_type)
|
lexer = get_lexer_for_mimetype(content_type)
|
||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
return content
|
return content
|
||||||
|
|
||||||
if content_type == 'application/json':
|
if content_type == "application/json":
|
||||||
try:
|
try:
|
||||||
# Indent and sort the JSON data.
|
# Indent and sort the JSON data.
|
||||||
content = json.dumps(json.loads(content),
|
content = json.dumps(json.loads(content),
|
||||||
|
3
setup.py
3
setup.py
@ -5,7 +5,8 @@ import httpie
|
|||||||
|
|
||||||
|
|
||||||
if sys.argv[-1] == 'test':
|
if sys.argv[-1] == 'test':
|
||||||
sys.exit(os.system('python tests/tests.py'))
|
status = os.system('python tests/tests.py')
|
||||||
|
sys.exit(1 if status > 127 else status)
|
||||||
|
|
||||||
|
|
||||||
requirements = [
|
requirements = [
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import json
|
import json
|
||||||
from requests.compat import is_py26
|
from requests.compat import is_py26, is_py3
|
||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
|
|
||||||
@ -453,7 +453,7 @@ class FakeResponse(Response):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return u'Mock string'
|
return 'Mock string'
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
@ -470,8 +470,13 @@ class UnicodeOutputTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_unicode_output(self):
|
def test_unicode_output(self):
|
||||||
# some cyrillic and simplified chinese symbols
|
# some cyrillic and simplified chinese symbols
|
||||||
response_dict = {u'Привет': u'Мир!',
|
response_dict = {'Привет': 'Мир!',
|
||||||
u'Hello': u'世界'}
|
'Hello': '世界'}
|
||||||
|
if not is_py3:
|
||||||
|
response_dict = dict(
|
||||||
|
(k.decode('utf8'), v.decode('utf8'))
|
||||||
|
for k, v in response_dict.items()
|
||||||
|
)
|
||||||
response_body = json.dumps(response_dict)
|
response_body = json.dumps(response_dict)
|
||||||
# emulate response
|
# emulate response
|
||||||
response = FakeResponse(response_body)
|
response = FakeResponse(response_body)
|
||||||
@ -486,7 +491,7 @@ class UnicodeOutputTestCase(BaseTestCase):
|
|||||||
# colorized output contains escape sequences
|
# colorized output contains escape sequences
|
||||||
output = __main__._get_output(args, True, response)
|
output = __main__._get_output(args, True, response)
|
||||||
|
|
||||||
for key, value in response_dict.iteritems():
|
for key, value in response_dict.items():
|
||||||
self.assertIn(key, output)
|
self.assertIn(key, output)
|
||||||
self.assertIn(value, output)
|
self.assertIn(value, output)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user