use more raw strings to prevent escaping

This commit is contained in:
Eli Schwartz 2019-06-14 03:27:02 -04:00
parent 1f794c4cd2
commit 67f8b23baa
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
2 changed files with 8 additions and 9 deletions

View File

@ -152,16 +152,16 @@ class HTMLConverter(object):
(re.compile('<hr>', re.IGNORECASE), (re.compile('<hr>', re.IGNORECASE),
lambda match : '<span style="page-break-after:always"> </span>'), lambda match : '<span style="page-break-after:always"> </span>'),
# Create header tags # Create header tags
(re.compile('<h2[^><]*?id=BookTitle[^><]*?(align=)*(?(1)(\\w+))*[^><]*?>[^><]*?</h2>', re.IGNORECASE), (re.compile(r'<h2[^><]*?id=BookTitle[^><]*?(align=)*(?(1)(\w+))*[^><]*?>[^><]*?</h2>', re.IGNORECASE),
lambda match : '<h1 id="BookTitle" align="%s">%s</h1>'%(match.group(2) if match.group(2) else 'center', match.group(3))), lambda match : '<h1 id="BookTitle" align="%s">%s</h1>'%(match.group(2) if match.group(2) else 'center', match.group(3))),
(re.compile('<h2[^><]*?id=BookAuthor[^><]*?(align=)*(?(1)(\\w+))*[^><]*?>[^><]*?</h2>', re.IGNORECASE), (re.compile(r'<h2[^><]*?id=BookAuthor[^><]*?(align=)*(?(1)(\w+))*[^><]*?>[^><]*?</h2>', re.IGNORECASE),
lambda match : '<h2 id="BookAuthor" align="%s">%s</h2>'%(match.group(2) if match.group(2) else 'center', match.group(3))), lambda match : '<h2 id="BookAuthor" align="%s">%s</h2>'%(match.group(2) if match.group(2) else 'center', match.group(3))),
(re.compile('<span[^><]*?id=title[^><]*?>(.*?)</span>', re.IGNORECASE|re.DOTALL), (re.compile(r'<span[^><]*?id=title[^><]*?>(.*?)</span>', re.IGNORECASE|re.DOTALL),
lambda match : '<h2 class="title">%s</h2>'%(match.group(1),)), lambda match : '<h2 class="title">%s</h2>'%(match.group(1),)),
(re.compile('<span[^><]*?id=subtitle[^><]*?>(.*?)</span>', re.IGNORECASE|re.DOTALL), (re.compile(r'<span[^><]*?id=subtitle[^><]*?>(.*?)</span>', re.IGNORECASE|re.DOTALL),
lambda match : '<h3 class="subtitle">%s</h3>'%(match.group(1),)), lambda match : '<h3 class="subtitle">%s</h3>'%(match.group(1),)),
# Blank lines # Blank lines
(re.compile('<div[^><]*?>(&nbsp;){4}</div>', re.IGNORECASE), (re.compile(r'<div[^><]*?>(&nbsp;){4}</div>', re.IGNORECASE),
lambda match : '<p></p>'), lambda match : '<p></p>'),
] ]
@ -403,7 +403,7 @@ class HTMLConverter(object):
selector name and the value is a dictionary of properties selector name and the value is a dictionary of properties
""" """
sdict, pdict = {}, {} sdict, pdict = {}, {}
style = re.sub('/\\*.*?\\*/', '', style) # Remove /*...*/ comments style = re.sub(r'/\*.*?\*/', '', style) # Remove /*...*/ comments
for sel in re.findall(HTMLConverter.SELECTOR_PAT, style): for sel in re.findall(HTMLConverter.SELECTOR_PAT, style):
for key in sel[0].split(','): for key in sel[0].split(','):
val = self.parse_style_properties(sel[1]) val = self.parse_style_properties(sel[1])

View File

@ -492,9 +492,8 @@ class LrfFileStream(LrfStreamBase):
def __init__(self, streamFlags, filename): def __init__(self, streamFlags, filename):
LrfStreamBase.__init__(self, streamFlags) LrfStreamBase.__init__(self, streamFlags)
f = open(filename, "rb") with open(filename, "rb") as f:
self.streamData = f.read() self.streamData = f.read()
f.close()
class LrfObject(object): class LrfObject(object):