Parse the values stored in the "ifos" and
"instruments" columns found in many tables. This function is
mostly for internal use by the .instruments properties of the
corresponding row classes. The mapping from input to output is as
follows (rules are applied in order):
input is None --> output is None
input contains "," --> output is set of strings split on
"," with leading and trailing whitespace stripped from each
piece and empty strings removed from the set
input contains "+" --> output is set of strings split on
"+" with leading and trailing whitespace stripped from each
piece and empty strings removed from the set
else, after stripping input of leading and trailing whitespace,
input has an even length greater than two --> output is set of
two-character pieces
input is a non-empty string --> output is a set containing input as
single value
else output is an empty set.
NOTE: the complexity of this algorithm is a consequence of there
being several conventions in use for encoding a set of instruments into
one of these columns; it has been proposed that L.L.W. documents
standardize on the comma-delimited variant of the encodings recognized by
this function, and for this reason the inverse function,
instrumentsproperty.set(), implements that encoding only.
NOTE: to force a string containing an even number of characters to be
interpreted as a single instrument name and not to be be split into
two-character pieces, add a "," character to the end to force
the comma-delimited decoding to be used. instrumentsproperty.set() does
this for you.
Example:
>>> print(instrumentsproperty.get(None))
None
>>> instrumentsproperty.get(u"")
set([])
>>> instrumentsproperty.get(u" , ,,")
set([])
>>> instrumentsproperty.get(u"H1")
set([u'H1'])
>>> instrumentsproperty.get(u"SWIFT")
set([u'SWIFT'])
>>> instrumentsproperty.get(u"H1L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1L1,")
set([u'H1L1'])
>>> instrumentsproperty.get(u"H1,L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1+L1")
set([u'H1', u'L1'])
|