Compare commits

..

2 Commits

Author SHA1 Message Date
pictuga f83a4b1430 readabilite: avoid double parsing of html
continuous-integration/drone/push Build was killed Details
2022-01-01 12:36:06 +01:00
pictuga 87d2fe772d wsgi: fix py2 compatibility 2022-01-01 12:35:41 +01:00
2 changed files with 4 additions and 10 deletions

View File

@ -19,19 +19,13 @@ import re
import lxml.etree
import lxml.html
import lxml.html.soupparser
from bs4 import BeautifulSoup
def parse(data, encoding=None):
if encoding:
data = BeautifulSoup(data, 'lxml', from_encoding=encoding).prettify('utf-8')
else:
data = BeautifulSoup(data, 'lxml').prettify('utf-8')
parser = lxml.html.HTMLParser(remove_comments=True, encoding='utf-8')
return lxml.html.fromstring(data, parser=parser)
kwargs = {'from_encoding': encoding} if encoding else {}
return lxml.html.soupparser.fromstring(data, **kwargs)
def count_words(string):

View File

@ -277,7 +277,7 @@ def cgi_handle_request():
class WSGIRequestHandlerRequestUri(wsgiref.simple_server.WSGIRequestHandler):
def get_environ(self):
env = super().get_environ()
env = wsgiref.simple_server.WSGIRequestHandler.get_environ(self)
env['REQUEST_URI'] = self.path
return env