Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/smc_pyutil/smc_pyutil/py23.py
Views: 285
1
# -*- coding: utf-8 -*-
2
3
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
4
# License: AGPLv3 s.t. "Commons Clause" – read LICENSE.md for details
5
6
# thin compatibility layer to support python 2 and 3
7
# to avoid an additional dependency on six & others
8
9
from __future__ import absolute_import, print_function
10
import sys
11
12
PY2 = sys.version_info[0] == 2
13
PY3 = sys.version_info[0] == 3
14
15
if PY3:
16
string_types = str,
17
text_type = str
18
binary_type = bytes
19
20
def iteritems(d, **kw):
21
return iter(d.items(**kw))
22
23
from urllib.parse import unquote, quote
24
from html.parser import HTMLParser
25
import pickle as cPickle
26
27
else:
28
string_types = basestring,
29
text_type = unicode
30
binary_type = str
31
32
def iteritems(d, **kw):
33
return d.iteritems(**kw)
34
35
from urllib import unquote, quote
36
from HTMLParser import HTMLParser
37
import cPickle
38
39
40
def py2decodestr(s):
41
if PY3:
42
return s
43
else:
44
return s.decode('utf8')
45
46
47
def py2encodestr(s):
48
if PY3:
49
return s
50
else:
51
return s.encode('utf8')
52
53