本文整理汇总了Python中circuits.web.Server类的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unixserver
def test_unixserver(manager, watcher, tmpfile):
if pytest.PLATFORM == "win32":
pytest.skip("Unsupported Platform")
server = Server(tmpfile).register(manager)
MakeQuiet().register(server)
assert watcher.wait("ready")
Root().register(server)
assert path.basename(server.host) == "test.sock"
try:
from uhttplib import UnixHTTPConnection
client = UnixHTTPConnection(server.http.base)
client.request("GET", "/")
response = client.getresponse()
s = response.read()
assert s == b"Hello World!"
except ImportError:
pass
server.unregister()
watcher.wait("unregistered")
示例2: CircuitsWebAdapter
class CircuitsWebAdapter(object):
class Root(Controller):
def index(self):
return "circuits"
def eventSub(self):
return "\n"
def setup(self, host, port, app_callback):
self._server = Server((host,port))
self._server += Gateway(app_callback)
self._server += self.Root()
sfile = StaticFile('test.flac', '/mnt/nas/Anastacia/Anastacia/03 Time.flac')
self._tree = {}
self._tree[sfile.name] = sfile
def start(self):
self._server.start()
def stop(self):
self._server.stop()
def application(self, environ, start_response):
if environ['SCRIPT_NAME'] == '/':
environ['SCRIPT_NAME'] = ''
environ['PATH_INFO'] = '/' + environ['PATH_INFO']
oldenviron = environ.copy()
path = wsgiref.util.shift_path_info(environ)
return self._tree[path].application(environ, start_response)
示例3: CircuitsWebAdapter
class CircuitsWebAdapter(AdapterInterface):
""" circuits.web WSGI server adapter.
"""
def setup(self, server_name, host, port, app_callback):
from circuits.web import BaseServer, Server
from circuits.lib.web.wsgi import Gateway
from circuits.web import Controller
# self._server = BaseServer(port, host)
self._server = Server(port, host)
self._server += Gateway(app_callback)
self._server += Root()
# self._server += Test()
# self._server += eventsub()
# self._server += handler()
def start(self):
self._server.start()
def stop(self):
self._server.stop()
@classmethod
def is_available(cls):
try:
from circuits.web import BaseServer
from circuits.web import Controller
from circuits.lib.web.wsgi import Gateway
return True
except:
return False
示例4: __init__
def __init__(self):
Server.__init__(self, (listen, port))
Static(docroot="../html/").register(self)
DartsWSServer().register(self)
DartsServerController().register(self)
Root().register(self)
#Logger().register(Webserver)
WebSockets("/websocket").register(self)
示例5: main
def main():
config = Config()
manager = Manager()
if config.get("debug"):
manager += Debugger(events=config.get("verbose"), file=config.get("errorlog"))
environ = Environment(config)
SignalHandler(environ).register(environ)
manager += environ
if config.get("sock") is not None:
bind = config.get("sock")
elif ":" in config.get("bind"):
address, port = config.get("bind").split(":")
bind = (address, int(port))
else:
bind = (config.get("bind"), config.get("port"))
server = Server(bind) + Sessions() + Root(environ) + CacheControl(environ) + ErrorHandler(environ)
if MemoryMonitor is not None:
MemoryMonitor(channel="/memory").register(server)
if not config.get("disable-logging"):
server += Logger(file=config.get("accesslog", sys.stdout))
if not config.get("disable-static"):
server += Static(docroot=os.path.join(config.get("theme"), "htdocs"))
if not config.get("disable-hgweb"):
baseui = ui()
baseui.setconfig("web", "prefix", "/+hg")
baseui.setconfig("web", "style", "gitweb")
baseui.setconfig("web", "allow_push", "*")
baseui.setconfig("web", "push_ssl", False)
baseui.setconfig("web", "allow_archive", ["bz2", "gz", "zip"])
baseui.setconfig("web", "description", config.get("description"))
server += Gateway({"/+hg": hgweb(environ.storage.repo_path, config.get("name"), baseui)})
if not config.get("disable-compression"):
server += Compression(environ)
if config.get("daemon"):
manager += Daemon(config.get("pidfile"))
server.register(manager)
manager.run()
示例6: main
def main():
app = Server(("0.0.0.0", 8000))
Root().register(app)
Static(docroot="static").register(app)
env = Environment(loader=FileSystemLoader("templates"))
JinjaRenderer(env, defaults).register(app)
Sessions().register(app)
# LoginManager().register(app)
app.run()
示例7: setup
def setup(self, host, port, app_callback):
self._server = Server((host,port))
self._server += Gateway(app_callback)
self._server += self.Root()
sfile = StaticFile('test.flac', '/mnt/nas/Anastacia/Anastacia/03 Time.flac')
self._tree = {}
self._tree[sfile.name] = sfile
示例8: test_unixserver
def test_unixserver(manager, watcher, tmpdir):
if pytest.PLATFORM == "win32":
pytest.skip("Unsupported Platform")
sockpath = tmpdir.ensure("test.sock")
socket = str(sockpath)
server = Server(socket).register(manager)
MakeQuiet().register(server)
watcher.wait("ready")
Root().register(server)
assert path.basename(server.host) == "test.sock"
server.unregister()
watcher.wait("unregistered")
示例9: test
def test(apps):
server = Server(0)
Gateway(apps).register(server)
waiter = pytest.WaitEvent(server, "ready")
server.start()
waiter.wait()
f = urlopen(server.http.base)
s = f.read()
assert s == b"Hello World!"
f = urlopen("{0:s}/foobar/".format(server.http.base))
s = f.read()
assert s == b"FooBar!"
server.stop()
示例10: setup
def setup(self, server_name, host, port, app_callback):
from circuits.web import BaseServer, Server
from circuits.lib.web.wsgi import Gateway
from circuits.web import Controller
# self._server = BaseServer(port, host)
self._server = Server(port, host)
self._server += Gateway(app_callback)
self._server += Root()
示例11: test_server
def test_server(manager, watcher):
server = Server(0).register(manager)
MakeQuiet().register(server)
watcher.wait("ready")
Root().register(server)
try:
f = urlopen(server.http.base)
except URLError as e:
if isinstance(e.reason, gaierror):
f = urlopen("http://127.0.0.1:9000")
else:
raise
s = f.read()
assert s == b"Hello World!"
server.unregister()
watcher.wait("unregistered")
示例12: test_secure_server
def test_secure_server(manager, watcher):
pytest.importorskip("ssl")
server = Server(0, secure=True, certfile=CERTFILE).register(manager)
MakeQuiet().register(server)
watcher.wait("ready")
Root().register(server)
try:
f = urlopen(server.http.base, context=SSL_CONTEXT)
except URLError as e:
if isinstance(e.reason, gaierror):
f = urlopen("http://127.0.0.1:9000")
else:
raise
s = f.read()
assert s == b"Hello World!"
server.unregister()
watcher.wait("unregistered")
示例13: __init__
def __init__(self):
Server.__init__(self, "0.0.0.0:%d" % PORT) #"localhost", PORT)
self + WebController() + Static(docroot=SHOTPATH)
示例14: run
def run():
port = os.environ.get("PORT", 8000)
app = Server(("0.0.0.0", int(port)))
Root().register(app)
app.run()
示例15: Root
HTML = """\
<html>
<head>
<title>An example application</title>
</head>
<body>
<h1>This is my sample application</h1>
Put the content here...
<hr>
<a href="/exit">Quit</a>
</body>
</html>
"""
class Root(Controller):
def index(self):
return HTML
def exit(self):
raise SystemExit(0)
app = Server(("0.0.0.0", 8000))
Root().register(app)
app.start()
webbrowser.open("http://127.0.0.1:8000/")
app.join()