Skip to content
Snippets Groups Projects
Commit 80af8eaf authored by Bruce Flynn's avatar Bruce Flynn
Browse files

crio: py3 compat

parent c92c99a7
No related branches found
No related tags found
No related merge requests found
"""PDS construction record input and output"""
import ctypes as c
import numbers
from edosl0util.headers import BaseStruct, DaySegmentedTimecode
......@@ -51,7 +51,9 @@ def read(cr_file):
def read_struct(f, struct):
rv = struct_to_dict(struct.from_buffer_copy(f.read(c.sizeof(struct))))
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
return {k: int(v) if isinstance(v, numbers.Integral) else v for k, v in
rv.items()} # no longs
return main()
......@@ -88,7 +90,13 @@ def write(cr, out_file):
def write_struct(data, struct, out):
fields = [f[0] for f in struct._fields_]
struct_data = {k: v for k, v in data.items() if k in fields}
struct_data = {}
for k, v in data.items():
if k in fields:
if isinstance(v, str):
struct_data[k] = v.encode('utf-8')
else:
struct_data[k] = v
out.write(memoryview(struct(**struct_data)))
main()
......
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