Skip to content
Permalink
Browse files

Python 3.4 compatibility; asyncio is guaranteed to exist

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 30, 2017
1 parent 4a72631 commit 496a4ad0ccea0c377ffbee1ff284e33fe1865dd6
Showing with 5 additions and 2 deletions.
  1. +5 −2 nikola/plugins/command/auto/__init__.py
@@ -32,8 +32,8 @@
import os
import sys
import subprocess
import asyncio
try:
import asyncio
import aiohttp
from aiohttp import web
from aiohttp.web_urldispatcher import StaticResource
@@ -42,7 +42,7 @@
from aiohttp.web_response import Response
from aiohttp.web_fileresponse import FileResponse
except ImportError:
asyncio = aiohttp = web = unquote = None
aiohttp = web = unquote = None
StaticResource = HTTPNotFound = HTTPForbidden = Response = FileResponse = object

try:
@@ -430,6 +430,9 @@ def handle_file(self, request, filename, from_index=None):
ct, encoding = mimetypes.guess_type(str(filepath))
encoding = encoding or 'utf-8'
if ct == 'text/html' and self.modify_html:
if sys.version_info[0] == 3 and sys.version_info[1] == 4:
# Python 3.4 does not accept pathlib.Path objects in calls to open()
filepath = str(filepath)
with open(filepath, 'r', encoding=encoding) as fh:
text = fh.read()
text = self.transform_html(text)

0 comments on commit 496a4ad

Please sign in to comment.