blpapi.test.MessageFormatter

class blpapi.test.MessageFormatter

MessageFormatter is 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:

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.Element and append it to the blpapi.Element on which this MessageFormatter is operating.

Raises

Exception – If the schema of the blpapi.Message is flat or the current blpapi.Element to which this new blpapi.Element is being appended is not an array, a sequence or a choice.

appendValue(value)

Append the specified value to the element on which this MessageFormatter is 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 value is appended is not an array.

formatMessageDict(dictMessage)

Format the blpapi.Message from its dict representation.

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.Message from its JSON representation.

Parameters

jsonMessage (str) – A JSON-formatted str 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.

formatMessageXml(xmlMessage)

Format the blpapi.Message from its XML representation.

Parameters

xmlMessage (str) – An XML-formatted str 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.

popElement()

Undo the most recent call to pushElement() on this MessageFormatter and return the context of the MessageFormatter to where it was before the call to pushElement(). Once popElement() has been called, it is invalid to attempt to re-visit the same context.

pushElement(name)

Change the level at which this MessageFormatter is operating to the element specified by name.

After this returns, the context of the MessageFormatter is set to the element specified by name in the schema and any calls to setElement() or meth:pushElement are applied at that level.

If name represents an array of scalars then appendValue() must be used to add values.

If name represents an array of complex types then appendElement() must be used.

Parameters

name (Name or str) – Specifies the blpapi.Element on 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 name is invalid for the current message or if the element identified by name has already been set.

setElement(name, value)

Set the element with the specified name to the specified value in the current blpapi.Message referenced by this MessageFormatter.

Parameters
Raises

Exception – An exception is raised if any of the following are true: - The name is invalid for the current message - The element identified by name has already been set - The value cannot be assigned to the element identified by name