Python SocketServer.StreamRequestHandler() Examples

The following are 30 code examples of SocketServer.StreamRequestHandler(). 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 SocketServer , or try the search function .
Example #1
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
Example #2
Source File: standalone.py    From pywebsocket with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setup(self):
        """Override SocketServer.StreamRequestHandler.setup to wrap rfile
        with MemorizingFile.

        This method will be called by BaseRequestHandler's constructor
        before calling BaseHTTPRequestHandler.handle.
        BaseHTTPRequestHandler.handle will call
        BaseHTTPRequestHandler.handle_one_request and it will call
        WebSocketRequestHandler.parse_request.
        """

        # Call superclass's setup to prepare rfile, wfile, etc. See setup
        # definition on the root class SocketServer.StreamRequestHandler to
        # understand what this does.
        CGIHTTPServer.CGIHTTPRequestHandler.setup(self)

        self.rfile = memorizingfile.MemorizingFile(
            self.rfile,
            max_memorized_lines=_MAX_MEMORIZED_LINES) 
Example #3
Source File: test_socketserver.py    From BinderFilter with MIT License 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
Example #4
Source File: test_socketserver.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
Example #5
Source File: test_socketserver.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join()
            close_server(s) 
Example #6
Source File: test_socketserver.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_shutdown_request_called_if_verify_request_false(self):
        # Issue #26309: BaseServer should call shutdown_request even if
        # verify_request is False

        class MyServer(SocketServer.TCPServer):
            def verify_request(self, request, client_address):
                return False

            shutdown_called = 0
            def shutdown_request(self, request):
                self.shutdown_called += 1
                SocketServer.TCPServer.shutdown_request(self, request)

        server = MyServer((HOST, 0), SocketServer.StreamRequestHandler)
        s = socket.socket(server.address_family, socket.SOCK_STREAM)
        s.connect(server.server_address)
        s.close()
        server.handle_request()
        self.assertEqual(server.shutdown_called, 1)
        close_server(server) 
Example #7
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
Example #8
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_shutdown(self):
        # Issue #2302: shutdown() should always succeed in making an
        # other thread leave serve_forever().
        class MyServer(SocketServer.TCPServer):
            pass

        class MyHandler(SocketServer.StreamRequestHandler):
            pass

        threads = []
        for i in range(20):
            s = MyServer((HOST, 0), MyHandler)
            t = threading.Thread(
                name='MyServer serving',
                target=s.serve_forever,
                kwargs={'poll_interval':0.01})
            t.daemon = True  # In case this function raises.
            threads.append((t, s))
        for t, s in threads:
            t.start()
            s.shutdown()
        for t, s in threads:
            t.join() 
Example #9
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_ForkingUnixStreamServer(self):
                with simple_subprocess(self):
                    self.run_server(ForkingUnixStreamServer,
                                    SocketServer.StreamRequestHandler,
                                    self.stream_examine) 
Example #10
Source File: test_imaplib.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_issue5949(self):

        class EOFHandler(SocketServer.StreamRequestHandler):
            def handle(self):
                # EOF without sending a complete welcome message.
                self.wfile.write('* OK')

        with self.reaped_server(EOFHandler) as server:
            self.assertRaises(imaplib.IMAP4.abort,
                              self.imap_class, *server.server_address) 
Example #11
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingUnixStreamServer(self):
            self.run_server(SocketServer.ThreadingUnixStreamServer,
                            SocketServer.StreamRequestHandler,
                            self.stream_examine) 
Example #12
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_ForkingTCPServer(self):
            with simple_subprocess(self):
                self.run_server(SocketServer.ForkingTCPServer,
                                SocketServer.StreamRequestHandler,
                                self.stream_examine) 
Example #13
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #14
Source File: test_socketserver.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_TCPServer(self):
        self.run_server(SocketServer.TCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #15
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_ForkingUnixStreamServer(self):
                with simple_subprocess(self):
                    self.run_server(ForkingUnixStreamServer,
                                    SocketServer.StreamRequestHandler,
                                    self.stream_examine) 
Example #16
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_ForkingTCPServer(self):
            with simple_subprocess(self):
                self.run_server(SocketServer.ForkingTCPServer,
                                SocketServer.StreamRequestHandler,
                                self.stream_examine) 
Example #17
Source File: server.py    From ice with GNU General Public License v3.0 5 votes vote down vote up
def finish(self):
		#print "==> Disconnection from:", self.client_address
		self.server.server.untrack(self)
		
		with self.server.client_lock:
			self.server.clients.remove(self)
		try:
			SocketServer.StreamRequestHandler.finish(self)
		except socket.error, (e, msg):
			#if (e != 32): # Broken pipe
			#	print "==>", self.client_address, "-", msg
			pass 
Example #18
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #19
Source File: test_imaplib.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_issue5949(self):

        class EOFHandler(SocketServer.StreamRequestHandler):
            def handle(self):
                # EOF without sending a complete welcome message.
                self.wfile.write('* OK')

        with self.reaped_server(EOFHandler) as server:
            self.assertRaises(imaplib.IMAP4.abort,
                              self.imap_class, *server.server_address) 
Example #20
Source File: test_imaplib.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_issue5949(self):

        class EOFHandler(SocketServer.StreamRequestHandler):
            def handle(self):
                # EOF without sending a complete welcome message.
                self.wfile.write('* OK')

        with self.reaped_server(EOFHandler) as server:
            self.assertRaises(imaplib.IMAP4.abort,
                              self.imap_class, *server.server_address) 
Example #21
Source File: server.py    From remi with Apache License 2.0 5 votes vote down vote up
def setup(self):
        socketserver.StreamRequestHandler.setup(self)
        self._log.info('connection established: %r' % (self.client_address,))
        self.handshake_done = False 
Example #22
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_TCPServer(self):
        self.run_server(SocketServer.TCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #23
Source File: test_socketserver.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_ThreadingUnixStreamServer(self):
            self.run_server(SocketServer.ThreadingUnixStreamServer,
                            SocketServer.StreamRequestHandler,
                            self.stream_examine) 
Example #24
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_InterruptServerSelectCall(self):
        with self.mocked_select_module() as mock_select:
            pid = self.run_server(SocketServer.TCPServer,
                                  SocketServer.StreamRequestHandler,
                                  self.stream_examine)
            # Make sure select was called again:
            self.assertGreater(mock_select.called, 1)

    # Alas, on Linux (at least) recvfrom() doesn't return a meaningful
    # client address so this cannot work:

    # @requires_unix_sockets
    # def test_UnixDatagramServer(self):
    #     self.run_server(SocketServer.UnixDatagramServer,
    #                     SocketServer.DatagramRequestHandler,
    #                     self.dgram_examine)
    #
    # @requires_unix_sockets
    # def test_ThreadingUnixDatagramServer(self):
    #     self.run_server(SocketServer.ThreadingUnixDatagramServer,
    #                     SocketServer.DatagramRequestHandler,
    #                     self.dgram_examine)
    #
    # @requires_unix_sockets
    # @requires_forking
    # def test_ForkingUnixDatagramServer(self):
    #     self.run_server(SocketServer.ForkingUnixDatagramServer,
    #                     SocketServer.DatagramRequestHandler,
    #                     self.dgram_examine) 
Example #25
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_ThreadingUnixStreamServer(self):
        self.run_server(SocketServer.ThreadingUnixStreamServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #26
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_UnixStreamServer(self):
        self.run_server(SocketServer.UnixStreamServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #27
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_ForkingTCPServer(self):
        with simple_subprocess(self):
            self.run_server(SocketServer.ForkingTCPServer,
                            SocketServer.StreamRequestHandler,
                            self.stream_examine) 
Example #28
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_ThreadingTCPServer(self):
        self.run_server(SocketServer.ThreadingTCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #29
Source File: test_socketserver.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_TCPServer(self):
        self.run_server(SocketServer.TCPServer,
                        SocketServer.StreamRequestHandler,
                        self.stream_examine) 
Example #30
Source File: server.py    From ice with GNU General Public License v3.0 5 votes vote down vote up
def setup(self):
		SocketServer.StreamRequestHandler.setup(self)
		#print "==> Connection from:", self.client_address#, "in thread", threading.currentThread().getName()
		self.request.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
		with self.server.client_lock:
			self.server.clients.append(self)
		self.registration_map = {}