Skip to content
Permalink
Browse files

Code style + python 2 cleanup

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 13, 2017
1 parent f8622a8 commit d60e346b441f5f153545c9a3e75aa3b9b312ed2f
Showing with 7 additions and 10 deletions.
  1. +1 −2 nikola/plugins/command/serve.py
  2. +4 −2 nikola/shortcodes.py
  3. +2 −6 nikola/utils.py
@@ -191,8 +191,7 @@ def log_message(self, *args):
if self.quiet:
return
else:
# Old-style class in Python 2.7, cannot use super()
return SimpleHTTPRequestHandler.log_message(self, *args)
return super().log_message(self, *args)

# NOTICE: this is a patched version of send_head() to disable all sorts of
# caching. `nikola serve` is a development server, hence caching should
@@ -306,7 +306,7 @@ def _split_shortcodes(data):
return result


def apply_shortcodes(data, registry, site=None, filename=None, raise_exceptions=False, lang=None, extra_context={}):
def apply_shortcodes(data, registry, site=None, filename=None, raise_exceptions=False, lang=None, extra_context=None):
"""Apply Hugo-style shortcodes on data.
{{% name parameters %}} will end up calling the registered "name" function with the given parameters.
@@ -323,7 +323,9 @@ def apply_shortcodes(data, registry, site=None, filename=None, raise_exceptions=
>>> print(apply_shortcodes('==> {{% foo bar=baz %}}some data{{% /foo %}} <==', {'foo': lambda *a, **k: k['bar']+k['data']}))
==> bazsome data <==
"""
empty_string = data[:0] # same string type as data; to make Python 2 happy
if extra_context is None:
extra_context = {}
empty_string = ''
try:
# Split input data into text, shortcodes and shortcode endings
sc_data = _split_shortcodes(data)
@@ -1291,8 +1291,7 @@ def publish(self, handler):
"""Publish a feed."""
if self.xsl_stylesheet_href:
handler.processingInstruction("xml-stylesheet", 'type="text/xsl" href="{0}" media="all"'.format(self.xsl_stylesheet_href))
# old-style class in py2
rss.RSS2.publish(self, handler)
super().publish(self, handler)

def publish_extensions(self, handler):
"""Publish extensions."""
@@ -1895,10 +1894,7 @@ def load_data(path):
import html # Python 3.4 and newer
html_unescape = html.unescape
except (AttributeError, ImportError):
try:
from HTMLParser import HTMLParser # Python 2.7
except ImportError:
from html.parser import HTMLParser # Python 3 (up to 3.4)
from html.parser import HTMLParser # Python 3 (up to 3.4)

def html_unescape(s):
"""Convert all named and numeric character references in the string s to the corresponding unicode characters."""

0 comments on commit d60e346

Please sign in to comment.
You can’t perform that action at this time.