| Home | Trees | Indices | Help |
|
|---|
|
|
1 """
2 xmlstan elements of VOTable.
3 """
4
5 #c Copyright 2008-2019, the GAVO project
6 #c
7 #c This program is free software, covered by the GNU GPL. See the
8 #c COPYING file in the source distribution.
9
10
11 from gavo import utils
12 from gavo.utils import ElementTree
13 from gavo.utils.stanxml import (
14 Element, registerPrefix, getPrefixInfo, schemaURL, escapePCDATA)
15 from gavo.votable import common
16
17
18 NAMESPACES = {
19 "1.3": "http://www.ivoa.net/xml/VOTable/v1.3",
20 "1.2": "http://www.ivoa.net/xml/VOTable/v1.2",
21 "1.1": "http://www.ivoa.net/xml/VOTable/v1.1",
22 }
23
24 # WARNING: if you change the default version of the VOTables generated,
25 # you'll probably have to adapt them in resources/xsl, too.
26 registerPrefix("vot", NAMESPACES["1.3"], schemaURL("VOTable-1.3.xsd"))
27 registerPrefix("vot2", NAMESPACES["1.2"], schemaURL("VOTable-1.2.xsd"))
28 registerPrefix("vot1", NAMESPACES["1.1"], schemaURL("VOTable-1.1.xsd"))
32 """extra VODML element, slated for VOTable 1.4.
33 """
38
40 _childSequence = ["MODEL", "GLOBALS", "TEMPLATES"]
41
43 _childSequence = ["NAME", "URL"]
44
46 _childSequence = ["INSTANCE"]
47
49 _childSequence = ["INSTANCE"]
50
52 _a_version = None
53
55
59
63
65
67 _a_dmrole = None
68 _childSequence = [
69 "CONSTANT", "COLUMN", "LITERAL", "INSTANCE", "REFERENCE"]
70
75
80
82 _childSequence = ["INSTANCE"]
83
87
90 """The container for VOTable elements.
91 """
95
97 _a_ID = None
98 _a_ref = None
99 _a_name = None
100 _a_ucd = None
101 _a_utype = None
102 _mayBeEmpty = True
103
105 """returns some name-like thing for a FIELD or PARAM.
106 """
107 if self.name:
108 res = self.name
109 elif self.ID:
110 res = self.ID
111 else:
112 res = "%s_%s"%(self.__class__.__name__, "%x"%id(self))
113 return res.encode("ascii", "ignore")
114
116 """returns the description for this element, or an empty string.
117 """
118 try:
119 return self.iterChildrenOfType(VOTable.DESCRIPTION).next().text_
120 except StopIteration:
121 return ""
122
126
128 _a_ref = None
129 _a_arraysize = None
130 _a_datatype = None
131 _a_precision = None
132 _a_ref = None
133 _a_type = None
134 _a_width = None
135 _a_format = None
136
139
142
145
147 """returns the number of items one should expect in value, or
148 None for variable-length arrays.
149 """
150 return common.getLength(self.arraysize)
151
154
156 """sets the null literal of self to val.
157 """
158 valEls = list(self.iterChildrenWithName("VALUES"))
159 if valEls:
160 valEls[0](null=val)
161 else:
162 self[VOTable.VALUES(null=val)]
163
169
171 """An element containing tabular data.
172
173 These are usually serialized using some kind of streaming.
174
175 See votable.tablewriter for details.
176 """
178 raise NotImplementedError("This _ContentElement cannot write yet")
179
180
182 """a base class for both BINARY and BINARY2.
183 """
184 _childSequence = ["STREAM"]
185 encoding = "base64"
186
188 # To be able to write incrementally, encode chunks of multiples
189 # of base64's block size until the stream is finished.
190 blockSize = 57
191 buf, bufFil, flushThreshold = [], 0, blockSize*20
192 file.write('<%s>'%self.name_)
193 file.write('<STREAM encoding="base64">')
194 try:
195 for data in self.iterSerialized():
196 buf.append(data)
197 bufFil += len(data)
198 if bufFil>flushThreshold:
199 curData = ''.join(buf)
200 curBlockLen = (len(curData)//blockSize)*blockSize
201 file.write(curData[:curBlockLen].encode("base64"))
202 buf = [curData[curBlockLen:]]
203 finally:
204 file.write("".join(buf).encode("base64"))
205 file.write("</STREAM>")
206 file.write('</%s>'%self.name_)
207
210
213
215 _mayBeEmpty = True
216 _a_ID = None
217 _a_epoch = None
218 _a_equinox = None
219 _a_system = None
220
222 _mayBeEmpty = True
223 _a_ID = None
224 _a_timescale = None
225 _a_refposition = None
226 _a_timeorigin = None
227
230
233
235 _childSequence = ["INFO", "TABLEDATA", "BINARY", "BINARY2", "FITS"]
236
239
241 _childSequence = [None]
242
244 _childSequence = ["DESCRIPTION", "VALUES", "LINK"]
245
247
249 _childSequence = ["STREAM"]
250
252 _mayBeEmpty = True
253 _a_ref = None
254 _childSequence = ["DESCRIPTION", "PARAM", "FIELDref",
255 "PARAMref", "GROUP"]
256
257
265
267 # a bad hack; TAP mandates INFO items below table, and this is
268 # the least complicated way to force this.
269 name_ = "INFO"
270
272 _a_ID = None
273 _a_action = None
274 _a_content_role = None
275 _name_a_content_role = "content-role"
276 _a_content_type = None
277 _name_a_content_type = "content-type"
278 _a_gref = None
279 _a_href = None
280 _a_name = None
281 _a_value = None
282 _a_title = None
283 _childSequence = []
284 _mayBeEmpty = True
285
286
288 _a_inclusive = None
289 _a_value = None
290 _childSequence = []
291
293 return self.value is None
294
295
297 _a_inclusive = None
298 _a_value = None
299 _childSequence = []
300
302 return self.value is None
303
304
306 _a_name = None
307 _a_value = "" # as with PARAM below
308 _childSequence = ["OPTION"]
309 _mayBeEmpty = True
310
311
313 _mayBeEmpty = True
314 _a_value = "" # supposed to mean "ah, somewhat null"
315 # Needs to be cared for in client code.
316 _childSequence = ["DESCRIPTION", "VALUES", "LINK"]
317
318
320
321
323 _a_ID = None
324 _a_name = None
325 _a_type = None
326 _a_utype = None
327 _childSequence = ["DESCRIPTION", "VODML", "DEFINITIONS",
328 "INFO", "COOSYS", "TIMESYS", "GROUP",
329 "PARAM", "LINK", "TABLE", "INFO_atend", "RESOURCE", "stub"]
330 # (stub for delayed overflow warnings and such)
331
333 outputFile.write(
334 """<INFO name="QUERY_STATUS" value="ERROR">%s</INFO>"""%
335 escapePCDATA("Error while serializing VOTable,"
336 " content is probably incomplete: %s"%
337 utils.safe_str(exception)))
338
339
341 _a_actuate = None
342 _a_encoding = None
343 _a_expires = None
344 _a_href = None
345 _a_rights = None
346 _a_type = None
347 _childSequence = [None]
348
349
351 """A TABLE element.
352
353 If you want to access fields by name (getFieldForName), make sure
354 name and ids are unique.
355 """
356 _a_nrows = None
357 _childSequence = ["DESCRIPTION", "INFO", "GROUP", "FIELD", "PARAM", "LINK",
358 "DATA", "stub"] # (stub for delayed overflow warnings and such)
359
360 _fieldIndex = None
361
362 @utils.memoized
365
367 if self._fieldIndex is None:
368 index = {}
369 for child in self.getFields():
370 if child.name:
371 index[child.name] = child
372 if child.ID:
373 index[child.ID] = child
374 self._fieldIndex = index
375 return self._fieldIndex
376
384
385
398
399
404
405
409
410
419
420
422 _a_ID = None
423 _a_version = "1.3"
424 _prefix = "vot"
425 _supressedPrefix = "vot"
426 _mayBeEmpty = True
427 # The following is for when the xmlstan tree is processed by
428 # tablewriter.write rather than asETree
429 _fixedTagMaterial = ('xmlns="%s" xmlns:xsi="%s"'
430 ' xsi:schemaLocation="%s %s"')%((
431 getPrefixInfo("vot")[0],
432 getPrefixInfo("xsi")[0])
433 +getPrefixInfo("vot"))
434 _childSequence = ["DESCRIPTION", "VODML", "DEFINITIONS", "INFO", "COOSYS",
435 "TIMESYS", "GROUP", "PARAM", "RESOURCE"]
436
437
439 # An incredibly nasty hack that kinda works due to the fact that
440 # all elements here are local -- make this your top-level element
441 # and only use what's legal in VOTable 1.1, and you get a VOTable1.1
442 # conforming document
443 name_ = "VOTABLE"
444 _a_version = "1.1"
445 _prefix = "vot1"
446 _supressedPrefix = "vot1"
447 # The following is for when the xmlstan tree is processed by
448 # tablewriter.write rather than asETree
449 _fixedTagMaterial = ('xmlns="%s" xmlns:xsi="%s"'
450 ' xsi:schemaLocation="%s %s"')%((
451 getPrefixInfo("vot1")[0],
452 getPrefixInfo("xsi")[0])
453 +getPrefixInfo("vot1"))
454
456 # see VOTABLE11
457 name_ = "VOTABLE"
458 _a_version = "1.2"
459 _prefix = "vot2"
460 _supressedPrefix = "vot2"
461 # The following is for when the xmlstan tree is processed by
462 # tablewriter.write rather than asETree
463 _fixedTagMaterial = ('xmlns="%s" xmlns:xsi="%s"'
464 ' xsi:schemaLocation="%s %s"')%((
465 getPrefixInfo("vot1")[0],
466 getPrefixInfo("xsi")[0])
467 +getPrefixInfo("vot2"))
468
472 """returns the VOTable QName for tagName.
473
474 You only need this if you want to search in ElementTrees.
475 """
476 return ElementTree.QName(NAMESPACES[version], tagName)
477
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu May 2 07:29:09 2019 | http://epydoc.sourceforge.net |