Mercurial > public > mercurial-scm > hg-stable
diff tests/get-with-headers.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | fe11fc7e541f |
children | 579672b347d2 |
line wrap: on
line diff
--- a/tests/get-with-headers.py Sat Oct 05 10:29:34 2019 -0400 +++ b/tests/get-with-headers.py Sun Oct 06 09:45:02 2019 -0400 @@ -19,6 +19,7 @@ try: import msvcrt + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) except ImportError: @@ -31,11 +32,14 @@ parser.add_argument('--headeronly', action='store_true') parser.add_argument('--json', action='store_true') parser.add_argument('--hgproto') -parser.add_argument('--requestheader', nargs='*', default=[], - help='Send an additional HTTP request header. Argument ' - 'value is <header>=<value>') -parser.add_argument('--bodyfile', - help='Write HTTP response body to a file') +parser.add_argument( + '--requestheader', + nargs='*', + default=[], + help='Send an additional HTTP request header. Argument ' + 'value is <header>=<value>', +) +parser.add_argument('--bodyfile', help='Write HTTP response body to a file') parser.add_argument('host') parser.add_argument('path') parser.add_argument('show', nargs='*') @@ -49,6 +53,8 @@ requestheaders = args.requestheader tag = None + + def request(host, path, show): assert not path.startswith('/'), path global tag @@ -65,15 +71,19 @@ conn = httplib.HTTPConnection(host) conn.request("GET", '/' + path, None, headers) response = conn.getresponse() - stdout.write(b'%d %s\n' % (response.status, - response.reason.encode('ascii'))) + stdout.write( + b'%d %s\n' % (response.status, response.reason.encode('ascii')) + ) if show[:1] == ['-']: - show = sorted(h for h, v in response.getheaders() - if h.lower() not in show) + show = sorted( + h for h, v in response.getheaders() if h.lower() not in show + ) for h in [h.lower() for h in show]: if response.getheader(h, None) is not None: - stdout.write(b"%s: %s\n" % (h.encode('ascii'), - response.getheader(h).encode('ascii'))) + stdout.write( + b"%s: %s\n" + % (h.encode('ascii'), response.getheader(h).encode('ascii')) + ) if not headeronly: stdout.write(b'\n') data = response.read() @@ -104,6 +114,7 @@ return response.status + status = request(args.host, args.path, args.show) if twice: status = request(args.host, args.path, args.show)