python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -31,17 +31,23 @@ approach shown above.
"""
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument('-f', '--fixture',
help='The path to the fixture you\'d like to send '
'into Zulip')
parser.add_argument(
'-f', '--fixture', help='The path to the fixture you\'d like to send ' 'into Zulip'
)
parser.add_argument('-u', '--url',
help='The URL on your Zulip server that you want to post the fixture to')
parser.add_argument(
'-u', '--url', help='The URL on your Zulip server that you want to post the fixture to'
)
parser.add_argument('-H', '--custom-headers',
help='The headers you want to provide along with your mock request to Zulip.')
parser.add_argument(
'-H',
'--custom-headers',
help='The headers you want to provide along with your mock request to Zulip.',
)
self.add_realm_args(parser, help="Specify which realm/subdomain to connect to; default is zulip")
self.add_realm_args(
parser, help="Specify which realm/subdomain to connect to; default is zulip"
)
def parse_headers(self, custom_headers: Union[None, str]) -> Union[None, Dict[str, str]]:
if not custom_headers:
@@ -49,8 +55,10 @@ approach shown above.
try:
custom_headers_dict = orjson.loads(custom_headers)
except orjson.JSONDecodeError as ve:
raise CommandError('Encountered an error while attempting to parse custom headers: {}\n'
'Note: all strings must be enclosed within "" instead of \'\''.format(ve))
raise CommandError(
'Encountered an error while attempting to parse custom headers: {}\n'
'Note: all strings must be enclosed within "" instead of \'\''.format(ve)
)
return standardize_headers(custom_headers_dict)
def handle(self, **options: Optional[str]) -> None:
@@ -71,11 +79,17 @@ approach shown above.
client = Client()
if headers:
result = client.post(options['url'], json, content_type="application/json",
HTTP_HOST=realm.host, **headers)
result = client.post(
options['url'],
json,
content_type="application/json",
HTTP_HOST=realm.host,
**headers,
)
else:
result = client.post(options['url'], json, content_type="application/json",
HTTP_HOST=realm.host)
result = client.post(
options['url'], json, content_type="application/json", HTTP_HOST=realm.host
)
if result.status_code != 200:
raise CommandError(f'Error status {result.status_code}: {result.content}')