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


Python socket._fileobject方法代码示例

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


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

示例1: testClose

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def testClose(self):
        class MockSocket:
            closed = False
            def flush(self): pass
            def close(self): self.closed = True

        # must not close unless we request it: the original use of _fileobject
        # by module socket requires that the underlying socket not be closed until
        # the _socketobject that created the _fileobject is closed
        s = MockSocket()
        f = socket._fileobject(s)
        f.close()
        self.assertTrue(not s.closed)

        s = MockSocket()
        f = socket._fileobject(s, close=True)
        f.close()
        self.assertTrue(s.closed) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_socket.py

示例2: test_close

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def test_close(self):
        import httplib

        # calling .close() on urllib2's response objects should close the
        # underlying socket

        # delve deep into response to fetch socket._socketobject
        response = _urlopen_with_retry("http://www.example.com/")
        abused_fileobject = response.fp
        self.assertIs(abused_fileobject.__class__, socket._fileobject)
        httpresponse = abused_fileobject._sock
        self.assertIs(httpresponse.__class__, httplib.HTTPResponse)
        fileobject = httpresponse.fp
        self.assertIs(fileobject.__class__, socket._fileobject)

        self.assertTrue(not fileobject.closed)
        response.close()
        self.assertTrue(fileobject.closed) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:test_urllib2net.py

示例3: makefile

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:5,代码来源:pyopenssl.py

示例4: makefile

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def makefile(self, mode, bufsize):
            return socket._fileobject(self.__conn, mode, bufsize) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:4,代码来源:httpserver.py

示例5: makefile

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def makefile(self, mode='r', bufsize=-1):

        """Make and return a file-like object that
        works with the SSL connection.  Just use the code
        from the socket module."""

        self._makefile_refs += 1
        # close=True so as to decrement the reference count when done with
        # the file-like object.
        return _fileobject(self, mode, bufsize, close=True) 
开发者ID:glmcdona,项目名称:meddle,代码行数:12,代码来源:ssl.py

示例6: _test_readline

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def _test_readline(self, size=-1, **kwargs):
        mock_sock = self.MockSocket(recv_funcs=[
                lambda : "This is the first line\nAnd the sec",
                self._raise_eintr,
                lambda : "ond line is here\n",
                lambda : "",
            ])
        fo = socket._fileobject(mock_sock, **kwargs)
        self.assertEqual(fo.readline(size), "This is the first line\n")
        self.assertEqual(fo.readline(size), "And the second line is here\n") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_socket.py

示例7: _test_read

# 需要导入模块: import socket [as 别名]
# 或者: from socket import _fileobject [as 别名]
def _test_read(self, size=-1, **kwargs):
        mock_sock = self.MockSocket(recv_funcs=[
                lambda : "This is the first line\nAnd the sec",
                self._raise_eintr,
                lambda : "ond line is here\n",
                lambda : "",
            ])
        fo = socket._fileobject(mock_sock, **kwargs)
        self.assertEqual(fo.read(size), "This is the first line\n"
                          "And the second line is here\n") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_socket.py


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