コード例 #1
0
 def setup(self):
     # overriding SocketServer.setup to correctly handle SSL.Connection objects
     conn = self.connection = self.request
     try:
         self.rfile = conn.makefile('rb', self.rbufsize)
         self.wfile = conn.makefile('wb', self.wbufsize)
     except (AttributeError, NotImplementedError):
         if hasattr(conn, 'send') and hasattr(conn, 'recv'):
             # it's an SSL.Connection
             self.rfile = socket._fileobject(conn, "rb", self.rbufsize)
             self.wfile = socket._fileobject(conn, "wb", self.wbufsize)
         else:
             # it's a SSLObject, or a martian
             raise NotImplementedError("wsgi.py doesn't support sockets "\
                                       "of type %s" % type(conn))
コード例 #2
0
ファイル: wsgi.py プロジェクト: inercia/evy
 def setup (self):
     # overriding SocketServer.setup to correctly handle SSL.Connection objects
     conn = self.connection = self.request
     try:
         self.rfile = conn.makefile('rb', self.rbufsize)
         self.wfile = conn.makefile('wb', self.wbufsize)
     except (AttributeError, NotImplementedError):
         if hasattr(conn, 'send') and hasattr(conn, 'recv'):
             # it's an SSL.Connection
             self.rfile = socket._fileobject(conn, "rb", self.rbufsize)
             self.wfile = socket._fileobject(conn, "wb", self.wbufsize)
         else:
             # it's a SSLObject, or a martian
             raise NotImplementedError("wsgi.py doesn't support sockets "\
                                       "of type %s" % type(conn))
コード例 #3
0
 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")
コード例 #4
0
 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")
コード例 #5
0
    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)
コード例 #6
0
 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")
コード例 #7
0
 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")
コード例 #8
0
    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)