mirror of
https://github.com/httpie/cli.git
synced 2024-11-22 15:53:13 +01:00
Clean-up
This commit is contained in:
parent
f5cfd0143b
commit
26a76e8243
@ -3,7 +3,6 @@ python:
|
|||||||
- 2.6
|
- 2.6
|
||||||
- 2.7
|
- 2.7
|
||||||
- pypy
|
- pypy
|
||||||
- 3.1
|
|
||||||
- 3.2
|
- 3.2
|
||||||
script: python setup.py test
|
script: python setup.py test
|
||||||
install:
|
install:
|
||||||
|
16
README.rst
16
README.rst
@ -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
|
``--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
|
HTTP status is one of ``3xx``, ``4xx``, or ``5xx``. The exit status will
|
||||||
be ``3`` (unless ``--allow-redirects`` is set), ``4``, or ``5``
|
be ``3`` (unless ``--allow-redirects`` is set), ``4``, or ``5``
|
||||||
respectivelly::
|
respectively::
|
||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
@ -191,7 +191,8 @@ Flags
|
|||||||
Most of the flags mirror the arguments understood by ``requests.request``.
|
Most of the flags mirror the arguments understood by ``requests.request``.
|
||||||
See ``http --help`` for more details::
|
See ``http --help`` for more details::
|
||||||
|
|
||||||
# http --help
|
|
||||||
|
$ http --help
|
||||||
usage: http [--help] [--version] [--json | --form] [--traceback]
|
usage: http [--help] [--version] [--json | --form] [--traceback]
|
||||||
[--pretty | --ugly]
|
[--pretty | --ugly]
|
||||||
[--print OUTPUT_OPTIONS | --verbose | --headers | --body]
|
[--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
|
--timeout TIMEOUT Float describes the timeout of the request (Use
|
||||||
socket.setdefaulttimeout() as fallback).
|
socket.setdefaulttimeout() as fallback).
|
||||||
|
|
||||||
|
|
||||||
Contribute
|
Contribute
|
||||||
-----------
|
----------
|
||||||
|
|
||||||
`View contributors on GitHub <https://github.com/jkbr/httpie/contributors>`_.
|
`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>`_
|
* `0.2.6dev <https://github.com/jkbr/httpie/compare/0.2.5...master>`_
|
||||||
* Short option for ``--headers`` is now ``-h`` (``-t`` has been removed,
|
* Short option for ``--headers`` is now ``-h`` (``-t`` has been removed,
|
||||||
for usage use ``--help``).
|
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``).
|
(e.g.,``http -f url a=1 a=2``).
|
||||||
* Added ``--check-status`` to exit with an error for HTTP 3xx, 4xx and
|
* Added ``--check-status`` to exit with an error for HTTP 3xx, 4xx and
|
||||||
5xx (3, 4, 5).
|
5xx (3, 4, 5).
|
||||||
* If the output is piped to another program or redirected to a file,
|
* If the output is piped to another program or redirected to a file,
|
||||||
the new default behaviour is to only print the response body.
|
the new default behaviour is to only print the response body.
|
||||||
(It can still be overriden via the ``--print`` flag.)
|
(It can still be overwritten via the ``--print`` flag.)
|
||||||
* Improved highlighing of HTTP headers.
|
* Improved highlighting of HTTP headers.
|
||||||
* Added query string parameters (param==value).
|
* Added query string parameters (param==value).
|
||||||
* Added support for terminal colors under Windows.
|
* 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)
|
* `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.
|
* --auth now prompts for a password if only a username provided.
|
||||||
* Added support for request payloads from a file path with automatic
|
* Added support for request payloads from a file path with automatic
|
||||||
``Content-Type`` (``http URL @/path``).
|
``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``.
|
``--verbose``.
|
||||||
* Fixed Content-Type for requests with no data.
|
* 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)
|
* `0.2.2 <https://github.com/jkbr/httpie/compare/0.2.1...0.2.2>`_ (2012-06-24)
|
||||||
|
@ -59,6 +59,7 @@ class Parser(argparse.ArgumentParser):
|
|||||||
action='help', default=argparse.SUPPRESS,
|
action='help', default=argparse.SUPPRESS,
|
||||||
help=argparse._('show this help message and exit'))
|
help=argparse._('show this help message and exit'))
|
||||||
|
|
||||||
|
#noinspection PyMethodOverriding
|
||||||
def parse_args(self, env, args=None, namespace=None):
|
def parse_args(self, env, args=None, namespace=None):
|
||||||
|
|
||||||
args = super(Parser, self).parse_args(args, namespace)
|
args = super(Parser, self).parse_args(args, namespace)
|
||||||
@ -324,6 +325,7 @@ class AuthCredentialsArgType(KeyValueArgType):
|
|||||||
|
|
||||||
class ParamDict(OrderedDict):
|
class ParamDict(OrderedDict):
|
||||||
|
|
||||||
|
#noinspection PyMethodOverriding
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
"""
|
"""
|
||||||
If `key` is assigned more than once, `self[key]` holds a
|
If `key` is assigned more than once, `self[key]` holds a
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import requests.auth
|
||||||
from requests.compat import str
|
from requests.compat import str
|
||||||
|
|
||||||
from .models import HTTPMessage, Environment
|
from .models import HTTPMessage, Environment
|
||||||
from .output import OutputProcessor
|
from .output import OutputProcessor
|
||||||
from . import cliparse
|
from . import cliparse
|
||||||
@ -12,7 +15,7 @@ TYPE_FORM = 'application/x-www-form-urlencoded; charset=utf-8'
|
|||||||
TYPE_JSON = 'application/json; 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
|
auto_json = args.data and not args.form
|
||||||
if args.json or auto_json:
|
if args.json or auto_json:
|
||||||
@ -57,12 +60,12 @@ def get_response(args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
sys.stderr.write('\n')
|
env.stderr.write('\n')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if args.traceback:
|
if args.traceback:
|
||||||
raise
|
raise
|
||||||
sys.stderr.write(str(e.message) + '\n')
|
env.stderr.write(str(e.message) + '\n')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +143,7 @@ def main(args=sys.argv[1:], env=Environment()):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
args = cli.parser.parse_args(args=args, env=env)
|
args = cli.parser.parse_args(args=args, env=env)
|
||||||
response = get_response(args)
|
response = get_response(args, env)
|
||||||
|
|
||||||
status = 0
|
status = 0
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ class HTTPMessage(object):
|
|||||||
if request.params:
|
if request.params:
|
||||||
if url.query:
|
if url.query:
|
||||||
qs += '&'
|
qs += '&'
|
||||||
|
#noinspection PyUnresolvedReferences
|
||||||
qs += type(request)._encode_params(request.params)
|
qs += type(request)._encode_params(request.params)
|
||||||
|
|
||||||
# Request-Line
|
# Request-Line
|
||||||
@ -103,6 +104,7 @@ class HTTPMessage(object):
|
|||||||
# requests < 0.12.1
|
# requests < 0.12.1
|
||||||
body = request._enc_data
|
body = request._enc_data
|
||||||
if isinstance(body, dict):
|
if isinstance(body, dict):
|
||||||
|
#noinspection PyUnresolvedReferences
|
||||||
body = type(request)._encode_params(body)
|
body = type(request)._encode_params(body)
|
||||||
|
|
||||||
return HTTPMessage(
|
return HTTPMessage(
|
||||||
|
@ -4,6 +4,7 @@ Colorizing of HTTP messages and content processing.
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pygments
|
import pygments
|
||||||
from pygments import token, lexer
|
from pygments import token, lexer
|
||||||
from pygments.styles import get_style_by_name, STYLE_MAP
|
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.formatters.terminal256 import Terminal256Formatter
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
from requests.compat import is_windows
|
from requests.compat import is_windows
|
||||||
|
|
||||||
from . import solarized
|
from . import solarized
|
||||||
|
|
||||||
|
|
||||||
|
1
setup.py
1
setup.py
@ -55,5 +55,6 @@ setup(
|
|||||||
'Topic :: System :: Networking',
|
'Topic :: System :: Networking',
|
||||||
'Topic :: Terminals',
|
'Topic :: Terminals',
|
||||||
'Topic :: Text Processing',
|
'Topic :: Text Processing',
|
||||||
|
'Topic :: Utilities'
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -100,6 +100,7 @@ def http(*args, **kwargs):
|
|||||||
if TERMINAL_COLOR_PRESENCE_CHECK not in r:
|
if TERMINAL_COLOR_PRESENCE_CHECK not in r:
|
||||||
# De-serialize JSON body if possible.
|
# De-serialize JSON body if possible.
|
||||||
if r.strip().startswith('{'):
|
if r.strip().startswith('{'):
|
||||||
|
#noinspection PyTypeChecker
|
||||||
r.json = json.loads(r)
|
r.json = json.loads(r)
|
||||||
elif r.count('Content-Type:') == 1 and 'application/json' in r:
|
elif r.count('Content-Type:') == 1 and 'application/json' in r:
|
||||||
try:
|
try:
|
||||||
@ -886,4 +887,5 @@ class UnicodeOutputTestCase(BaseTestCase):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
#noinspection PyCallingNonCallable
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
2
tox.ini
2
tox.ini
@ -4,7 +4,7 @@
|
|||||||
# and then run "tox" from this directory.
|
# and then run "tox" from this directory.
|
||||||
|
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py26, py27, py30, py31, py32, pypy
|
envlist = py26, py27, py32, pypy
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands = {envpython} setup.py test
|
commands = {envpython} setup.py test
|
||||||
|
Loading…
Reference in New Issue
Block a user