mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-28 06:49:46 +00:00
move response-check to function
This commit is contained in:
parent
7738f9f4e3
commit
d939ed5042
@ -371,6 +371,16 @@ def node_url(node_dir, uri_fragment):
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def _check_status(response):
|
||||||
|
"""
|
||||||
|
Check the response code is a 2xx (raise an exception otherwise)
|
||||||
|
"""
|
||||||
|
if response.status_code < 200 or response.status_code >= 300:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Expected a 2xx code, got {}".format(response.status_code)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def web_get(node_dir, uri_fragment, **kw):
|
def web_get(node_dir, uri_fragment, **kw):
|
||||||
"""
|
"""
|
||||||
Make a web-request to the webport of `node_dir`. This will look
|
Make a web-request to the webport of `node_dir`. This will look
|
||||||
@ -378,10 +388,7 @@ def web_get(node_dir, uri_fragment, **kw):
|
|||||||
"""
|
"""
|
||||||
url = node_url(node_dir, uri_fragment)
|
url = node_url(node_dir, uri_fragment)
|
||||||
resp = requests.get(url, **kw)
|
resp = requests.get(url, **kw)
|
||||||
if resp.status_code < 200 or resp.status_code >= 300:
|
_check_status(resp)
|
||||||
raise RuntimeError(
|
|
||||||
"Expected a 200 code, got {}".format(resp.status_code)
|
|
||||||
)
|
|
||||||
return resp.content
|
return resp.content
|
||||||
|
|
||||||
|
|
||||||
@ -392,10 +399,7 @@ def web_post(node_dir, uri_fragment, **kw):
|
|||||||
"""
|
"""
|
||||||
url = node_url(node_dir, uri_fragment)
|
url = node_url(node_dir, uri_fragment)
|
||||||
resp = requests.post(url, **kw)
|
resp = requests.post(url, **kw)
|
||||||
if resp.status_code < 200 or resp.status_code >= 300:
|
_check_status(resp)
|
||||||
raise RuntimeError(
|
|
||||||
"Expected a 200 code, got {}".format(resp.status_code)
|
|
||||||
)
|
|
||||||
return resp.content
|
return resp.content
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user