File: compat.py

package info (click to toggle)
webtest 3.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 612 kB
  • sloc: python: 4,576; makefile: 135; javascript: 6
file content (19 lines) | stat: -rw-r--r-- 366 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import unittest  # noqa

try:
    unicode()
except NameError:
    b = bytes

    def u(value):
        if isinstance(value, bytes):
            return value.decode('utf-8')
        return value
else:
    def b(value):
        return str(value)

    def u(value):
        if isinstance(value, unicode):
            return value
        return unicode(value, 'utf-8')