Skip to content

Commit d60e346

Browse files
committedJun 13, 2017
Code style + python 2 cleanup
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent f8622a8 commit d60e346

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed
 

‎nikola/plugins/command/serve.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ def log_message(self, *args):
191191
if self.quiet:
192192
return
193193
else:
194-
# Old-style class in Python 2.7, cannot use super()
195-
return SimpleHTTPRequestHandler.log_message(self, *args)
194+
return super().log_message(self, *args)
196195

197196
# NOTICE: this is a patched version of send_head() to disable all sorts of
198197
# caching. `nikola serve` is a development server, hence caching should

‎nikola/shortcodes.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def _split_shortcodes(data):
306306
return result
307307

308308

309-
def apply_shortcodes(data, registry, site=None, filename=None, raise_exceptions=False, lang=None, extra_context={}):
309+
def apply_shortcodes(data, registry, site=None, filename=None, raise_exceptions=False, lang=None, extra_context=None):
310310
"""Apply Hugo-style shortcodes on data.
311311
312312
{{% 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=
323323
>>> print(apply_shortcodes('==> {{% foo bar=baz %}}some data{{% /foo %}} <==', {'foo': lambda *a, **k: k['bar']+k['data']}))
324324
==> bazsome data <==
325325
"""
326-
empty_string = data[:0] # same string type as data; to make Python 2 happy
326+
if extra_context is None:
327+
extra_context = {}
328+
empty_string = ''
327329
try:
328330
# Split input data into text, shortcodes and shortcode endings
329331
sc_data = _split_shortcodes(data)

‎nikola/utils.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,7 @@ def publish(self, handler):
12911291
"""Publish a feed."""
12921292
if self.xsl_stylesheet_href:
12931293
handler.processingInstruction("xml-stylesheet", 'type="text/xsl" href="{0}" media="all"'.format(self.xsl_stylesheet_href))
1294-
# old-style class in py2
1295-
rss.RSS2.publish(self, handler)
1294+
super().publish(self, handler)
12961295

12971296
def publish_extensions(self, handler):
12981297
"""Publish extensions."""
@@ -1895,10 +1894,7 @@ def load_data(path):
18951894
import html # Python 3.4 and newer
18961895
html_unescape = html.unescape
18971896
except (AttributeError, ImportError):
1898-
try:
1899-
from HTMLParser import HTMLParser # Python 2.7
1900-
except ImportError:
1901-
from html.parser import HTMLParser # Python 3 (up to 3.4)
1897+
from html.parser import HTMLParser # Python 3 (up to 3.4)
19021898

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

0 commit comments

Comments
 (0)
Please sign in to comment.