Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Get the status of all our registered tasks."""
print("AMR status get request received")
return self.gather(self._tasks)
class TaskAPI(RESTApi):
"""REST API which runs a bunch of pseudo tasks, and provides a REST
entity to report their status via HTTP GET."""
def __init__(self, app, config, mount):
RESTApi.__init__(self, app, config, mount)
print("AMR mounting RESTApi app: %s, config: %s, mount: %s" % (app, config, mount))
tasks = [Task() for _ in xrange(0, 10)]
self._add({ "status": Status(app, self, config, mount, tasks) })
print("AMR done mounting the 'status' API")
class TaskTest(webtest.WebCase):
"""Client to verify :class:`TaskAPI` works."""
def setUp(self):
self.h = fake_authz_headers(FAKE_FILE.data)
webtest.WebCase.PORT = PORT
self.engine = cherrypy.engine
self.proc = load_server(self.engine)
print("AMR server loaded")
def tearDown(self):
stop_server(self.proc, self.engine)
def test(self):
h = self.h
h.append(("Accept", "application/json"))
print("AMR headers: %s" % h)
print(self.getPage("/test", headers=h))
def wsgi_server():
"""Set up and tear down a Cheroot WSGI server instance."""
for srv in cheroot_server(cheroot.wsgi.Server):
yield srv
import time
import pytest
from six.moves import http_client
import cheroot.server
from cheroot.test import webtest
import cheroot.wsgi
EPHEMERAL_PORT = 0
NO_INTERFACE = None # Using this or '' will cause an exception
ANY_INTERFACE_IPV4 = '0.0.0.0'
ANY_INTERFACE_IPV6 = '::'
config = {
cheroot.wsgi.Server: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'wsgi_app': None,
},
cheroot.server.HTTPServer: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'gateway': cheroot.server.Gateway,
},
}
def cheroot_server(server_factory):
"""Set up and tear down a Cheroot server instance."""
conf = config[server_factory].copy()
bind_port = conf.pop('bind_addr')[-1]
for interface in ANY_INTERFACE_IPV6, ANY_INTERFACE_IPV4:
def setup(self):
"""
Generate the flask App and prepare the HTTP server.
:return: server host and port tuple
:rtype: ``Tuple[str, int]``
"""
app, _ = generate_interactive_api(self.cfg.ihandler)
self._server = wsgi.Server((self.cfg.host, self.cfg.port), app)
self._server.prepare()
return self._server.bind_addr
def start(self):
d = PathInfoDispatcher({"/": self.app})
self.server = Server(("0.0.0.0", self.proxyport), d)
self.proxy_thread = threading.Thread(target=self.server.start)
self.proxy_thread.daemon = True
self.proxy_thread.start()
BitcoinD.start(self)
# Now that bitcoind is running on the real rpcport, let's tell all
# future callers to talk to the proxyport. We use the bind_addr as a
# signal that the port is bound and accepting connections.
while self.server.bind_addr[1] == 0:
pass
self.proxiedport = self.rpcport
self.rpcport = self.server.bind_addr[1]
logging.debug(
"bitcoind reverse proxy listening on {}, forwarding to {}".format(
self.rpcport, self.proxiedport
)
def wsgi_server():
"""Set up and tear down a Cheroot WSGI server instance."""
for srv in cheroot_server(cheroot.wsgi.Server):
yield srv
import cheroot.server
from cheroot.test import webtest
import cheroot.wsgi
EPHEMERAL_PORT = 0
NO_INTERFACE = None # Using this or '' will cause an exception
ANY_INTERFACE_IPV4 = '0.0.0.0'
ANY_INTERFACE_IPV6 = '::'
config = {
cheroot.wsgi.Server: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'wsgi_app': None,
},
cheroot.server.HTTPServer: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'gateway': cheroot.server.Gateway,
},
}
def cheroot_server(server_factory):
"""Set up and tear down a Cheroot server instance."""
conf = config[server_factory].copy()
bind_port = conf.pop('bind_addr')[-1]
for interface in ANY_INTERFACE_IPV6, ANY_INTERFACE_IPV4:
try:
actual_bind_addr = (interface, bind_port)
httpserver = server_factory( # create it
bind_addr=actual_bind_addr,
import cheroot.server
from cheroot.test import webtest
import cheroot.wsgi
EPHEMERAL_PORT = 0
NO_INTERFACE = None # Using this or '' will cause an exception
ANY_INTERFACE_IPV4 = '0.0.0.0'
ANY_INTERFACE_IPV6 = '::'
config = {
cheroot.wsgi.Server: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'wsgi_app': None,
},
cheroot.server.HTTPServer: {
'bind_addr': (NO_INTERFACE, EPHEMERAL_PORT),
'gateway': cheroot.server.Gateway,
},
}
def cheroot_server(server_factory):
"""Set up and tear down a Cheroot server instance."""
conf = config[server_factory].copy()
bind_port = conf.pop('bind_addr')[-1]
for interface in ANY_INTERFACE_IPV6, ANY_INTERFACE_IPV4:
try:
actual_bind_addr = (interface, bind_port)
httpserver = server_factory( # create it
bind_addr=actual_bind_addr,
def native_server():
"""Set up and tear down a Cheroot HTTP server instance."""
for srv in cheroot_server(cheroot.server.HTTPServer):
yield srv
proc.join(timeout=1)
return proc
def start_server(engine):
webtest.WebCase.PORT = PORT
cherrypy.log.screen = True
engine.start()
engine.block()
def stop_server(proc, engine):
cherrypy.log.screen = True
engine.stop()
proc.terminate()
if __name__ == '__main__':
webtest.main()