Ejemplo n.º 1
0
def _tag(value):
    if isinstance(value, tuple):
        return {' t': [_tag(x) for x in value]}
    elif isinstance(value, uuid.UUID):
        return {' u': value.hex}
    elif isinstance(value, bytes):
        return {' b': b64encode(value).decode('ascii')}
    elif callable(getattr(value, '__html__', None)):
        return {' m': text_type(value.__html__())}
    elif isinstance(value, list):
        return [_tag(x) for x in value]
    elif isinstance(value, datetime):
        return {' d': http_date(value)}
    elif isinstance(value, dict):
        return dict((k, _tag(v)) for k, v in iteritems(value))
    elif isinstance(value, str):
        try:
            return text_type(value)
        except UnicodeError:
            from flask.debughelpers import UnexpectedUnicodeError
            raise UnexpectedUnicodeError(
                u'A byte string with '
                u'non-ASCII data was passed to the session system '
                u'which can only store unicode strings.  Consider '
                u'base64 encoding your string (String was %r)' % value)
    return value
Ejemplo n.º 2
0
 def _tag(value):
     if isinstance(value, CheckerSessionObject):
         return {" ch": dict((k, _tag(v)) for k, v in iteritems(value))}
     elif isinstance(value, MeansTest):
         return {" mt": dict((k, _tag(v)) for k, v in iteritems(value))}
     elif isinstance(value, tuple):
         return {" t": [_tag(x) for x in value]}
     elif isinstance(value, uuid.UUID):
         return {" u": value.hex}
     elif isinstance(value, bytes):
         return {" b": b64encode(value).decode("ascii")}
     elif callable(getattr(value, "__html__", None)):
         return {" m": text_type(value.__html__())}
     elif isinstance(value, list):
         return [_tag(x) for x in value]
     elif isinstance(value, datetime):
         return {" d": http_date(value)}
     elif isinstance(value, dict):
         return dict((k, _tag(v)) for k, v in iteritems(value))
     elif isinstance(value, str):
         try:
             return text_type(value)
         except UnicodeError:
             raise UnexpectedUnicodeError(
                 u"A byte string with "
                 u"non-ASCII data was passed to the session system "
                 u"which can only store unicode strings.  Consider "
                 u"base64 encoding your string (String was %r)" % value)
     return value
 def serialize_string(self, value):
     try:
         return text_type(value)
     except UnicodeError:
         raise UnexpectedUnicodeError(
             u"A byte string with "
             u"non-ASCII data was passed to the session system "
             u"which can only store unicode strings.  Consider "
             u"base64 encoding your string (String was %r)" % value)
Ejemplo n.º 4
0
 def _tag_string(self, value):
     try:
         return text_type(value)
     except UnicodeError:
         from flask.debughelpers import UnexpectedUnicodeError
         raise UnexpectedUnicodeError(u'A byte string with '
             u'non-ASCII data was passed to the session system '
             u'which can only store unicode strings.  Consider '
             u'base64 encoding your string (String was %r)' % value)
Ejemplo n.º 5
0
 def _tag(value):
     if isinstance(value, tuple):
         return {' t': [_tag(x) for x in value]}
     elif callable(getattr(value, '__html__', None)):
         return {' m': unicode(value.__html__())}
     elif isinstance(value, list):
         return [_tag(x) for x in value]
     elif isinstance(value, datetime):
         return {' d': http_date(value)}
     elif isinstance(value, dict):
         return dict((k, _tag(v)) for k, v in value.iteritems())
     elif isinstance(value, str):
         try:
             return unicode(value)
         except UnicodeError:
             raise UnexpectedUnicodeError(
                 u'A byte string with '
                 u'non-ASCII data was passed to the session system '
                 u'which can only store unicode strings.  Consider '
                 u'base64 encoding your string (String was %r)' % value)
     return value