Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if data:
if data[0].isspace():
self.trailing_space = True
if data[-1].isspace():
future_trailing_space = True
data = ' '.join(data.split())
if self.anchor_stack[-1] is None:
style = 'msgtext'
else:
style = 'anchor'
if self.style_stack[-1]:
stylelist = list(self.style_stack[-1])
stylelist.sort()
style = style + ':' + ''.join(stylelist)
self.add_chunk(Chunk((style, data), self.cur_url()))
self.trailing_space = future_trailing_space
def end_para(self):
if self.at_para_start:
self.rval.append([])
else:
self.at_para_start = True
self.trailing_space = False
if self.list_stack:
self.add_chunk(Chunk(' ' * 3 * len(self.list_stack),
self.cur_url()))
def end_list_para(self):
if self.at_para_start:
self.rval.append([])
if self.list_stack:
tag = self.list_stack[-1][0]
if tag == 'ul':
depth = len([t for t in self.list_stack if t[0] == tag])
ul_tags = HTMLChunker.ul_tags
chunk = Chunk('%s ' % (ul_tags[depth % len(ul_tags)]),
self.cur_url())
else:
counter = self.list_stack[-1][1]
self.list_stack[-1] = (tag, counter + 1)
chunk = Chunk("%2d." % counter, self.cur_url())
self.add_chunk(chunk)
else:
self.end_para()
loc = 0
for match in URLRE.finditer(mesg):
if loc < match.start():
rval.append(Chunk(mesg[loc:match.start()], None))
# Turn email addresses into mailto: links
email = match.group("email")
if email and "mailto" not in email:
mailto = "mailto:{}".format(email)
else:
mailto = match.group(1)
rval.append(Chunk(None, mailto))
loc = match.end()
if loc < len(mesg):
rval.append(Chunk(mesg[loc:], None))
return rval
def add_chunk(self, chunk):
if self.at_para_start:
self.rval.append([])
elif self.trailing_space:
self.rval[-1].append(Chunk(' ', self.cur_url()))
self.rval[-1].append(chunk)
self.at_para_start = False
self.trailing_space = False
components."""
rval = []
loc = 0
for match in URLRE.finditer(mesg):
if loc < match.start():
rval.append(Chunk(mesg[loc:match.start()], None))
# Turn email addresses into mailto: links
email = match.group("email")
if email and "mailto" not in email:
mailto = "mailto:{}".format(email)
else:
mailto = match.group(1)
rval.append(Chunk(None, mailto))
loc = match.end()
if loc < len(mesg):
rval.append(Chunk(mesg[loc:], None))
return rval