Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_caption_error_for_invalid_or_unsupported_positioning_units(self):
invalid_dfxp = (
SAMPLE_DFXP_INVALID_POSITIONING_VALUE_TEMPLATE
.format(origin="6foo 7bar")
)
self.assertRaises(
CaptionReadSyntaxError, DFXPReader().read,
invalid_dfxp
)
def get_current_position(self):
"""Returns the currently tracked positioning, the last positioning that
was set (anywhere), or the default it was initiated with
:rtype: tuple[int]
"""
try:
return (
super(DefaultProvidingPositionTracker, self).
get_current_position()
)
except CaptionReadSyntaxError:
return self.default
def _parse_timestamp(self, timestamp):
"""Returns an integer representing a number of microseconds
:rtype: int
"""
m = TIMESTAMP_PATTERN.search(timestamp)
if not m:
raise CaptionReadSyntaxError(
'Invalid timing format.')
m = m.groups()
if m[2]:
# Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
return microseconds(m[0], m[1], m[2].replace(":", ""), m[3])
else:
# Timestamp takes the form of [minutes]:[seconds].[milliseconds]
return microseconds(0, m[0], m[1], m[3])
def _validate_timings(self, start, end, last_start_time):
if start is None:
raise CaptionReadSyntaxError(
'Invalid cue start timestamp.')
if end is None:
raise CaptionReadSyntaxError('Invalid cue end timestamp.')
if start > end:
raise CaptionReadError(
'End timestamp is not greater than start timestamp.')
if start < last_start_time:
raise CaptionReadError(
'Start timestamp is not greater than or equal'
'to start timestamp of previous cue.')
if not styling_tag:
return result
reference = style.get('style')
if reference:
referenced_styles = styling_tag.findChildren(
'style', {'xml:id': reference}
)
if len(referenced_styles) == 1:
return result + cls._get_style_reference_chain(
referenced_styles[0], styling_tag
)
elif len(referenced_styles) > 1:
raise CaptionReadSyntaxError(
"Invalid caption file. "
"More than 1 style with 'xml:id': {id}"
.format(id=reference)
)
return result
def feed(self, data):
"""
:param data: Raw SAMI unicode string
:returns: tuple (unicode, dict, set)
"""
no_cc = 'no closed captioning available'
if '")
self.styles = self._css_parse(
BeautifulSoup(data[:index], "lxml").find('style').get_text())
except AttributeError:
self.styles = {}
# fix erroneous italics tags
data = data.replace('<i>', '<i>')
# fix awkward tags found in some SAMIs
data = data.replace(';>', '>')</i></i>
if '-->' in line:
found_timing = True
timing_line = i
last_start_time = captions[-1].start if captions else 0
try:
start, end, layout_info = self._parse_timing_line(
line, last_start_time)
except CaptionReadError as e:
new_message = '%s (line %d)' % (e.args[0], timing_line)
six.reraise(type(e), type(e)(new_message), sys.exc_info()[2])
elif '' == line:
if found_timing:
if not nodes:
raise CaptionReadSyntaxError(
'Cue without content. (line %d)' % timing_line)
else:
found_timing = False
caption = Caption(
start, end, nodes, layout_info=layout_info)
captions.append(caption)
nodes = []
else:
if found_timing:
if nodes:
nodes.append(CaptionNode.create_break())
nodes.append(CaptionNode.create_text(
self._decode(line)))
else:
# it's a comment or some metadata; ignore it
pass
def feed(self, data):
"""
:param data: Raw SAMI unicode string
:returns: tuple (unicode, dict, set)
"""
no_cc = 'no closed captioning available'
if '")
self.styles = self._css_parse(
BeautifulSoup(data[:index], "lxml").find('style').get_text())
except AttributeError:
self.styles = {}
# fix erroneous italics tags
data = data.replace('<i>', '<i>')</i></i>