-
Notifications
You must be signed in to change notification settings - Fork 205
/
py23.py
51 lines (37 loc) · 1.06 KB
/
py23.py
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
# -*- coding: utf-8 -*-
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
# License: AGPLv3 s.t. "Commons Clause" – read LICENSE.md for details
# thin compatibility layer to support python 2 and 3
# to avoid an additional dependency on six & others
from __future__ import absolute_import, print_function
import sys
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
text_type = str
binary_type = bytes
def iteritems(d, **kw):
return iter(d.items(**kw))
from urllib.parse import unquote, quote
from html.parser import HTMLParser
import pickle as cPickle
else:
string_types = basestring,
text_type = unicode
binary_type = str
def iteritems(d, **kw):
return d.iteritems(**kw)
from urllib import unquote, quote
from HTMLParser import HTMLParser
import cPickle
def py2decodestr(s):
if PY3:
return s
else:
return s.decode('utf8')
def py2encodestr(s):
if PY3:
return s
else:
return s.encode('utf8')