當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。