Skip to content

Commit

Permalink
Python 3.4 compatibility; asyncio is guaranteed to exist
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 30, 2017
1 parent 4a72631 commit 496a4ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nikola/plugins/command/auto/__init__.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 496a4ad

Please sign in to comment.