Changeset 1528
- Timestamp:
- 12/11/06 20:17:21
- Files:
-
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cpserver.py (modified) (4 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test.py (modified) (11 diffs)
- trunk/cherrypy/test/test_core.py (modified) (4 diffs)
- trunk/cherrypy/test/test_proxy.py (modified) (1 diff)
- trunk/cherrypy/test/test_xmlrpc.py (modified) (1 diff)
- trunk/cherrypy/test/webtest.py (modified) (2 diffs)
- trunk/cherrypy/wsgiserver.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1469 r1528 220 220 host = server.socket_host 221 221 if not host: 222 # The empty string signifies INADDR_ANY. 223 # Look up the host name, which should be 224 # the safest thing to spit out in a URL. 222 225 import socket 223 226 host = socket.gethostname() trunk/cherrypy/_cpserver.py
r1460 r1528 84 84 host = self.socket_host 85 85 port = self.socket_port 86 if not host:87 host = 'localhost'88 86 return httpserver, (host, port) 89 87 … … 182 180 """Raise an error if the given port is not free on the given host.""" 183 181 if not host: 182 # The empty string signifies INADDR_ANY, 183 # which should respond on localhost. 184 184 host = 'localhost' 185 185 port = int(port) … … 209 209 """Wait for the specified port to become free (drop requests).""" 210 210 if not host: 211 # The empty string signifies INADDR_ANY, 212 # which should respond on localhost. 211 213 host = 'localhost' 212 214 … … 227 229 """Wait for the specified port to become active (receive requests).""" 228 230 if not host: 231 # The empty string signifies INADDR_ANY, 232 # which should respond on localhost. 229 233 host = 'localhost' 230 234 trunk/cherrypy/test/helper.py
r1403 r1528 42 42 else: 43 43 port = ":%s" % self.PORT 44 return "%s://%s%s%s" % (self.scheme, self.HOST, port, 44 45 host = self.HOST 46 if not host: 47 # The empty string signifies INADDR_ANY, 48 # which should respond on localhost. 49 host = "127.0.0.1" 50 51 return "%s://%s%s%s" % (self.scheme, host, port, 45 52 self.script_name.rstrip("/")) 46 53 trunk/cherrypy/test/test.py
r1467 r1528 23 23 24 24 def __init__(self, tests=None, server=None, protocol="HTTP/1.1", 25 port=8000, scheme="http", interactive=True ):25 port=8000, scheme="http", interactive=True, host='127.0.0.1'): 26 26 """Constructor to populate the TestHarness instance. 27 27 … … 32 32 self.protocol = protocol 33 33 self.port = port 34 self.host = host 34 35 self.scheme = scheme 35 36 self.interactive = interactive … … 50 51 if isinstance(conf, basestring): 51 52 conf = cherrypy.config._Parser().dict_from_file(conf) 52 baseconf = {'server.socket_host': '127.0.0.1',53 baseconf = {'server.socket_host': self.host, 53 54 'server.socket_port': self.port, 54 55 'server.thread_pool': 10, … … 72 73 from cherrypy.test import helper, webtest 73 74 webtest.WebCase.PORT = self.port 75 webtest.WebCase.HOST = self.host 74 76 webtest.WebCase.harness = self 75 77 helper.CPWebCase.scheme = self.scheme … … 91 93 protocol = "HTTP/1.1" 92 94 port = 8080 95 host = '127.0.0.1' 93 96 cover = False 94 97 profile = False … … 111 114 longopts = ['cover', 'profile', 'validate', 'conquer', 'dumb', 112 115 '1.0', 'ssl', 'help', 113 'basedir=', 'port=', 'server=' ]116 'basedir=', 'port=', 'server=', 'host='] 114 117 longopts.extend(self.available_tests) 115 118 try: … … 144 147 elif o == "--port": 145 148 self.port = int(a) 149 elif o == "--host": 150 self.host = a 146 151 elif o == "--server": 147 152 if a in self.available_servers: … … 170 175 print """CherryPy Test Program 171 176 Usage: 172 test.py --server=* -- port=%s --1.0 --cover --basedir=path --profile --validate --conquer --dumb --tests**173 174 """ % self.__class__.port177 test.py --server=* --host=%s --port=%s --1.0 --cover --basedir=path --profile --validate --conquer --dumb --tests** 178 179 """ % (self.__class__.host, self.__class__.port) 175 180 print ' * servers:' 176 181 for name, val in self.available_servers.iteritems(): … … 182 187 print """ 183 188 189 --host=<name or IP addr>: use a host other than the default (%s). 190 Not yet available with mod_python servers. 184 191 --port=<int>: use a port other than the default (%s) 185 192 --1.0: use HTTP/1.0 servers instead of default HTTP/1.1 … … 192 199 --conquer: use wsgiconq (which uses pyconquer) to trace calls. 193 200 --dumb: turn off the interactive output features. 194 """ % self.__class__.port201 """ % (self.__class__.host, self.__class__.port) 195 202 196 203 print ' ** tests:' … … 319 326 else: 320 327 h = TestHarness(self.tests, self.server, self.protocol, 321 self.port, self.scheme, self.interactive) 328 self.port, self.scheme, self.interactive, 329 self.host) 322 330 323 331 success = h.run(conf) trunk/cherrypy/test/test_core.py
r1433 r1528 297 297 hMap['content-length'] = 18 298 298 hMap['server'] = 'CherryPy headertest' 299 hMap['location'] = ('%s://127.0.0.1:%s/headers/' 300 % (cherrypy.request.remote.port, 299 hMap['location'] = ('%s://%s:%s/headers/' 300 % (cherrypy.request.local.ip, 301 cherrypy.request.local.port, 301 302 cherrypy.request.scheme)) 302 303 … … 481 482 482 483 data = open(log_access_file, "rb").readlines() 483 self.assertEqual(data[0][:15], '127.0.0.1 - - [') 484 485 host = self.HOST 486 if not host: 487 # The empty string signifies INADDR_ANY, 488 # which should respond on localhost. 489 host = "127.0.0.1" 490 intro = '%s - - [' % host 491 492 if not data[0].startswith(intro): 493 self.fail("%r doesn't start with %r" % (data[0], intro)) 484 494 haslength = False 485 495 for k, v in self.headers: … … 496 506 self.fail(line) 497 507 498 self.assertEqual(data[-1][:15], '127.0.0.1 - - [') 508 if not data[-1].startswith(intro): 509 self.fail("%r doesn't start with %r" % (data[-1], intro)) 499 510 haslength = False 500 511 for k, v in self.headers: … … 952 963 lines256 = "x" * 248 953 964 self.getPage("/", 954 headers=[('Host', ' 127.0.0.1:%s' % self.PORT),965 headers=[('Host', '%s:%s' % (self.HOST, self.PORT)), 955 966 ('From', lines256)]) 956 967 trunk/cherrypy/test/test_proxy.py
r1369 r1528 91 91 elif self.scheme == "https" and self.PORT != 443: 92 92 port = ":%s" % self.PORT 93 host = self.HOST 94 if host == '': 95 import socket 96 host = socket.gethostname() 93 97 self.assertEqual(cherrypy.url("/this/new/page", script_name=sn), 94 98 "%s://%s%s%s/this/new/page" 95 % (self.scheme, self.HOST, port, sn))99 % (self.scheme, host, port, sn)) 96 100 97 101 # Test trailing slash (see http://www.cherrypy.org/ticket/562). trunk/cherrypy/test/test_xmlrpc.py
r1431 r1528 96 96 # load the appropriate xmlrpc proxy 97 97 if getattr(self.harness, "scheme", "http") == "https": 98 url = 'https:// localhost:%s/xmlrpc/' % self.PORT98 url = 'https://%s:%s/xmlrpc/' % (self.HOST, self.PORT) 99 99 proxy = xmlrpclib.ServerProxy(url, transport=HTTPSTransport()) 100 100 else: 101 url = 'http:// localhost:%s/xmlrpc/' % self.PORT101 url = 'http://%s:%s/xmlrpc/' % (self.HOST, self.PORT) 102 102 proxy = xmlrpclib.ServerProxy(url) 103 103 trunk/cherrypy/test/webtest.py
r1474 r1528 164 164 165 165 if on: 166 self.HTTP_CONN = cls(self.HOST, self.PORT) 166 host = self.HOST 167 if not host: 168 # The empty string signifies INADDR_ANY, 169 # which should respond on localhost. 170 host = "127.0.0.1" 171 self.HTTP_CONN = cls(host, self.PORT) 167 172 # Automatically re-connect? 168 173 self.HTTP_CONN.auto_open = auto_open … … 182 187 183 188 self.url = url 184 result = openURL(url, headers, method, body, self.HOST, self.PORT, 189 host = self.HOST 190 if not host: 191 # The empty string signifies INADDR_ANY, 192 # which should respond on localhost. 193 host = "127.0.0.1" 194 result = openURL(url, headers, method, body, host, self.PORT, 185 195 self.HTTP_CONN, protocol or self.PROTOCOL) 186 196 self.status, self.headers, self.body = result trunk/cherrypy/wsgiserver.py
r1478 r1528 665 665 # Get the correct address family for our host (allows IPv6 addresses) 666 666 host, port = self.bind_addr 667 flags = 0 668 if host == '': 669 # Despite the socket module docs, using '' does not 670 # allow AI_PASSIVE to work. Passing None instead 671 # returns '0.0.0.0' like we want. 672 host = None 673 flags = socket.AI_PASSIVE 667 674 try: 668 675 info = socket.getaddrinfo(host, port, socket.AF_UNSPEC, 669 socket.SOCK_STREAM )676 socket.SOCK_STREAM, 0, flags) 670 677 except socket.gaierror: 671 678 # Probably a DNS issue. Assume IPv4. … … 756 763 raise 757 764 else: 765 # Note that we're explicitly NOT using AI_PASSIVE, 766 # here, because we want an actual IP to touch. 767 # localhost won't work if we've bound to a public IP, 768 # but it would if we bound to INADDR_ANY via host = ''. 758 769 for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, 759 770 socket.SOCK_STREAM):

