Commit 22af8200 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: Make py3 API available on py2.

Standard library was reorganized (urlparse => urllib, httplib => http...) in PEP
3108. install_aliases() from `future` egg provides module aliases so that
imports work on both python2 and python3.
parent 68baa37c
# Modules aliases to support both python2 and python3
from future import standard_library
standard_library.install_aliases()
import argparse import argparse
from io import BytesIO from io import BytesIO
import logging import logging
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# #
############################################################################## ##############################################################################
import six
import copy import copy
import sys import sys
import types import types
...@@ -307,10 +308,32 @@ import hashlib ...@@ -307,10 +308,32 @@ import hashlib
allow_type(type(hashlib.md5())) allow_type(type(hashlib.md5()))
allow_module('time') allow_module('time')
allow_module('unicodedata') allow_module('unicodedata')
allow_module('urlparse')
import urlparse if six.PY2:
allow_type(urlparse.ParseResult) import urlparse
allow_type(urlparse.SplitResult) allow_module('urlparse')
allow_type(urlparse.ParseResult)
allow_type(urlparse.SplitResult)
ModuleSecurityInfo('urllib').declarePublic(
'urlencode',
'quote', 'unquote',
'quote_plus', 'unquote_plus',
)
# six.PY2 with future.standard_library.install_aliases()
# six.PY3
import urllib.parse
allow_module('urllib.parse')
allow_type(urllib.parse.ParseResult)
allow_type(urllib.parse.SplitResult)
ModuleSecurityInfo('urllib.parse').declarePublic(
'urlencode',
'quote', 'unquote',
'quote_plus', 'unquote_plus',
)
allow_module('struct') allow_module('struct')
ModuleSecurityInfo('os.path').declarePublic( ModuleSecurityInfo('os.path').declarePublic(
...@@ -371,12 +394,6 @@ safe_builtins['__import__'] = guarded_import ...@@ -371,12 +394,6 @@ safe_builtins['__import__'] = guarded_import
ModuleSecurityInfo('transaction').declarePublic('doom') ModuleSecurityInfo('transaction').declarePublic('doom')
ModuleSecurityInfo('urllib').declarePublic(
'urlencode',
'quote', 'unquote',
'quote_plus', 'unquote_plus',
)
import hmac import hmac
allow_module('hmac') allow_module('hmac')
# HMAC does not sub-class object so ContainerAssertions # HMAC does not sub-class object so ContainerAssertions
......
  • (keep)

  • for reference, we did not use this approach and used six.moves, but since future was installed we sometimes used the python3 modules directly (for example we used _thread)

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment