Commits

Martin von Löwis  committed a86c179

Add IPv6 support to the cherrypy entrypoint (cherrypy already
has been supporting IPv6 before).

  • Participants
  • Parent commits a115d42

Comments (0)

Files changed (1)

File paste/script/cherrypy_server.py

         This is the ipaddress to bind to (or a hostname if your
         nameserver is properly configured).  This defaults to
         127.0.0.1, which is not a public interface.
+        0.0.0.0 denotes the wildcard IPv4 address, :: denotes
+        the wildcard IPv6 address. :: also activates dual-stack
+        support on the socket on systems supporting that.
+        host:port notation is also supported ([host]:port for
+        IPv6).
 
     ``port``
 
         is_ssl = True
 
     if not port:
-        if ':' in host:
+        if host.count(':') > 1:
+            # IPv6 address
+            orig = host
+            if host.startswith('['):
+                host, port = host.rsplit(':', 1)
+                if host.endswith(']'):
+                    # [host]:port
+                    host = host[1:-1]
+                else:
+                    raise ValueError, 'Invalid IPv6 [host]:port address: '+orig
+            else:
+                # pure host address, use default port
+                port = 8080
+        elif ':' in host:
+            # IPv4:port
             host, port = host.split(':', 1)
         else:
+            # pure IPv4 address, use default port
             port = 8080
     bind_addr = (host, int(port))
 
             print 'serving on 0.0.0.0:%s view at %s://127.0.0.1:%s' % \
                 (port, protocol, port)
         else:
-            print "serving on %s://%s:%s" % (protocol, host, port)
+            if ':' in host:
+                phost = '['+host+']'
+            else:
+                phost = host
+            print "serving on %s://%s:%s" % (protocol, phost, port)
         server.start()
     except (KeyboardInterrupt, SystemExit):
         server.stop()