Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if chunk:
yield TEXT, chunk
if bracket == -1:
break
ptr = bracket
# at least two chars after opening bracket:
bracket = line.find("]", ptr + 2)
if line[ptr + 1] == "/":
yield CLOSE, line[ptr + 2:bracket]
else:
for tag, _, _, tag_open_re in self.tags:
if re.match(tag_open_re, line[ptr:bracket + 1]):
yield OPEN, _tag.Tag(line[ptr + 1:bracket], tag)
break
else:
tag = line[ptr + 1:bracket]
yield OPEN, _tag.Tag(tag, tag)
ptr = bracket + 1
:param tag: tag.Tag
:return: bool
"""
return tag in self.tags
def __repr__(self):
return 'Layer({%s}, %r)' % (', '.join(map(str, self.tags)), self.text)
def __eq__(self, other):
"""
mostly for unittest.
"""
return self.text == other.text and self.tags == other.tags
i_and_c = {tag.Tag('i', 'i'), tag.Tag('c', 'c')}
p_tag = tag.Tag('p', 'p')
def close_tags(stack, tags, layer_index=-1):
"""
close given tags on layer with index `layer_index`.
:param stack: Iterable[Layer]
:param layer_index: int
:param tags: Iterable[tag.Tag]
:return: None
"""
if layer_index == -1:
layer_index = len(stack) - 1
layer = stack[layer_index]
:return: bool
"""
return tag in self.tags
def __repr__(self):
return 'Layer({%s}, %r)' % (', '.join(map(str, self.tags)), self.text)
def __eq__(self, other):
"""
mostly for unittest.
"""
return self.text == other.text and self.tags == other.tags
i_and_c = {tag.Tag('i', 'i'), tag.Tag('c', 'c')}
p_tag = tag.Tag('p', 'p')
def close_tags(stack, tags, layer_index=-1):
"""
close given tags on layer with index `layer_index`.
:param stack: Iterable[Layer]
:param layer_index: int
:param tags: Iterable[tag.Tag]
:return: None
"""
if layer_index == -1:
layer_index = len(stack) - 1
layer = stack[layer_index]
if layer.text:
if bracket == -1:
break
ptr = bracket
# at least two chars after opening bracket:
bracket = line.find("]", ptr + 2)
if line[ptr + 1] == "/":
yield CLOSE, line[ptr + 2:bracket]
else:
for tag, _, _, tag_open_re in self.tags:
if re.match(tag_open_re, line[ptr:bracket + 1]):
yield OPEN, _tag.Tag(line[ptr + 1:bracket], tag)
break
else:
tag = line[ptr + 1:bracket]
yield OPEN, _tag.Tag(tag, tag)
ptr = bracket + 1