Пример #1
0
 def text(self):
     """ text will return the unicode string of content,
     see `requests.Response.text`
     """
     if not self.content:
         return str("")
     try:
         content = str(self.content, self.encoding, errors="replace")
     except (LookupError, TypeError):
         content = str(self.content, errors="replace")
     return content
Пример #2
0
    def json(self, **kwargs) -> typing.Optional[dict]:
        """ json will return the bytes of content
        """
        if not self.content:
            return None

        try:
            return self._decode_json(**kwargs)
        except Exception as e:
            raise exc.InvalidResponseException(self.content,
                                               str(e),
                                               request_uuid=self.request_uuid)
Пример #3
0
    def _convert(self, value, name=None):
        if self.strict and not isinstance(value, str):
            self.fail(name, "str", type(value))

        return str(value)
Пример #4
0
def encode_value(v):
    if isinstance(v, bool):
        return "true" if v else "false"
    if isinstance(v, float):
        return str(int(v)) if v % 1 == 0 else str(v)
    return str(v)