This commit is contained in:
Jakub Roztocil 2012-07-26 00:26:23 +02:00
parent f5cfd0143b
commit 26a76e8243
9 changed files with 25 additions and 14 deletions

View File

@ -3,7 +3,6 @@ python:
- 2.6
- 2.7
- pypy
- 3.1
- 3.2
script: python setup.py test
install:

View File

@ -170,7 +170,7 @@ When using HTTPie from **shell scripts**, you might want to use the
``--check-status`` flag. It instructs HTTPie to exit with an error if the
HTTP status is one of ``3xx``, ``4xx``, or ``5xx``. The exit status will
be ``3`` (unless ``--allow-redirects`` is set), ``4``, or ``5``
respectivelly::
respectively::
#!/bin/bash
@ -191,7 +191,8 @@ Flags
Most of the flags mirror the arguments understood by ``requests.request``.
See ``http --help`` for more details::
# http --help
$ http --help
usage: http [--help] [--version] [--json | --form] [--traceback]
[--pretty | --ugly]
[--print OUTPUT_OPTIONS | --verbose | --headers | --body]
@ -287,9 +288,8 @@ See ``http --help`` for more details::
--timeout TIMEOUT Float describes the timeout of the request (Use
socket.setdefaulttimeout() as fallback).
Contribute
-----------
----------
`View contributors on GitHub <https://github.com/jkbr/httpie/contributors>`_.
@ -329,14 +329,14 @@ Changelog
* `0.2.6dev <https://github.com/jkbr/httpie/compare/0.2.5...master>`_
* Short option for ``--headers`` is now ``-h`` (``-t`` has been removed,
for usage use ``--help``).
* Form data and URL params can now have mutiple fields with the same name
* Form data and URL params can now have multiple fields with the same name
(e.g.,``http -f url a=1 a=2``).
* Added ``--check-status`` to exit with an error for HTTP 3xx, 4xx and
5xx (3, 4, 5).
* If the output is piped to another program or redirected to a file,
the new default behaviour is to only print the response body.
(It can still be overriden via the ``--print`` flag.)
* Improved highlighing of HTTP headers.
(It can still be overwritten via the ``--print`` flag.)
* Improved highlighting of HTTP headers.
* Added query string parameters (param==value).
* Added support for terminal colors under Windows.
* `0.2.5 <https://github.com/jkbr/httpie/compare/0.2.2...0.2.5>`_ (2012-07-17)
@ -345,7 +345,7 @@ Changelog
* --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``).
* Fixed missing query string when displaing the request headers via
* Fixed missing query string when displaying the request headers via
``--verbose``.
* Fixed Content-Type for requests with no data.
* `0.2.2 <https://github.com/jkbr/httpie/compare/0.2.1...0.2.2>`_ (2012-06-24)

View File

@ -59,6 +59,7 @@ class Parser(argparse.ArgumentParser):
action='help', default=argparse.SUPPRESS,
help=argparse._('show this help message and exit'))
#noinspection PyMethodOverriding
def parse_args(self, env, args=None, namespace=None):
args = super(Parser, self).parse_args(args, namespace)
@ -324,6 +325,7 @@ class AuthCredentialsArgType(KeyValueArgType):
class ParamDict(OrderedDict):
#noinspection PyMethodOverriding
def __setitem__(self, key, value):
"""
If `key` is assigned more than once, `self[key]` holds a

View File

@ -1,7 +1,10 @@
import sys
import json
import requests
import requests.auth
from requests.compat import str
from .models import HTTPMessage, Environment
from .output import OutputProcessor
from . import cliparse
@ -12,7 +15,7 @@ TYPE_FORM = 'application/x-www-form-urlencoded; charset=utf-8'
TYPE_JSON = 'application/json; charset=utf-8'
def get_response(args):
def get_response(args, env):
auto_json = args.data and not args.form
if args.json or auto_json:
@ -57,12 +60,12 @@ def get_response(args):
)
except (KeyboardInterrupt, SystemExit):
sys.stderr.write('\n')
env.stderr.write('\n')
sys.exit(1)
except Exception as e:
if args.traceback:
raise
sys.stderr.write(str(e.message) + '\n')
env.stderr.write(str(e.message) + '\n')
sys.exit(1)
@ -140,7 +143,7 @@ def main(args=sys.argv[1:], env=Environment()):
"""
args = cli.parser.parse_args(args=args, env=env)
response = get_response(args)
response = get_response(args, env)
status = 0

View File

@ -76,6 +76,7 @@ class HTTPMessage(object):
if request.params:
if url.query:
qs += '&'
#noinspection PyUnresolvedReferences
qs += type(request)._encode_params(request.params)
# Request-Line
@ -103,6 +104,7 @@ class HTTPMessage(object):
# requests < 0.12.1
body = request._enc_data
if isinstance(body, dict):
#noinspection PyUnresolvedReferences
body = type(request)._encode_params(body)
return HTTPMessage(

View File

@ -4,6 +4,7 @@ Colorizing of HTTP messages and content processing.
"""
import re
import json
import pygments
from pygments import token, lexer
from pygments.styles import get_style_by_name, STYLE_MAP
@ -12,6 +13,7 @@ from pygments.formatters.terminal import TerminalFormatter
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.util import ClassNotFound
from requests.compat import is_windows
from . import solarized

View File

@ -55,5 +55,6 @@ setup(
'Topic :: System :: Networking',
'Topic :: Terminals',
'Topic :: Text Processing',
'Topic :: Utilities'
],
)

View File

@ -100,6 +100,7 @@ def http(*args, **kwargs):
if TERMINAL_COLOR_PRESENCE_CHECK not in r:
# De-serialize JSON body if possible.
if r.strip().startswith('{'):
#noinspection PyTypeChecker
r.json = json.loads(r)
elif r.count('Content-Type:') == 1 and 'application/json' in r:
try:
@ -886,4 +887,5 @@ class UnicodeOutputTestCase(BaseTestCase):
if __name__ == '__main__':
#noinspection PyCallingNonCallable
unittest.main()

View File

@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
envlist = py26, py27, py30, py31, py32, pypy
envlist = py26, py27, py32, pypy
[testenv]
commands = {envpython} setup.py test