11#! /usr/bin/env python
22
3- import httplib
3+ import sys
4+ if sys .version_info > (3 ,):
5+ import http .client as httplib
6+ else :
7+ import httplib
48import rospy
59import unittest
610import time
@@ -48,17 +52,17 @@ def test_default_action(self):
4852 self .conn .request ("GET" , "/a_static_response" )
4953 response = self .conn .getresponse ()
5054 self .assertEqual (200 , response .status )
51- self .assertEqual ("A RESPONSE" , response .read ())
55+ self .assertEqual (b "A RESPONSE" , response .read ())
5256
5357 def test_http_echo1 (self ):
54- test_content = "hello HELLO" * 1000 # make sure to exceed MTU
58+ test_content = b "hello HELLO"* 1000 # make sure to exceed MTU
5559 self .conn .request ("GET" , "/http_body_echo" , test_content )
5660 response = self .conn .getresponse ()
5761 self .assertEqual (200 , response .status )
5862 self .assertEqual (test_content , response .read ())
5963
6064 def test_http_echo2 (self ):
61- test_content = "THIS is A test" * 1000 # make sure to exceed MTU
65+ test_content = b "THIS is A test"* 1000 # make sure to exceed MTU
6266 self .conn .request ("POST" , "/http_body_echo" , test_content )
6367 response = self .conn .getresponse ()
6468 self .assertEqual (200 , response .status )
@@ -68,25 +72,25 @@ def test_http_path_echo(self):
6872 self .conn .request ("GET" , "/http_path_echo/this_is_a_test" )
6973 response = self .conn .getresponse ()
7074 self .assertEqual (200 , response .status )
71- self .assertEqual ("/http_path_echo/this_is_a_test" , response .read ())
75+ self .assertEqual (b "/http_path_echo/this_is_a_test" , response .read ())
7276
7377 def test_http_query_echo (self ):
7478 self .conn .request ("GET" , "/http_query_echo?hello=1&b=test&c=10" )
7579 response = self .conn .getresponse ()
7680 self .assertEqual (200 , response .status )
77- self .assertEqual ("b=test\n c=10\n hello=1\n " , response .read ())
81+ self .assertEqual (b "b=test\n c=10\n hello=1\n " , response .read ())
7882
7983 def test_file (self ):
8084 self .conn .request ("GET" , "/test_file" )
8185 response = self .conn .getresponse ()
8286 self .assertEqual (200 , response .status )
83- self .assertEqual ("<html></html>\n " , response .read ())
87+ self .assertEqual (b "<html></html>\n " , response .read ())
8488
8589 def test_file_from_filesystem (self ):
8690 self .conn .request ("GET" , "/test_files/test_dir/test_file.txt" )
8791 response = self .conn .getresponse ()
8892 self .assertEqual (200 , response .status )
89- self .assertEqual ("test\n " , response .read ())
93+ self .assertEqual (b "test\n " , response .read ())
9094
9195 def test_directory_listing_forbidden_from_filesystem1 (self ):
9296 self .conn .request ("GET" , "/test_files/test_dir/" )
0 commit comments