File: compathelper.py

package info (click to toggle)
pygobject 3.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,268 kB
  • ctags: 4,864
  • sloc: ansic: 20,813; python: 15,139; sh: 11,845; makefile: 567; xml: 31
file content (69 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys

if sys.version_info >= (3, 0):
    '''
    for tests that need to test long values in python 2

    python 3 does not differentiate between long and int
    and does not supply a long keyword

    instead of testing longs by using values such as 10L
    test writters should do this:

    from compathelper import _long
    _long(10)
    '''
    _long = int

    '''
    for tests that need to test string values in python 2

    python 3 does differentiate between str and bytes
    and does not supply a basestring keyword

    any tests that use basestring should do this:

    from compathelper import _basestring
    isinstance(_basestring, "hello")
    '''
    _basestring = str

    '''
    for tests that need to write to intefaces that take bytes in
    python 3

    python 3 has a seperate bytes type for low level functions like os.write

    python 2 treats these as strings

    any tests that need to write a string of bytes should do something like
    this:

    from compathelper import _bytes
    os.write(_bytes("hello"))
    '''

    _bytes = lambda s: s.encode()

    '''
    for tests that need to write to intefaces that take unicode in
    python 2

    python 3 strings are unicode encoded as UTF-8 so the unicode object
    doesn't exist

    python 2 differs between a string an unicode string and you must specify
    an encoding.  This macro will specify UTF-8 in python 2

    any tests that need to use unicode should do this

    from compathelper import _unicode
    unicode_string = _unicode('this is a unicode string')
    '''

    _unicode = lambda s: str(s)
else:
    _long = long
    _basestring = basestring
    _bytes = str
    _unicode = lambda s: unicode(s, 'UTF-8')