def appendMessage(event, elementDef, properties=None): """ Create a new message and append it to the specified ``event``. Return a :class:`MessageFormatter` to format the last appended message. Args: event (Event): The ``event`` to which the new message will be appended. The ``event`` must be a test :class:`blpapi.Event` created by :meth:`createEvent()`. elementDef (SchemaElementDefinition): Used to verify and encode the contents of the message. properties (MessageProperties): Used to set the metadata properties for the message. Returns: MessageFormatter: The :class:`MessageFormatter` used to format the last appended message. Raises: Exception: If the method fails to append the message. """ if properties is None: properties = MessageProperties() rc, formatter_handle = internals.blpapi_TestUtil_appendMessage( get_handle(event), get_handle(elementDef), get_handle(properties)) _ExceptionUtil.raiseOnError(rc) message_formatter = MessageFormatter(formatter_handle) return message_formatter
def _setElementInt(self, name, value): """ Dispatch method for setting integer types. """ if MIN_32BIT_INT <= value <= MAX_32BIT_INT: _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueInt32( self.__handle, get_handle(name), value)) elif MIN_64BIT_INT <= value <= MAX_64BIT_INT: _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueInt64( self.__handle, get_handle(name), value)) else: raise ValueError("Value is out of element's supported range")
def pushElement(self, name): """ Change the level at which this :class:`MessageFormatter` is operating to the element specified by ``name``. After this returns, the context of the :class:`MessageFormatter` is set to the element specified by ``name`` in the schema and any calls to :meth:`setElement` or meth:`pushElement` are applied at that level. If ``name`` represents an array of scalars then :meth:`appendValue` must be used to add values. If ``name`` represents an array of complex types then :meth:`appendElement()` must be used. Args: name (Name or str): Specifies the :class:`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. """ if isstr(name): name = Name(conv2str(name)) _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_pushElement( self.__handle, get_handle(name)))
def serializeService(service): """ Serialize the provided ``service`` in ``XML`` format. Args: service (Service): The :class:`blpapi.Service` to be serialized. Returns: str: The ``service`` represented as an ``XML`` formatted ``str``. Raises: Exception: If the service can't be serialized successfully. """ service_str = internals.blpapi_TestUtil_serializeServiceHelper( get_handle(service)) return service_str
def createWithUser(cls, user): """Creates an :class:`AuthOptions` instance for User Mode with the Operating System Login (Domain/User), Active Directory, or Email. Args: user (AuthUser): user-specific authorization option. Returns: AuthOptions: Specifies User Mode with the Operating System Login (Domain/User), Active Directory, or Email. The behavior is undefined when ``user`` was created with :meth:`AuthUser.createWithManualOptions` or is ``None``. """ retcode, authOptions_handle = internals \ .blpapi_AuthOptions_create_forUserMode(get_handle(user)) _ExceptionUtil.raiseOnError(retcode) return cls(authOptions_handle)
def createTopic(service, isActive=True): """ Create a valid :class:`blpapi.Topic` with the specified ``service`` to support testing publishers. The expected use case is to support returning a custom :class:`blpapi.Topic` while mocking :meth:`blpapi.ProviderSession.getTopic()` methods. Args: service (Service): The :class:`blpapi.Service` to which the returned :class:`blpapi.Topic` will belong. isActive (bool): Optional. Specifies whether the returned :class:`blpapi.Topic` is active. Returns: Topic: A valid :class:`blpapi.Topic` with the specified ``service``. """ rc, topic_handle = internals.blpapi_TestUtil_createTopic( get_handle(service), isActive) _ExceptionUtil.raiseOnError(rc) topic = Topic(topic_handle, sessions=None) return topic
def createWithUserAndApp(cls, user, appName): """Create an :class:`AuthOptions` instance for User and Application Mode. Args: user (AuthUser): user-specific authorization option. appName (str): app name used for Application Mode. Returns: AuthOptions: an :class:`AuthOptions` that contains the authorization option for the User+Application authorization mode. The behavior is undefined when ``appName`` is ``None`` or ``""``. """ app_handle = AuthOptions._create_app_handle(appName) retcode, authOptions_handle = internals \ .blpapi_AuthOptions_create_forUserAndAppMode(get_handle(user), app_handle) _ExceptionUtil.raiseOnError(retcode) return cls(authOptions_handle, app_handle=app_handle)
def getAdminMessageDefinition(messageName): """ Return the definition for an admin message of the specified ``messageName``. Args: messageName (Name or str): The name of the desired admin message. Returns: SchemaElementDefinition: The element definition for the message specified by ``messageName``. Raises: Exception: If ``messageName`` does not name an admin message. """ if isstr(messageName): messageName = Name(conv2str(messageName)) rc, schema_element_definition_handle = \ internals.blpapi_TestUtil_getAdminMessageDefinition( get_handle(messageName)) _ExceptionUtil.raiseOnError(rc) schema_definition = \ SchemaElementDefinition(schema_element_definition_handle, sessions=None) return schema_definition
def _(self, value): """ Dispatch method for appending `Name` types. """ _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_appendValueFromName( self.__handle, get_handle(value)))
def _setElementStr(self, name, value): """ Dispatch method for setting string types. """ _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueString( self.__handle, get_handle(name), conv2str(value)))
def _(self, name, _): """ Dispatch method for setting `None` types. """ _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueNull( self.__handle, get_handle(name)))
def _(self, name, value): """ Dispatch method for setting `float` types. """ _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueFloat( self.__handle, get_handle(name), value))
def _(self, name, value): """ Dispatch method for setting time types. """ _ExceptionUtil.raiseOnError( internals.blpapi_MessageFormatter_setValueHighPrecisionDatetime( self.__handle, get_handle(name), _DatetimeUtil.convertToBlpapi(value)))