| 1 | import sys |
| 2 | |
| 3 | # Library compatibility |
| 4 | if sys.version[0] == "2": |
| 5 | from HTMLParser import HTMLParser |
| 6 | from urllib2 import URLError |
| 7 | else: |
| 8 | from html.parser import HTMLParser |
| 9 | from urllib.error import URLError |
| 10 | |
| 11 | unescape = HTMLParser().unescape |
| 12 | # According to https://github.com/python/cpython/blob/master/Lib/html/parser.py#L547 , |
| 13 | # in python 3.5 maybe I should use |
| 14 | # from html import unescape |
| 15 | # but it is a far-future story:) |
| 16 | |
| 17 | |
| 18 | # Function compatibility |
| 19 | # xrange, raw_input, map ,unicde |
| 20 | if sys.version[0] == "2": |
| 21 | lmap = lambda f, a: map(f, a) |
| 22 | str2u = lambda x: x.decode('utf-8') |
| 23 | u2str = lambda x: x.encode('utf-8') |
| 24 | else: |
| 25 | xrange = range |
| 26 | raw_input = input |
| 27 | lmap = lambda f, a: list(map(f, a)) |
| 28 | str2u = u2str = lambda x: x |