Skip to content
Snippets Groups Projects
Commit d830e566 authored by Greg Quinn's avatar Greg Quinn
Browse files

Use crio.ReadError for CR input exceptions

parent 8452a48f
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,10 @@ import numbers
from edosl0util.headers import BaseStruct, DaySegmentedTimecode
class ReadError(ValueError):
"""Unable to parse construction record due to improper format"""
def read(cr_file):
"""Parse a PDS construction record from a file (*00.PDS)"""
......@@ -42,14 +46,17 @@ def read(cr_file):
rv['file_info'].append(d)
extra = f.read()
if extra:
raise ValueError('{} bytes remain after reading CR'.format(len(extra)))
raise ReadError('{} bytes remain after reading CR'.format(len(extra)))
return rv
def read_into_dict(f, struct, data):
data.update(read_struct(f, struct))
def read_struct(f, struct):
rv = struct_to_dict(struct.from_buffer_copy(f.read(c.sizeof(struct))))
buf = f.read(c.sizeof(struct))
if len(buf) < c.sizeof(struct):
raise ReadError('Unexpected EOF reading CR')
rv = struct_to_dict(struct.from_buffer_copy(buf))
rv = {k: v for k, v in rv.items() if not k.startswith('spare_')} # no spare fields
return {k: int(v) if isinstance(v, numbers.Integral) else v for k, v in
rv.items()} # no longs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment