improved _compat.py
@@ -11,8 +11,31 @@ if PY2:
from cStringIO import StringIO
import copy_reg as copyreg
from urllib import unquote
+ from HTMLParser import HTMLParser
+ import urlparse
+ from htmlentitydefs import entitydefs, name2codepoint
+ import __builtin__ as builtin
+ import thread
+ import Cookie
+ import urllib2
+ import Queue
+ import ConfigParser as configparser
+ from email.MIMEBase import MIMEBase
+ from email.Header import Header
+ from email import Encoders, Charset
+ from email.MIMEMultipart import MIMEMultipart
+ from email.MIMEText import MIMEText
+ from email.Charset import add_charset, QP as charset_QP
+ from urllib import FancyURLopener, urlencode, urlopen
+ from urllib import quote as urllib_quote, unquote as urllib_unquote, quote_plus as urllib_quote_plus
+ from string import maketrans
+ from types import ClassType
+ import cgi
+ import cookielib
+ from xmlrpclib import ProtocolError
BytesIO = StringIO
reduce = reduce
+ reload = reload
hashlib_md5 = hashlib.md5
iterkeys = lambda d: d.iterkeys()
itervalues = lambda d: d.itervalues()
@@ -21,19 +44,21 @@ if PY2:
string_types = (str, unicode)
text_type = unicode
basestring = basestring
- long = long
xrange = xrange
-
- def implements_iterator(cls):
- cls.next = cls.__next__
- del cls.__next__
- return cls
+ long = long
+ unichr = unichr
+ unicodeT = unicode
def implements_bool(cls):
cls.__nonzero__ = cls.__bool__
del cls.__bool__
return cls
+ def implements_iterator(cls):
+ cls.next = cls.__next__
+ del cls.__next__
+ return cls
+
def to_bytes(obj, charset='utf-8', errors='strict'):
if obj is None:
return None
@@ -47,12 +72,34 @@ if PY2:
if obj is None or isinstance(obj, str):
return obj
return obj.encode(charset, errors)
+
else:
import pickle
from io import StringIO, BytesIO
import copyreg
+ from importlib import reload
from functools import reduce
from urllib.parse import unquote
+ from html.parser import HTMLParser
+ from http import cookies as Cookie
+ from urllib import parse as urlparse
+ from urllib import request as urllib2
+ from html.entities import entitydefs, name2codepoint
+ import builtins as builtin
+ import _thread as thread
+ import configparser
+ import queue as Queue
+ from email.mime.base import MIMEBase
+ from email.mime.multipart import MIMEMultipart
+ from email.mime.text import MIMEText
+ from email import encoders as Encoders
+ from email.header import Header
+ from email.charset import Charset, add_charset, QP as charset_QP
+ from urllib.request import FancyURLopener, urlopen
+ from urllib.parse import quote as urllib_quote, unquote as urllib_unquote, urlencode, quote_plus as urllib_quote_plus
+ from http import cookiejar as cookielib
+ from xmlrpc.client import ProtocolError
+ import html # warning, this is the python3 module and not the web2py html module
hashlib_md5 = lambda s: hashlib.md5(bytes(s, 'utf8'))
iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values())
@@ -61,8 +108,12 @@ else:
string_types = (str,)
text_type = str
basestring = str
- long = int
xrange = range
+ long = int
+ unichr = chr
+ unicodeT = str
+ maketrans = str.maketrans
+ ClassType = type
implements_iterator = _identity
implements_bool = _identity
