File: compat.py

package info (click to toggle)
python-sqt 0.8.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 824 kB
  • sloc: python: 5,964; sh: 38; makefile: 10
file content (37 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (4)
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
"""
Minimal Py2/Py3 compatibility library.
"""
import sys
PY3 = sys.version > '3'


if PY3:
	maketrans = bytes.maketrans
	basestring = str
	zip = zip

	def bytes_to_str(s):
		return s.decode('ascii')

	def str_to_bytes(s):
		return s.encode('ascii')

	def force_str(s):
		if isinstance(s, (bytes, bytearray)):
			return s.decode('ascii')
		else:
			return s

else:
	def bytes_to_str(s):
		return s

	def str_to_bytes(s):
		return s

	def force_str(s):
		return s

	from string import maketrans
	basestring = basestring
	from itertools import izip as zip