Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ass/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def from_ass(cls, v):
""" Convert a Visual Basic (ASS) color code into an ``Color``.
"""
if not v.startswith("&H"):
raise ValueError("color must start with &H")
raise ValueError("color must start with &H (found '%s')" % v)

rest = int(v[2:], 16)

Expand Down
13 changes: 8 additions & 5 deletions src/ass/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def parse_file(cls, f):

section = None
seen_sections = CaseInsensitiveOrderedDict()
for i, line in enumerate(f):
for i, raw_line in enumerate(f):
if i == 0:
bom_seqeunces = ("\xef\xbb\xbf", "\xff\xfe", "\ufeff")
if any(line.startswith(seq) for seq in bom_seqeunces):
if any(raw_line.startswith(seq) for seq in bom_seqeunces):
raise ValueError("BOM detected. Please open the file with the proper encoding,"
" usually '%s'" % cls.PREFERRED_ENCODING.name)

line = line.strip()
line = raw_line.strip()
if not line or line.startswith(';'):
continue

Expand All @@ -105,15 +105,18 @@ def parse_file(cls, f):
continue

if section is None:
raise ValueError('Content outside of any section.')
raise ValueError("Content outside of any section\n\n%d:%s" % (i+1, raw_line))

if ':' not in line:
# illformed, ignore
continue

type_name, _, line = line.partition(":")
line = line.lstrip()
section.add_line(type_name, line)
try:
section.add_line(type_name, line)
except Exception as e:
raise type(e)("Failed to parse file\n\n%d:%s" % (i+1, raw_line)) from e

# append default sections not present in the parsed file
for section_name, section in doc.sections.items():
Expand Down
2 changes: 1 addition & 1 deletion src/ass/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def add_line(self, type_name, raw_line):
self.field_order = [field.strip() for field in raw_line.split(",")]
else:
if self.line_parsers is not None and type_name.lower() not in self.line_parsers:
raise ValueError("unexpected {} line in {}".format(type_name, self.name))
raise ValueError("unexpected '{}' line in {}".format(type_name, self.name))

parser = (self.line_parsers[type_name.lower()]
if self.line_parsers is not None
Expand Down