@@ -237,29 +237,30 @@ def serve_static(self, environ, start_response):
237
237
uri = wsgiref .util .request_uri (environ )
238
238
p_uri = urlparse (uri )
239
239
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'
241
241
242
242
if os .path .isdir (f_path ):
243
243
f_path = os .path .join (f_path , self .site .config ['INDEX_FILE' ])
244
244
245
245
if p_uri .path == '/robots.txt' :
246
- start_response (b '200 OK' , [(b 'Content-type' , 'txt /plain' )])
247
- return ''' User-Agent: *\n Disallow: /\n '''
246
+ start_response ('200 OK' , [('Content-type' , 'text /plain' )])
247
+ return [ ' User-Agent: *\n Disallow: /\n ']
248
248
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 ())]
252
252
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 ))]
258
258
259
259
def inject_js (self , mimetype , data ):
260
260
"""Inject livereload.js in HTML files."""
261
261
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' )
263
264
return data
264
265
265
266
@@ -275,7 +276,7 @@ def __init__(self, *a, **kw):
275
276
super (LRSocket , self ).__init__ (* a , ** kw )
276
277
277
278
def received_message (self , message ):
278
- message = json .loads (message .data )
279
+ message = json .loads (message .data . decode ( 'utf8' ) )
279
280
self .logger .info ('<--- {0}' .format (message ))
280
281
response = None
281
282
if message ['command' ] == 'hello' : # Handshake
0 commit comments