Skip to content
Permalink
Browse files
fix #1682 -- allow IPv6 in nikola serve
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 4, 2015
1 parent c231f17 commit 27b1cf4cc54ca412a93cb1716d7d5dfe9c4bde0f
Showing with 28 additions and 5 deletions.
  1. +1 −0 CHANGES.txt
  2. +27 −5 nikola/plugins/command/serve.py
@@ -4,6 +4,7 @@ New in master
Features
--------

* Allow IPv6 in `nikola serve` (Issue #1682)
* Set default new site URL to https://example.com/
* Plugins can manipulate task dependencies (Issue #1679)
* LINK_CHECK_WHITELIST now works with output relative and full fs paths
@@ -26,6 +26,7 @@

from __future__ import print_function
import os
import socket
import webbrowser
try:
from BaseHTTPServer import HTTPServer
@@ -38,6 +39,11 @@
from nikola.utils import get_logger


class IPv6Server(HTTPServer):
"""An IPv6 HTTPServer."""
address_family = socket.AF_INET6


class CommandServe(Command):
"""Start test server."""

@@ -53,15 +59,15 @@ class CommandServe(Command):
'long': 'port',
'default': 8000,
'type': int,
'help': 'Port nummber (default: 8000)',
'help': 'Port number (default: 8000)',
},
{
'name': 'address',
'short': 'a',
'long': 'address',
'type': str,
'default': '',
'help': 'Address to bind (default: 0.0.0.0 – all local interfaces)',
'help': 'Address to bind (default: 0.0.0.0 – all local IPv4 interfaces)',
},
{
'name': 'browser',
@@ -70,7 +76,15 @@ class CommandServe(Command):
'type': bool,
'default': False,
'help': 'Open the test server in a web browser',
}
},
{
'name': 'ipv6',
'short': '6',
'long': 'ipv6',
'type': bool,
'default': False,
'help': 'Use IPv6',
},
)

def _execute(self, options, args):
@@ -81,8 +95,16 @@ def _execute(self, options, args):
self.logger.error("Missing '{0}' folder?".format(out_dir))
else:
os.chdir(out_dir)
httpd = HTTPServer((options['address'], options['port']),
OurHTTPRequestHandler)
if '[' in options['address']:
options['address'] = options['address'].strip('[').strip(']')
OurHTTP = IPv6Server
elif options['ipv6']:
OurHTTP = IPv6Server
else:
OurHTTP = HTTPServer

httpd = OurHTTP((options['address'], options['port']),
OurHTTPRequestHandler)
sa = httpd.socket.getsockname()
self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
if options['browser']:

0 comments on commit 27b1cf4

Please sign in to comment.