MythTV master
compat.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2# Copyright (c) 2012 Kenneth Reitz.
3
4# Permission to use, copy, modify, and/or distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16"""
17pythoncompat
18"""
19
20
21import sys
22
23# -------
24# Pythons
25# -------
26
27# Syntax sugar.
28_ver = sys.version_info
29
30#: Python 2.x?
31is_py2 = (_ver[0] == 2)
32
33#: Python 3.x?
34is_py3 = (_ver[0] == 3)
35
36# ---------
37# Specifics
38# ---------
39
40if is_py2:
41 from StringIO import StringIO
42 from urllib2 import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\
43 HTTPHandler, build_opener, HTTPError, URLError,\
44 build_opener
45 from httplib import BadStatusLine, HTTPException
46 from urlparse import urlunparse
47 from urllib import urlencode
48
49 bytes = str
50 unicode = unicode
51 basestring = basestring
52elif is_py3:
53 from io import StringIO
54 from urllib.request import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\
55 HTTPHandler, build_opener
56 from urllib.error import HTTPError, URLError
57 from http.client import HTTPException, BadStatusLine
58 from urllib.parse import urlunparse, urlencode
59
60 unicode = str
61 bytes = bytes
62 basestring = (str,bytes)