File: compat.py

package info (click to toggle)
python-cutadapt 1.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 2,112 kB
  • sloc: python: 4,297; makefile: 166
file content (45 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (3)
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
# coding: utf-8
"""
Minimal Py2/Py3 compatibility library.
"""
from __future__ import print_function, division, absolute_import
import sys
PY3 = sys.version > '3'


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

	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):
			return s.decode('ascii')
		else:
			return s
	from io import StringIO

else:
	def bytes_to_str(s):
		return s

	def str_to_bytes(s):
		return s

	def force_str(s):
		return s

	def next(it):
		return it.next()

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