当前位置: 首页>>代码示例>>Python>>正文


Python socket.makefile方法代码示例

本文整理汇总了Python中socket.makefile方法的典型用法代码示例。如果您正苦于以下问题:Python socket.makefile方法的具体用法?Python socket.makefile怎么用?Python socket.makefile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket的用法示例。


在下文中一共展示了socket.makefile方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dealloc_warn

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def test_dealloc_warn(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        r = repr(sock)
        with self.assertWarns(ResourceWarning) as cm:
            sock = None
            support.gc_collect()
        self.assertIn(r, str(cm.warning.args[0]))
        # An open socket file object gets dereferenced after the socket
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        f = sock.makefile('rb')
        r = repr(sock)
        sock = None
        support.gc_collect()
        with self.assertWarns(ResourceWarning):
            f = None
            support.gc_collect() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_socket.py

示例2: _makefile

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def _makefile(sock, mode):
        return sock.makefile(mode) 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:4,代码来源:connections.py

示例3: _fast_surrogateescape

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def _fast_surrogateescape(s):
        return s.decode('ascii', 'surrogateescape')

# socket.makefile() in Python 2 is not usable because very inefficient and
# bad behavior about timeout.
# XXX: ._socketio doesn't work under IronPython. 
开发者ID:tp4a,项目名称:teleport,代码行数:8,代码来源:connections.py

示例4: test_name_closed_socketio

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def test_name_closed_socketio(self):
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
            fp = sock.makefile("rb")
            fp.close()
            self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_socket.py

示例5: test_unusable_closed_socketio

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def test_unusable_closed_socketio(self):
        with socket.socket() as sock:
            fp = sock.makefile("rb", buffering=0)
            self.assertTrue(fp.readable())
            self.assertFalse(fp.writable())
            self.assertFalse(fp.seekable())
            fp.close()
            self.assertRaises(ValueError, fp.readable)
            self.assertRaises(ValueError, fp.writable)
            self.assertRaises(ValueError, fp.seekable) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_socket.py

示例6: setUp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def setUp(self):
        self.evt1, self.evt2, self.serv_finished, self.cli_finished = [
            threading.Event() for i in range(4)]
        SocketConnectedTest.setUp(self)
        self.read_file = self.cli_conn.makefile(
            self.read_mode, self.bufsize,
            encoding = self.encoding,
            errors = self.errors,
            newline = self.newline) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_socket.py

示例7: clientSetUp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def clientSetUp(self):
        SocketConnectedTest.clientSetUp(self)
        self.write_file = self.serv_conn.makefile(
            self.write_mode, self.bufsize,
            encoding = self.encoding,
            errors = self.errors,
            newline = self.newline) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_socket.py

示例8: testUnbufferedReadline

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def testUnbufferedReadline(self):
        # Read a line, create a new file object, read another line with it
        line = self.read_file.readline() # first line
        self.assertEqual(line, b"A. " + self.write_msg) # first line
        self.read_file = self.cli_conn.makefile('rb', 0)
        line = self.read_file.readline() # second line
        self.assertEqual(line, b"B. " + self.write_msg) # second line 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_socket.py

示例9: testMakefileClose

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def testMakefileClose(self):
        # The file returned by makefile should keep the socket open...
        self.cli_conn.close()
        msg = self.cli_conn.recv(1024)
        self.assertEqual(msg, self.read_msg)
        # ...until the file is itself closed
        self.read_file.close()
        self.assertRaises(OSError, self.cli_conn.recv, 1024) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_socket.py

示例10: worker

# 需要导入模块: import socket [as 别名]
# 或者: from socket import makefile [as 别名]
def worker(sock, authenticated):
    """
    Called by a worker process after the fork().
    """
    signal.signal(SIGHUP, SIG_DFL)
    signal.signal(SIGCHLD, SIG_DFL)
    signal.signal(SIGTERM, SIG_DFL)
    # restore the handler for SIGINT,
    # it's useful for debugging (show the stacktrace before exit)
    signal.signal(SIGINT, signal.default_int_handler)

    # Read the socket using fdopen instead of socket.makefile() because the latter
    # seems to be very slow; note that we need to dup() the file descriptor because
    # otherwise writes also cause a seek that makes us miss data on the read side.
    infile = os.fdopen(os.dup(sock.fileno()), "rb", 65536)
    outfile = os.fdopen(os.dup(sock.fileno()), "wb", 65536)

    if not authenticated:
        client_secret = UTF8Deserializer().loads(infile)
        if os.environ["PYTHON_WORKER_FACTORY_SECRET"] == client_secret:
            write_with_length("ok".encode("utf-8"), outfile)
            outfile.flush()
        else:
            write_with_length("err".encode("utf-8"), outfile)
            outfile.flush()
            sock.close()
            return 1

    exit_code = 0
    try:
        worker_main(infile, outfile)
    except SystemExit as exc:
        exit_code = compute_real_exit_code(exc.code)
    finally:
        try:
            outfile.flush()
        except Exception:
            pass
    return exit_code 
开发者ID:runawayhorse001,项目名称:LearningApacheSpark,代码行数:41,代码来源:daemon.py


注:本文中的socket.makefile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。