Python socket._fileobject() Examples

The following are 30 code examples of socket._fileobject(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module socket , or try the search function .
Example #1
Source File: test_socket.py    From BinderFilter with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: test_socket.py    From oss-ftp with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: test_urllib2net.py    From oss-ftp with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: test_socket.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: pyopenssl.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #6
Source File: securetransport.py    From wow-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #7
Source File: pyopenssl.py    From wow-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #8
Source File: pyopenssl.py    From oss-ftp with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #9
Source File: securetransport.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #10
Source File: securetransport.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #11
Source File: securetransport.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #12
Source File: pyopenssl.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #13
Source File: securetransport.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #14
Source File: securetransport.py    From anpr with Creative Commons Attribution 4.0 International 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #15
Source File: pyopenssl.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #16
Source File: pyopenssl.py    From anpr with Creative Commons Attribution 4.0 International 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #17
Source File: pyopenssl.py    From oss-ftp with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #18
Source File: test_socket.py    From BinderFilter with MIT License 5 votes vote down vote up
def _test_readline_no_buffer(self, size=-1):
        mock_sock = self.MockSocket(recv_funcs=[
                lambda : "aa",
                lambda : "\n",
                lambda : "BB",
                self._raise_eintr,
                lambda : "bb",
                lambda : "",
            ])
        fo = socket._fileobject(mock_sock, bufsize=0)
        self.assertEqual(fo.readline(size), "aa\n")
        self.assertEqual(fo.readline(size), "BBbb") 
Example #19
Source File: test_socket.py    From BinderFilter with MIT License 5 votes vote down vote up
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") 
Example #20
Source File: test_socket.py    From BinderFilter with MIT License 5 votes vote down vote up
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") 
Example #21
Source File: ssl.py    From BinderFilter with MIT License 5 votes vote down vote up
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) 
Example #22
Source File: __init__.py    From nightmare with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.bytes_read = 0
        self.bytes_written = 0
        socket._fileobject.__init__(self, *args, **kwargs) 
Example #23
Source File: pyopenssl.py    From FuYiSpider with Apache License 2.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #24
Source File: securetransport.py    From FuYiSpider with Apache License 2.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #25
Source File: pyopenssl.py    From FuYiSpider with Apache License 2.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #26
Source File: securetransport.py    From FuYiSpider with Apache License 2.0 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #27
Source File: pyopenssl.py    From Yuki-Chan-The-Auto-Pentest with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #28
Source File: pyopenssl.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #29
Source File: pyopenssl.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True) 
Example #30
Source File: securetransport.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def makefile(self, mode, bufsize=-1):
        self._makefile_refs += 1
        return _fileobject(self, mode, bufsize, close=True)