1 """
2 BINARY2 VOTable decoding
3
4 BINARY2 is like BINARY, except every record is preceded by a mask which
5 columns are NULL.
6
7 Sorry for gratuituously peeking into the guts of dec_binary here. But well,
8 it's family.
9 """
10
11
12
13
14
15
16
17 from gavo.votable import coding
18 from gavo.votable import common
19 from gavo.votable import dec_binary
20 from gavo.votable.model import VOTable
21
22
24 """returns the source for a function deserializing a BINARY stream.
25
26 tableDefinition is a VOTable.TABLE instance. The function returned
27 expects a file-like object.
28 """
29 source = [
30 "def codec(inF):",
31 " row = []",
32 " try:",
33 " nullMap = nullFlags.getFromFile(inF)",
34 " except IOError:",
35 " return None",
36 ]
37
38 for index, field in enumerate(
39 tableDefinition.iterChildrenOfType(VOTable.FIELD)):
40 source.extend([
41 " try:",]+
42 common.indentList(getLinesFor(field), " ")+[
43 " except common.VOTableError:",
44 " raise",
45 " except:",
46
47 " raise common.BadVOTableLiteral('%s', repr(inF.lastRes))"%(
48 field.datatype),
49 ])
50
51 source.extend([
52 " for index, isNull in enumerate(nullMap):",
53 " if isNull:",
54 " row[index] = None",
55 " return row"])
56 return "\n".join(source)
57
58
63
64
65 getLinesFor = dec_binary.getLinesFor
66