def _handle_binary_in_string(self, arg): try: if not is_bytes(arg): arg = arg.encode('ASCII') except UnicodeError: raise ValueError('Cannot represent %r as binary.' % arg) return xmlrpclib.Binary(arg)
def _to_string(self, value): if is_unicode(value): return value if is_bytes(value): return value.decode('UTF-8') if is_tuple(value): return f"{value[0]}={value[1]}" raise DataError('Return value must be string.')
def should_be_byte_string(self, item, msg=None): """Fails if the given ``item`` is not a byte string. Use `Should Be Unicode String` if you want to verify the ``item`` is a Unicode string, or `Should Be String` if both Unicode and byte strings are fine. See `Should Be String` for more details about Unicode strings and byte strings. The default error message can be overridden with the optional ``msg`` argument. """ if not is_bytes(item): self._fail(msg, "'%s' is not a byte string.", item)
def _string_contains_binary(self, arg): return (self.binary.search(arg) or is_bytes(arg) and self.non_ascii.search(arg))
def _contains_binary(self, arg): return (self.binary.search(arg) or is_bytes(arg) and not IRONPYTHON and self.non_ascii.search(arg))
def _to_string(self, value): if is_unicode(value): return value if is_bytes(value): return value.decode('UTF-8') raise DataError('Return value must be string.')