File: compat_py3.py

package info (click to toggle)
python-sure 1.2.5-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 752 kB
  • ctags: 1,708
  • sloc: python: 2,994; makefile: 53
file content (29 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import six

if six.PY3:
    def compat_repr(object_repr):
        return object_repr
else:
    def compat_repr(object_repr):
        # compat_repr is designed to return all reprs with leading 'u's
        # inserted to make all strings look like unicode strings.
        # This makes testing between py2 and py3 much easier.
        result = ''
        in_quote = False
        curr_quote = None
        for char in object_repr:
            if char in ['"', "'"] and (
                not curr_quote or char == curr_quote):
                if in_quote:
                    # Closing quote
                    curr_quote = None
                    in_quote = False
                else:
                    # Opening quote
                    curr_quote = char
                    result += 'u'
                    in_quote = True
            result += char
        return result

text_type_name = six.text_type().__class__.__name__