2020-10-18 11:00:57 -04:00
|
|
|
from future.utils import PY2
|
2009-02-23 14:19:43 -07:00
|
|
|
|
2017-02-21 13:15:51 -08:00
|
|
|
import treq
|
2020-09-23 16:24:40 -04:00
|
|
|
from twisted.internet.defer import (
|
|
|
|
maybeDeferred,
|
|
|
|
inlineCallbacks,
|
|
|
|
returnValue,
|
|
|
|
)
|
2017-02-21 13:15:51 -08:00
|
|
|
from twisted.web.error import Error
|
2009-02-23 14:19:43 -07:00
|
|
|
|
2020-09-23 16:24:40 -04:00
|
|
|
@inlineCallbacks
|
2017-02-21 13:15:51 -08:00
|
|
|
def do_http(method, url, **kwargs):
|
|
|
|
response = yield treq.request(method, url, persistent=False, **kwargs)
|
|
|
|
body = yield treq.content(response)
|
|
|
|
# TODO: replace this with response.fail_for_status when
|
|
|
|
# https://github.com/twisted/treq/pull/159 has landed
|
|
|
|
if 400 <= response.code < 600:
|
|
|
|
raise Error(response.code, response=body)
|
2020-09-23 16:24:40 -04:00
|
|
|
returnValue(body)
|
|
|
|
|
|
|
|
|
2020-10-18 11:00:57 -04:00
|
|
|
if PY2:
|
|
|
|
# We can only use Nevow on Python 2 and Tahoe-LAFS still *does* use Nevow
|
|
|
|
# so prefer the Nevow-based renderer if we can get it.
|
|
|
|
from .common_nevow import (
|
|
|
|
render,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# However, Tahoe-LAFS *will* use Twisted Web before too much longer so go
|
|
|
|
# ahead and let some tests run against the Twisted Web-based renderer on
|
|
|
|
# Python 3. Later this will become the only codepath.
|
|
|
|
from .common_tweb import (
|
|
|
|
render,
|
|
|
|
)
|