def YggRpcClient(name, outfmt='%s', infmt='%s', matlab=False): r"""Get class for handling requests and response to an RPC Server from a client. Args: name (str): The name of the server queues. outfmt (str, optional): Format string used to format variables in a message sent to the request queue. Defautls to '%s'. infmt (str, optional): Format string used to recover variables from messages received from the response queue. Defautls to '%s'. Returns: :class:.ClientComm: Communication object. """ from yggdrasil.communication import ClientComm if matlab: # pragma: matlab infmt = backwards.decode_escape(infmt) outfmt = backwards.decode_escape(outfmt) icomm_kwargs = dict(format_str=infmt) ocomm_kwargs = dict(format_str=outfmt) out = ClientComm.ClientComm(name, response_kwargs=icomm_kwargs, is_interface=True, recv_timeout=False, matlab=matlab, **ocomm_kwargs) return out
def decode_format(cls, format_str): r"""Method for decoding format strings created in this language. Args: format_str (str): Encoded format string. Returns: str: Decoded format string. """ return backwards.decode_escape(format_str)
def YggAsciiTableOutput(name, fmt, as_array=False, **kwargs): r"""Get class for handling table-like formatted output. Args: name (str): The name of the message queue where output should be sent. fmt (str): A C style format string specifying how each 'row' of output should be formated. This should include the newline character. as_array (bool, optional): If True, send expects and entire array. If False, send expects the entries for one table row. Defaults to False. **kwargs: Additional keyword arguments are passed to YggOutput. Returns: DefaultComm: Communication object. """ if kwargs.get('matlab', False): # pragma: matlab fmt = backwards.decode_escape(fmt) kwargs['serializer_kwargs'] = dict(as_array=as_array, format_str=fmt) return YggOutput(name, **kwargs)
def YggOutput(name, format_str=None, **kwargs): r"""Get class for handling output to a message queue. Args: name (str): The name of the message queue. Combined with the suffix '_OUT', it should match an environment variable containing a message queue key. format_str (str, optional): C style format string that should be used to create a message from a list of python ojbects. Defaults to None and raw string messages are sent. **kwargs: Additional keyword arguments are passed to the underlying comm. Returns: DefaultComm: Communication object. """ if format_str is not None: if kwargs.get('matlab', False): # pragma: matlab format_str = backwards.decode_escape(format_str) kwargs['format_str'] = format_str kwargs.update(direction='send', is_interface=True, recv_timeout=False) return DefaultComm(name, **kwargs)
def test_decode_escape(): r"""Test esscape decoding.""" s = 'hello\\nhello' ans = 'hello\nhello' assert_equal(backwards.decode_escape(s), ans)