Skip to content

Commit 9c4ad91

Browse files
committedJul 2, 2015
Merge pull request #1853 from getnikola/fix-1830
Fix 1830
2 parents 685239d + 7ba2665 commit 9c4ad91

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Features
2323
Bugfixes
2424
--------
2525

26+
* Nikola auto was broken in python 3 (Issue #1830)
2627
* Read configuration when importing into an existing site (Issue #1823)
2728
* Don’t crash on non-UTF-8 files during sitemap generation (Issue #1842)
2829
* Unnecessary rebuilds of yearly archives (Issue #1833)

‎nikola/plugins/command/auto/__init__.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,30 @@ def serve_static(self, environ, start_response):
237237
uri = wsgiref.util.request_uri(environ)
238238
p_uri = urlparse(uri)
239239
f_path = os.path.join(self.site.config['OUTPUT_FOLDER'], *p_uri.path.split('/'))
240-
mimetype = mimetypes.guess_type(uri)[0] or b'text/html'
240+
mimetype = mimetypes.guess_type(uri)[0] or 'text/html'
241241

242242
if os.path.isdir(f_path):
243243
f_path = os.path.join(f_path, self.site.config['INDEX_FILE'])
244244

245245
if p_uri.path == '/robots.txt':
246-
start_response(b'200 OK', [(b'Content-type', 'txt/plain')])
247-
return '''User-Agent: *\nDisallow: /\n'''
246+
start_response('200 OK', [('Content-type', 'text/plain')])
247+
return ['User-Agent: *\nDisallow: /\n']
248248
elif os.path.isfile(f_path):
249-
with open(f_path) as fd:
250-
start_response(b'200 OK', [(b'Content-type', mimetype)])
251-
return self.inject_js(mimetype, fd.read())
249+
with open(f_path, 'rb') as fd:
250+
start_response('200 OK', [('Content-type', mimetype)])
251+
return [self.inject_js(mimetype, fd.read())]
252252
elif p_uri.path == '/livereload.js':
253-
with open(LRJS_PATH) as fd:
254-
start_response(b'200 OK', [(b'Content-type', mimetype)])
255-
return self.inject_js(mimetype, fd.read())
256-
start_response(b'404 ERR', [])
257-
return self.inject_js('text/html', ERROR_N.format(404).format(uri))
253+
with open(LRJS_PATH, 'rb') as fd:
254+
start_response('200 OK', [('Content-type', mimetype)])
255+
return [self.inject_js(mimetype, fd.read())]
256+
start_response('404 ERR', [])
257+
return [self.inject_js('text/html', ERROR_N.format(404).format(uri))]
258258

259259
def inject_js(self, mimetype, data):
260260
"""Inject livereload.js in HTML files."""
261261
if mimetype == 'text/html':
262-
data = re.sub('</head>', self.snippet, data, 1, re.IGNORECASE)
262+
data = re.sub('</head>', self.snippet, data.decode('utf8'), 1, re.IGNORECASE)
263+
data = data.encode('utf8')
263264
return data
264265

265266

@@ -275,7 +276,7 @@ def __init__(self, *a, **kw):
275276
super(LRSocket, self).__init__(*a, **kw)
276277

277278
def received_message(self, message):
278-
message = json.loads(message.data)
279+
message = json.loads(message.data.decode('utf8'))
279280
self.logger.info('<--- {0}'.format(message))
280281
response = None
281282
if message['command'] == 'hello': # Handshake

0 commit comments

Comments
 (0)
Please sign in to comment.