blpapi.test.MessageFormatter
- class blpapi.test.MessageFormatter(handle)
MessageFormatteris used to populate/format a message. It supports writing only once to each field. Attempting to set an already set element will fail.Note that the behavior is undefined if:
A message is formatted with
formatMessageJson()orformatMessageXml()orformatMessageDict()is further formatted.A message formatted with set*() or append*() is further formatted using
formatMessageJson()orformatMessageXml()orformatMessageDict().
Currently, the JSON and XML formatting methods have some known limitations:
The parsers can not differentiate complex field types (sequences, choices, arrays) that are empty with complex field types that are missing / null. These fields are dropped and absent in the message contents.
Enumerations of type “Datetime”, or any “Datetime” element with timezone offset or sub-microsecond precision (e.g. nanoseconds) are not supported.
- appendElement()
Create an array
blpapi.Elementand append it to theblpapi.Elementon which thisMessageFormatteris operating.- Raises
Exception – If the schema of the
blpapi.Messageis flat or the currentblpapi.Elementto which this newblpapi.Elementis being appended is not an array, a sequence or a choice.- Return type
- appendValue(value)
Append the specified
valueto the element on which thisMessageFormatteris operating.
- formatMessageDict(dictMessage)
Format the
blpapi.Messagefrom itsdictrepresentation.- Parameters
dictMessage (
dict) – A dictionary representing the content used to format the message.- Raises
Exception – If the method fails to format the
blpapi.Message.
The behavior is undefined if further formatting is done using this
MessageFormatter.- Return type
- formatMessageJson(jsonMessage)
Format the
blpapi.Messagefrom itsJSONrepresentation.- Parameters
jsonMessage (str) – A
JSON-formattedstrrepresenting the content used to format the message.- Raises
Exception – If the method fails to format the
blpapi.Message.
The behavior is undefined if further formatting is done using this
MessageFormatter.- Return type
- formatMessageXml(xmlMessage)
Format the
blpapi.Messagefrom itsXMLrepresentation.- Parameters
xmlMessage (str) – An
XML-formattedstrrepresenting the content used to format the message.- Raises
Exception – If the method fails to format the
blpapi.Message.
The behavior is undefined if further formatting is done using this
MessageFormatter.- Return type
- popElement()
Undo the most recent call to
pushElement()orappendElement()on thisMessageFormatterand return the context of theMessageFormatterto where it was before the call topushElement()orappendElement(). OncepopElement()has been called, it is invalid to attempt to re-visit the same context.- Return type
- pushElement(name)
Change the level at which this
MessageFormatteris operating to the element specified byname.After this returns, the context of the
MessageFormatteris set to the element specified bynamein the schema and any calls tosetElement()or meth:pushElement are applied at that level.If
namerepresents an array of scalars thenappendValue()must be used to add values.If
namerepresents an array of complex types thenappendElement()must be used.- Parameters
name (
Name) – Specifies theblpapi.Elementon which to operate. The element must identify either a choice, a sequence or an array at the current level of the schema or the behavior is undefined.- Raises
Exception – If the
nameis invalid for the current message or if the element identified bynamehas already been set.
Note
Please use
blpapi.Nameoverstrwhere possible forname.blpapi.Nameobjects should be initialized once and then reused as eachblpapi.Nameinstance refers to an entry in a global static table which grows in an unbounded manner.- Return type
- setElement(name, value)
Set the element with the specified
nameto the specifiedvaluein the currentblpapi.Messagereferenced by thisMessageFormatter.- Parameters
- Raises
Exception – An exception is raised if any of the following are true: - The
nameis invalid for the current message - The element identified bynamehas already been set - Thevaluecannot be assigned to the element identified byname
Note
Please use
blpapi.Nameoverstrwhere possible forname.blpapi.Nameobjects should be initialized once and then reused as eachblpapi.Nameinstance refers to an entry in a global static table which grows in an unbounded manner.- Return type