arrow
[rainbowstream.git] / rainbowstream / py3patch.py
... / ...
CommitLineData
1"""
2 Python 3 supports
3"""
4import sys
5
6# StringIO module
7try:
8 from StringIO import StringIO, BytesIO
9except:
10 from io import StringIO, BytesIO
11
12# HTMLParser module
13if sys.version[0] == "2":
14 from HTMLParser import HTMLParser
15else:
16 from html.parser import HTMLParser
17unescape = HTMLParser().unescape
18# According to https://github.com/python/cpython/blob/master/Lib/html/parser.py#L547 ,
19# in python 3.5 maybe I should use
20# from html import unescape
21# but it is a far-future story:)
22
23# raw_input and map function behaviour
24if sys.version[0] == "2":
25 lmap = lambda f, a: map(f, a)
26 str2u = lambda x: x.decode('utf-8')
27 u2str = lambda x: x.encode('utf-8')
28else:
29 xrange = range
30 raw_input = input
31 lmap = lambda f, a: list(map(f, a))
32 str2u = u2str = lambda x: x