mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-23 18:50:24 +00:00
More modernization.
This commit is contained in:
parent
1823dd4c03
commit
2916984114
@ -1,12 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
Ported to Python 3.
|
Blocking HTTP client APIs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from http import client as http_client
|
from http import client as http_client
|
||||||
import urllib
|
import urllib
|
||||||
import six
|
|
||||||
import allmydata # for __full_version__
|
import allmydata # for __full_version__
|
||||||
|
|
||||||
from allmydata.util.encodingutil import quote_output
|
from allmydata.util.encodingutil import quote_output
|
||||||
@ -44,7 +43,7 @@ class BadResponse(object):
|
|||||||
def do_http(method, url, body=b""):
|
def do_http(method, url, body=b""):
|
||||||
if isinstance(body, bytes):
|
if isinstance(body, bytes):
|
||||||
body = BytesIO(body)
|
body = BytesIO(body)
|
||||||
elif isinstance(body, six.text_type):
|
elif isinstance(body, str):
|
||||||
raise TypeError("do_http body must be a bytestring, not unicode")
|
raise TypeError("do_http body must be a bytestring, not unicode")
|
||||||
else:
|
else:
|
||||||
# We must give a Content-Length header to twisted.web, otherwise it
|
# We must give a Content-Length header to twisted.web, otherwise it
|
||||||
@ -87,16 +86,14 @@ def do_http(method, url, body=b""):
|
|||||||
|
|
||||||
|
|
||||||
def format_http_success(resp):
|
def format_http_success(resp):
|
||||||
# ensure_text() shouldn't be necessary when Python 2 is dropped.
|
|
||||||
return quote_output(
|
return quote_output(
|
||||||
"%s %s" % (resp.status, six.ensure_text(resp.reason)),
|
"%s %s" % (resp.status, resp.reason),
|
||||||
quotemarks=False)
|
quotemarks=False)
|
||||||
|
|
||||||
def format_http_error(msg, resp):
|
def format_http_error(msg, resp):
|
||||||
# ensure_text() shouldn't be necessary when Python 2 is dropped.
|
|
||||||
return quote_output(
|
return quote_output(
|
||||||
"%s: %s %s\n%s" % (msg, resp.status, six.ensure_text(resp.reason),
|
"%s: %s %s\n%s" % (msg, resp.status, resp.reason,
|
||||||
six.ensure_text(resp.read())),
|
resp.read()),
|
||||||
quotemarks=False)
|
quotemarks=False)
|
||||||
|
|
||||||
def check_http_error(resp, stderr):
|
def check_http_error(resp, stderr):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user