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


Python netutil.bind_unix_socket方法代碼示例

本文整理匯總了Python中tornado.netutil.bind_unix_socket方法的典型用法代碼示例。如果您正苦於以下問題:Python netutil.bind_unix_socket方法的具體用法?Python netutil.bind_unix_socket怎麽用?Python netutil.bind_unix_socket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.netutil的用法示例。


在下文中一共展示了netutil.bind_unix_socket方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_unix_socket

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def test_unix_socket(self):
        sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        server = HTTPServer(app, io_loop=self.io_loop)
        server.add_socket(sock)
        stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        stream.connect(sockfile, self.stop)
        self.wait()
        stream.write(b"GET /hello HTTP/1.0\r\n\r\n")
        stream.read_until(b"\r\n", self.stop)
        response = self.wait()
        self.assertEqual(response, b"HTTP/1.0 200 OK\r\n")
        stream.read_until(b"\r\n\r\n", self.stop)
        headers = HTTPHeaders.parse(self.wait().decode('latin1'))
        stream.read_bytes(int(headers["Content-Length"]), self.stop)
        body = self.wait()
        self.assertEqual(body, b"Hello world")
        stream.close()
        server.stop() 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:22,代碼來源:httpserver_test.py

示例2: test_unix_socket

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def test_unix_socket(self):
        sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        server = HTTPServer(app, io_loop=self.io_loop)
        server.add_socket(sock)
        stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        stream.connect(sockfile, self.stop)
        self.wait()
        stream.write(b("GET /hello HTTP/1.0\r\n\r\n"))
        stream.read_until(b("\r\n"), self.stop)
        response = self.wait()
        self.assertEqual(response, b("HTTP/1.0 200 OK\r\n"))
        stream.read_until(b("\r\n\r\n"), self.stop)
        headers = HTTPHeaders.parse(self.wait().decode('latin1'))
        stream.read_bytes(int(headers["Content-Length"]), self.stop)
        body = self.wait()
        self.assertEqual(body, b("Hello world"))
        stream.close()
        server.stop() 
開發者ID:omererdem,項目名稱:honeything,代碼行數:22,代碼來源:httpserver_test.py

示例3: cmd_web

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def cmd_web(unix_socket, debug):
    app = make_app(debug=debug)
    server = HTTPServer(app)
    if os.path.exists(unix_socket):
        try:
            r = requests.get('http+unix://{0}'.format(unix_socket.replace('/', '%2F')))
            if r.text.strip() == 'atx.taskqueue':
                print 'Already listening'
                return
        except:
            print 'Unlink unix socket'
            os.unlink(unix_socket)

    socket = bind_unix_socket(unix_socket)
    server.add_socket(socket)
    IOLoop.current().start() 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:18,代碼來源:__main__.py

示例4: setUp

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def setUp(self):
        super(UnixSocketTest, self).setUp()
        self.tmpdir = tempfile.mkdtemp()
        self.sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(self.sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        self.server = HTTPServer(app, io_loop=self.io_loop)
        self.server.add_socket(sock)
        self.stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        self.stream.connect(self.sockfile, self.stop)
        self.wait() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:13,代碼來源:httpserver_test.py

示例5: setUp

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def setUp(self):
        super(UnixSocketTest, self).setUp()
        self.tmpdir = tempfile.mkdtemp()
        self.sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(self.sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        self.server = HTTPServer(app)
        self.server.add_socket(sock)
        self.stream = IOStream(socket.socket(socket.AF_UNIX))
        self.io_loop.run_sync(lambda: self.stream.connect(self.sockfile)) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:httpserver_test.py

示例6: build_listener

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import bind_unix_socket [as 別名]
def build_listener(address, backlog=0):
    """address: tuple ('0.0.0.0', 1234) or unix domain socket path such as '/tmp/tmp.sock'"""

    address_type = get_address_type(address)

    if address_type == 'tcp':
        host, port = address
        socks = netutil.bind_sockets(port, address=host, backlog=backlog)
        return socks

    if address_type == 'uds':
        sock = netutil.bind_unix_socket(address, mode=0o600, backlog=backlog)
        return [sock] 
開發者ID:yoki123,項目名稱:torpc,代碼行數:15,代碼來源:util.py


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