aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/compat.py
blob: 5bc1c3c05d6202ec15ffc28e7f607207d15cf2b0 (plain)
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
import sys, os

is_py2 = (sys.version_info[0] == 2)
is_py3 = (sys.version_info[0] == 3)
is_win32 = os.name == "nt"

if is_py2:
    input = raw_input
    stdout = sys.stdout
    str = unicode

    def bytes(b, enc="ascii"):
        return str(b)

elif is_py3:
    bytes = bytes
    input = input
    stdout = sys.stdout.buffer
    str = str

try:
    import urllib.request as urllib
except ImportError:
    import urllib2 as urllib

try:
    from urllib.parse import urlparse, parse_qs
except ImportError:
    from urlparse import urlparse, parse_qs

__all__ = ["is_py2", "is_py3", "is_win32", "input", "stdout", "str",
           "bytes", "urllib", "urlparse", "parse_qs"]