Mercurial > hg
comparison mercurial/hgweb/wsgicgi.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 | 2d5b5bcc3b9f |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
10 | 10 |
11 from __future__ import absolute_import | 11 from __future__ import absolute_import |
12 | 12 |
13 import os | 13 import os |
14 | 14 |
15 from .. import ( | 15 from .. import pycompat |
16 pycompat, | |
17 ) | |
18 | 16 |
19 from ..utils import ( | 17 from ..utils import procutil |
20 procutil, | |
21 ) | |
22 | 18 |
23 from . import ( | 19 from . import common |
24 common, | 20 |
25 ) | |
26 | 21 |
27 def launch(application): | 22 def launch(application): |
28 procutil.setbinary(procutil.stdin) | 23 procutil.setbinary(procutil.stdin) |
29 procutil.setbinary(procutil.stdout) | 24 procutil.setbinary(procutil.stdout) |
30 | 25 |
31 environ = dict(os.environ.iteritems()) # re-exports | 26 environ = dict(os.environ.iteritems()) # re-exports |
32 environ.setdefault(r'PATH_INFO', '') | 27 environ.setdefault(r'PATH_INFO', '') |
33 if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'): | 28 if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'): |
34 # IIS includes script_name in PATH_INFO | 29 # IIS includes script_name in PATH_INFO |
35 scriptname = environ[r'SCRIPT_NAME'] | 30 scriptname = environ[r'SCRIPT_NAME'] |
36 if environ[r'PATH_INFO'].startswith(scriptname): | 31 if environ[r'PATH_INFO'].startswith(scriptname): |
37 environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):] | 32 environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname) :] |
38 | 33 |
39 stdin = procutil.stdin | 34 stdin = procutil.stdin |
40 if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue': | 35 if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue': |
41 stdin = common.continuereader(stdin, procutil.stdout.write) | 36 stdin = common.continuereader(stdin, procutil.stdout.write) |
42 | 37 |
63 elif not headers_sent: | 58 elif not headers_sent: |
64 # Before the first output, send the stored headers | 59 # Before the first output, send the stored headers |
65 status, response_headers = headers_sent[:] = headers_set | 60 status, response_headers = headers_sent[:] = headers_set |
66 out.write('Status: %s\r\n' % pycompat.bytesurl(status)) | 61 out.write('Status: %s\r\n' % pycompat.bytesurl(status)) |
67 for hk, hv in response_headers: | 62 for hk, hv in response_headers: |
68 out.write('%s: %s\r\n' % (pycompat.bytesurl(hk), | 63 out.write( |
69 pycompat.bytesurl(hv))) | 64 '%s: %s\r\n' |
65 % (pycompat.bytesurl(hk), pycompat.bytesurl(hv)) | |
66 ) | |
70 out.write('\r\n') | 67 out.write('\r\n') |
71 | 68 |
72 out.write(data) | 69 out.write(data) |
73 out.flush() | 70 out.flush() |
74 | 71 |
77 try: | 74 try: |
78 if headers_sent: | 75 if headers_sent: |
79 # Re-raise original exception if headers sent | 76 # Re-raise original exception if headers sent |
80 raise exc_info[0](exc_info[1], exc_info[2]) | 77 raise exc_info[0](exc_info[1], exc_info[2]) |
81 finally: | 78 finally: |
82 exc_info = None # avoid dangling circular ref | 79 exc_info = None # avoid dangling circular ref |
83 elif headers_set: | 80 elif headers_set: |
84 raise AssertionError("Headers already set!") | 81 raise AssertionError("Headers already set!") |
85 | 82 |
86 headers_set[:] = [status, response_headers] | 83 headers_set[:] = [status, response_headers] |
87 return write | 84 return write |
89 content = application(environ, start_response) | 86 content = application(environ, start_response) |
90 try: | 87 try: |
91 for chunk in content: | 88 for chunk in content: |
92 write(chunk) | 89 write(chunk) |
93 if not headers_sent: | 90 if not headers_sent: |
94 write('') # send headers now if body was empty | 91 write('') # send headers now if body was empty |
95 finally: | 92 finally: |
96 getattr(content, 'close', lambda: None)() | 93 getattr(content, 'close', lambda: None)() |