當前位置: 首頁>>代碼示例>>Python>>正文


Python web.Server類代碼示例

本文整理匯總了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")
開發者ID:ke4roh,項目名稱:circuits,代碼行數:26,代碼來源:test_servers.py

示例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)
開發者ID:Viper525,項目名稱:sonospy,代碼行數:30,代碼來源:web.py

示例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
開發者ID:jimmy2e,項目名稱:Sonar,代碼行數:33,代碼來源:webserver.py

示例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)
開發者ID:webhamster,項目名稱:pidart,代碼行數:8,代碼來源:webserver.py

示例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()
開發者ID:prologic,項目名稱:sahriswiki,代碼行數:53,代碼來源:main.py

示例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()
開發者ID:prologic,項目名稱:circuits_purecss_starter,代碼行數:13,代碼來源:server.py

示例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
開發者ID:Viper525,項目名稱:sonospy,代碼行數:7,代碼來源:web.py

示例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")
開發者ID:drozdovsky,項目名稱:circuits,代碼行數:17,代碼來源:test_servers.py

示例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()
開發者ID:AdricEpic,項目名稱:circuits,代碼行數:17,代碼來源:test_wsgi_gateway_multiple_apps.py

示例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()
開發者ID:jimmy2e,項目名稱:Sonar,代碼行數:8,代碼來源:webserver.py

示例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")
開發者ID:ke4roh,項目名稱:circuits,代碼行數:20,代碼來源:test_servers.py

示例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")
開發者ID:ke4roh,項目名稱:circuits,代碼行數:22,代碼來源:test_servers.py

示例13: __init__

 def __init__(self):
     Server.__init__(self, "0.0.0.0:%d" % PORT) #"localhost", PORT)
     self + WebController() + Static(docroot=SHOTPATH)
開發者ID:Chiru,項目名稱:naali,代碼行數:3,代碼來源:webcontroller.py

示例14: run

def run():
    port = os.environ.get("PORT", 8000)
    app = Server(("0.0.0.0", int(port)))
    Root().register(app)
    app.run()
開發者ID:shyba,項目名稱:todo-circuits,代碼行數:5,代碼來源:__init__.py

示例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()
開發者ID:ke4roh,項目名稱:circuits,代碼行數:30,代碼來源:singleclickandrun.py


注:本文中的circuits.web.Server類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。