blpapi.test.MessageFormatter¶
- class blpapi.test.MessageFormatter¶
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.
- appendValue(value)¶
Append the specified
valueto the element on which thisMessageFormatteris operating.- Parameters
value (bool or str or int or float or datetime.date or datetime.time or datetime.datetime or Name) – The value to append.
- Raises
Exception – If the schema of the message is flat or the current element to which
valueis appended is not an array.
- 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.
- 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.
- 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.
- popElement()¶
Undo the most recent call to
pushElement()on thisMessageFormatterand return the context of theMessageFormatterto where it was before the call topushElement(). OncepopElement()has been called, it is invalid to attempt to re-visit the same context.
- 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 or str) – Specifies the
blpapi.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.
- setElement(name, value)¶
Set the element with the specified
nameto the specifiedvaluein the currentblpapi.Messagereferenced by thisMessageFormatter.- Parameters
name (Name or str) – Identifies the element which will be set to
value.value (bool or str or int or float or datetime.date or datetime.time or datetime.datetime or Name or None) – The value to assign to the specified element.
- 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