Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)