Exemple #1
0
 def process_unicode_body(self, body, bom, charset, ignore_errors, fix_special_entities):
     if ignore_errors:
         errors = 'ignore'
     else:
         errors = 'strict'
     if bom:
         body = body[len(self.bom):]
     else:
         body = body
     if fix_special_entities:
         body = encoding_tools.fix_special_entities(body)
     return body.decode(charset, errors).strip()
Exemple #2
0
 def process_unicode_body(self, body, bom, charset, ignore_errors, fix_special_entities):
     if isinstance(body, unicode):
         #if charset in ('utf-8', 'utf8'):
         #    return body.strip()
         #else:
         #    body = body.encode('utf-8')
         #
         body = body.encode('utf-8')
     if bom:
         body = body[len(self.bom):]
     if fix_special_entities:
         body = encoding_tools.fix_special_entities(body)
     if ignore_errors:
         errors = 'ignore'
     else:
         errors = 'strict'
     return body.decode(charset, errors).strip()
Exemple #3
0
 def process_unicode_body(self, body, bom, charset, ignore_errors,
                          fix_special_entities):
     if isinstance(body, unicode):
         #if charset in ('utf-8', 'utf8'):
         #    return body.strip()
         #else:
         #    body = body.encode('utf-8')
         #
         body = body.encode('utf-8')
     if bom:
         body = body[len(self.bom):]
     if fix_special_entities:
         body = encoding_tools.fix_special_entities(body)
     if ignore_errors:
         errors = 'ignore'
     else:
         errors = 'strict'
     return body.decode(charset, errors).strip()
Exemple #4
0
    def unicode_body(self, ignore_errors=True, fix_special_entities=True):
        """
        Return response body as unicode string.
        """

        if not self._unicode_body:
            if ignore_errors:
                errors = 'ignore'
            else:
                errors = 'strict'
            if self.bom:
                body = self.body[len(self.bom):]
            else:
                body = self.body
            if fix_special_entities:
                body = encoding_tools.fix_special_entities(body)
            ubody = body.decode(self.charset, errors).strip()
            self._unicode_body = ubody
        return self._unicode_body
Exemple #5
0
    def unicode_body(self, ignore_errors=True, fix_special_entities=True):
        """
        Return response body as unicode string.
        """

        if not self._unicode_body:
            if ignore_errors:
                errors = 'ignore'
            else:
                errors = 'strict'
            if self.bom:
                body = self.body[len(self.bom):]
            else:
                body = self.body
            if fix_special_entities:
                body = encoding_tools.fix_special_entities(body)
            ubody = body.decode(self.charset, errors).strip()
            self._unicode_body = ubody
        return self._unicode_body