Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 d60e346
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions nikola/plugins/command/serve.py
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions nikola/shortcodes.py
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions nikola/utils.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit d60e346

Please sign in to comment.