Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1666

Show
Ignore:
Timestamp:
06/16/07 16:58:53
Author:
fumanchu
Message:

Upgraded all INADDR_ANY and localhost checks to include IPv6 equivalents.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpserver.py

    r1665 r1666  
    77import cherrypy 
    88from cherrypy.lib import attributes 
     9 
     10 
     11def client_host(server_host): 
     12    """Return the host on which a client can connect to the given listener.""" 
     13    if server_host == '0.0.0.0': 
     14        # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 
     15        return '127.0.0.1' 
     16    if server_host == '::': 
     17        # :: is IN6ADDR_ANY, which should answer on localhost. 
     18        return '::1' 
     19    return server_host 
    920 
    1021 
     
    5566        doc="""The hostname or IP address on which to listen for connections. 
    5667         
    57         Valid host values include any IPv4 or IPv6 address, any valid 
    58         hostname, 'localhost' as a synonym for '127.0.0.1', and '0.0.0.0' 
    59         as a special entry meaning "all active interfaces" (INADDR_ANY). 
    60         The empty string or None are not allowed.""") 
     68        Host values may be any IPv4 or IPv6 address, or any valid hostname. 
     69        The string 'localhost' is a synonym for '127.0.0.1' (or '::1', if 
     70        your hosts file prefers IPv6). The string '0.0.0.0' is a special 
     71        IPv4 entry meaning "any active interface" (INADDR_ANY), and '::' 
     72        is the similar IN6ADDR_ANY for IPv6. The empty string or None are 
     73        not allowed.""") 
    6174     
    6275    socket_file = '' 
     
    173186            if isinstance(bind_addr, tuple): 
    174187                host, port = bind_addr 
    175                 if host == '0.0.0.0': 
    176                     # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 
    177                     host = 'localhost' 
    178188                wait_for_occupied_port(host, port) 
    179189     
     
    203213         
    204214        host = self.socket_host 
    205         if host == '0.0.0.0': 
    206             # 0.0.0.0 is INADDR_ANY. Look up the host name, 
    207             # which should be the safest thing to spit out in a URL. 
     215        if host in ('0.0.0.0', '::'): 
     216            # 0.0.0.0 is INADDR_ANY and :: is IN6ADDR_ANY. 
     217            # Look up the host name, which should be the 
     218            # safest thing to spit out in a URL. 
    208219            host = socket.gethostname() 
    209220         
     
    226237    if not host: 
    227238        raise ValueError("Host values of '' or None are not allowed.") 
    228     if host == '0.0.0.0': 
    229         # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 
    230         host = 'localhost' 
     239    host = client_host(host) 
    231240    port = int(port) 
    232241     
     
    256265    if not host: 
    257266        raise ValueError("Host values of '' or None are not allowed.") 
    258     if host == '0.0.0.0': 
    259         # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 
    260         host = 'localhost' 
    261267     
    262268    for trial in xrange(50): 
     
    277283    if not host: 
    278284        raise ValueError("Host values of '' or None are not allowed.") 
    279     if host == '0.0.0.0': 
    280         # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 
    281         host = 'localhost' 
    282285     
    283286    for trial in xrange(50): 
  • trunk/cherrypy/test/helper.py

    r1627 r1666  
    4343            port = ":%s" % self.PORT 
    4444         
    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        return "%s://%s%s%s" % (self.scheme, self.HOST, port, 
    5246                                self.script_name.rstrip("/")) 
    5347     
  • trunk/cherrypy/test/test_core.py

    r1665 r1666  
    487487            # INADDR_ANY, which should respond on localhost. 
    488488            host = "127.0.0.1" 
     489        if host == '::': 
     490            # IN6ADDR_ANY, which should respond on localhost. 
     491            host = "::1" 
    489492        intro = '%s - - [' % host 
    490493         
  • trunk/cherrypy/test/test_proxy.py

    r1665 r1666  
    9292                port = ":%s" % self.PORT 
    9393            host = self.HOST 
    94             if host == '0.0.0.0'
     94            if host in ('0.0.0.0', '::')
    9595                import socket 
    9696                host = socket.gethostname() 
  • trunk/cherrypy/test/test_xmlrpc.py

    r1665 r1666  
    116116            # INADDR_ANY, which should respond on localhost. 
    117117            host = "127.0.0.1" 
     118        if host == '::': 
     119            # IN6ADDR_ANY, which should respond on localhost. 
     120            host = "::1" 
    118121         
    119122        if scheme == "https": 
  • trunk/cherrypy/test/webtest.py

    r1665 r1666  
    168168                # INADDR_ANY, which should respond on localhost. 
    169169                host = "127.0.0.1" 
     170            elif host == '::': 
     171                # IN6ADDR_ANY, which should respond on localhost. 
     172                host = "::1" 
    170173            self.HTTP_CONN = cls(host, self.PORT) 
    171174            # Automatically re-connect? 
     
    473476                    # INADDR_ANY, which should respond on localhost. 
    474477                    host = "127.0.0.1" 
     478                elif host == '::': 
     479                    # IN6ADDR_ANY, which should respond on localhost. 
     480                    host = "::1" 
    475481                conn = http_conn(host, port) 
    476482             
  • trunk/cherrypy/wsgiserver/__init__.py

    r1665 r1666  
    731731     
    732732    bind_addr: The interface on which to listen for connections. 
    733         For TCP sockets, a (host, port) tuple. Valid host values include: 
    734         any IPv4 or IPv6 address, any valid hostname, 'localhost' as a 
    735         synonym for '127.0.0.1', and '0.0.0.0' as a special entry meaning 
    736         "all active interfaces" (INADDR_ANY). The empty string or None 
    737         are not allowed. 
     733        For TCP sockets, a (host, port) tuple. Host values may be any IPv4 
     734        or IPv6 address, or any valid hostname. The string 'localhost' is a 
     735        synonym for '127.0.0.1' (or '::1', if your hosts file prefers IPv6). 
     736        The string '0.0.0.0' is a special IPv4 entry meaning "any active 
     737        interface" (INADDR_ANY), and '::' is the similar IN6ADDR_ANY for 
     738        IPv6. The empty string or None are not allowed. 
     739         
    738740        For UNIX sockets, supply the filename as a string. 
    739741    wsgi_app: the WSGI 'application callable'; multiple WSGI applications 
     
    818820            # '0.0.0.0', we deny both the empty string and None as values. 
    819821            raise ValueError("Host values of '' or None are not allowed. " 
    820                              "Use '0.0.0.0' instead to listen on all active
    821                              "interfaces (INADDR_ANY).") 
     822                             "Use '0.0.0.0' (IPv4) or '::' (IPv6) instead
     823                             "to listen on all active interfaces.") 
    822824        self._bind_addr = value 
    823825    bind_addr = property(_get_bind_addr, _set_bind_addr, 
    824826        doc="""The interface on which to listen for connections. 
    825827         
    826         For TCP sockets, a (host, port) tuple. Valid host values include: 
    827         any IPv4 or IPv6 address, any valid hostname, 'localhost' as a 
    828         synonym for '127.0.0.1', and '0.0.0.0' as a special entry meaning 
    829         "all active interfaces" (INADDR_ANY). The empty string or None 
    830         are not allowed. 
     828        For TCP sockets, a (host, port) tuple. Host values may be any IPv4 
     829        or IPv6 address, or any valid hostname. The string 'localhost' is a 
     830        synonym for '127.0.0.1' (or '::1', if your hosts file prefers IPv6). 
     831        The string '0.0.0.0' is a special IPv4 entry meaning "any active 
     832        interface" (INADDR_ANY), and '::' is the similar IN6ADDR_ANY for 
     833        IPv6. The empty string or None are not allowed. 
    831834         
    832835        For UNIX sockets, supply the filename as a string.""") 

Hosted by WebFaction

Log in as guest/cpguest to create tickets