Commit 1a5231fc authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: modernize -f imports_six.

parent 70b92ca3
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from urlparse import parse_qsl from six.moves.urllib.parse import parse_qsl
context.REQUEST.RESPONSE.setCookie("loyalty_reward", "disable", path='/') context.REQUEST.RESPONSE.setCookie("loyalty_reward", "disable", path='/')
......
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from urlparse import parse_qsl from six.moves.urllib.parse import parse_qsl
context.REQUEST.RESPONSE.setCookie("loyalty_reward", "enable", path='/') context.REQUEST.RESPONSE.setCookie("loyalty_reward", "enable", path='/')
......
...@@ -150,7 +150,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -150,7 +150,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
return [] return []
def cached_getTargetFormatItemList(content_type): def cached_getTargetFormatItemList(content_type):
from xmlrpclib import Fault from six.moves.xmlrpc_client import Fault
server_proxy = DocumentConversionServerProxy(self) server_proxy = DocumentConversionServerProxy(self)
try: try:
allowed_target_item_list = server_proxy.getAllowedTargetItemList( allowed_target_item_list = server_proxy.getAllowedTargetItemList(
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
import urllib2 import six.moves.urllib.request
from lxml import etree from lxml import etree
from erp5.component.document.Document import ConversionError from erp5.component.document.Document import ConversionError
import base64 import base64
...@@ -36,7 +36,7 @@ SVG_DEFAULT_NAMESPACE = "http://www.w3.org/2000/svg" ...@@ -36,7 +36,7 @@ SVG_DEFAULT_NAMESPACE = "http://www.w3.org/2000/svg"
def getDataURI(url): def getDataURI(url):
try: try:
data = urllib2.urlopen(url) data = six.moves.urllib.request.urlopen(url)
except Exception as e: except Exception as e:
raise ConversionError("Error to transform url (%s) into data uri. ERROR = %s" % (url, Exception(e))) raise ConversionError("Error to transform url (%s) into data uri. ERROR = %s" % (url, Exception(e)))
return 'data:%s;base64,%s' % (data.info()["content-type"], return 'data:%s;base64,%s' % (data.info()["content-type"],
......
...@@ -6,7 +6,7 @@ from six.moves import cStringIO as StringIO ...@@ -6,7 +6,7 @@ from six.moves import cStringIO as StringIO
from erp5.portal_type import Image from erp5.portal_type import Image
from types import ModuleType from types import ModuleType
from ZODB.serialize import ObjectWriter from ZODB.serialize import ObjectWriter
import cPickle import six.moves.cPickle
import sys import sys
import traceback import traceback
import ast import ast
...@@ -589,7 +589,7 @@ def canSerialize(obj): ...@@ -589,7 +589,7 @@ def canSerialize(obj):
# for example: if the user defines a dict with an object of a class # for example: if the user defines a dict with an object of a class
# that he created the dump will stil work, but the load will fail. # that he created the dump will stil work, but the load will fail.
try: try:
cPickle.loads(cPickle.dumps(obj)) six.moves.cPickle.loads(six.moves.cPickle.dumps(obj))
# By unknowing reasons, trying to catch cPickle.PicklingError in the "normal" # By unknowing reasons, trying to catch cPickle.PicklingError in the "normal"
# way isn't working. This issue might be related to some weirdness in # way isn't working. This issue might be related to some weirdness in
# pickle/cPickle that is reported in this issue: http://bugs.python.org/issue1457119. # pickle/cPickle that is reported in this issue: http://bugs.python.org/issue1457119.
...@@ -599,7 +599,7 @@ def canSerialize(obj): ...@@ -599,7 +599,7 @@ def canSerialize(obj):
# #
# Even though the issue seems complicated, this quickfix should be # Even though the issue seems complicated, this quickfix should be
# properly rewritten in a better way as soon as possible. # properly rewritten in a better way as soon as possible.
except (cPickle.PicklingError, TypeError, NameError, AttributeError): except (six.moves.cPickle.PicklingError, TypeError, NameError, AttributeError):
return False return False
else: else:
return True return True
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
############################################################################## ##############################################################################
from Products.ERP5Form.FormBox import FormBox from Products.ERP5Form.FormBox import FormBox
from urlparse import urlparse from six.moves.urllib.parse import urlparse
def Base_updatePropertyMapListWithFieldLabel(self, property_map_list): def Base_updatePropertyMapListWithFieldLabel(self, property_map_list):
"""Try to get the title of field which edit the given inside property_map_list """Try to get the title of field which edit the given inside property_map_list
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
############################################################################## ##############################################################################
import re import re
def getLastWorkflowDate(self, state_name='simulation_state', state=('released','public')): def getLastWorkflowDate(self, state_name='simulation_state', state=('released','public')):
'''we can make something more generic out of it '''we can make something more generic out of it
or JP says "there is an API for it" and we trash this one''' or JP says "there is an API for it" and we trash this one'''
......
from erp5.component.document.Document import ConversionError from erp5.component.document.Document import ConversionError
from erp5.component.module.Log import log from erp5.component.module.Log import log
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from xmlrpclib import Fault from six.moves.xmlrpc_client import Fault
from socket import error as SocketError from socket import error as SocketError
message = None message = None
......
...@@ -28,7 +28,7 @@ try: ...@@ -28,7 +28,7 @@ try:
except ImportError: # BBB Zope2 except ImportError: # BBB Zope2
from Globals import package_home from Globals import package_home
import PIL.Image as PIL_Image import PIL.Image as PIL_Image
import thread import six.moves._thread
import random import random
import base64 import base64
from OFS.Folder import Folder from OFS.Folder import Folder
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# #
############################################################################## ##############################################################################
from HTMLParser import HTMLParser from six.moves.html_parser import HTMLParser
class HtmlParseHelper(HTMLParser): class HtmlParseHelper(HTMLParser):
""" """
Listens to all the HTMLParser methods and push results in a list of tuple. Listens to all the HTMLParser methods and push results in a list of tuple.
......
import json import json
import re import re
from urlparse import urljoin from six.moves.urllib.parse import urljoin
if REQUEST is None: if REQUEST is None:
REQUEST = context.REQUEST REQUEST = context.REQUEST
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
import hashlib, httplib import hashlib, six.moves.http_client
from Products.ERP5Type.UnrestrictedMethod import super_user from Products.ERP5Type.UnrestrictedMethod import super_user
...@@ -110,6 +110,6 @@ def WebSite_viewAsWebPost(self, *args, **kwargs): ...@@ -110,6 +110,6 @@ def WebSite_viewAsWebPost(self, *args, **kwargs):
# security check should be done already. # security check should be done already.
document.publish() document.publish()
self.REQUEST.RESPONSE.setStatus(httplib.CREATED) self.REQUEST.RESPONSE.setStatus(six.moves.http_client.CREATED)
return sha512sum return sha512sum
...@@ -4,7 +4,7 @@ from Products.ERP5Type import Permissions, PropertySheet ...@@ -4,7 +4,7 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
import random, string, hashlib, urllib2, socket import random, string, hashlib, urllib2, socket
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from six import string_types as basestring from six import string_types as basestring
try: try:
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
......
input_file = open('big_file.log', 'r') input_file = open('big_file.log', 'r')
import httplib import six.moves.http_client
connection = httplib.HTTPConnection('192.168.242.68:12001') connection = six.moves.http_client.HTTPConnection('192.168.242.68:12001')
import base64 import base64
base64string = base64.encodestring('zope:insecure')[:-1] base64string = base64.encodestring('zope:insecure')[:-1]
......
...@@ -67,4 +67,5 @@ def initialize( context ): ...@@ -67,4 +67,5 @@ def initialize( context ):
# allow import of various exceptions in restricted environment # allow import of various exceptions in restricted environment
# so we can catch them in ZODB scripts and inform user nicely # so we can catch them in ZODB scripts and inform user nicely
allow_module('xmlrpclib.Fault') allow_module('xmlrpclib.Fault')
allow_module('six.moves.xmlrpc_client')
allow_module('socket.error') allow_module('socket.error')
import sys import sys
import httplib import six.moves.http_client
if ( len(sys.argv) != 5 ): if ( len(sys.argv) != 5 ):
print("usage tinyWebClient.py host port method path") print("usage tinyWebClient.py host port method path")
...@@ -11,6 +11,6 @@ else: ...@@ -11,6 +11,6 @@ else:
info = (host, port) info = (host, port)
print("%s:%s" % info) print("%s:%s" % info)
conn = httplib.HTTPConnection("%s:%s" % info) conn = six.moves.http_client.HTTPConnection("%s:%s" % info)
conn.request(method, path) conn.request(method, path)
print(conn.getresponse().msg) print(conn.getresponse().msg)
...@@ -18,15 +18,15 @@ ...@@ -18,15 +18,15 @@
# cgi-bin directory serves Python CGIs. # cgi-bin directory serves Python CGIs.
from __future__ import print_function from __future__ import print_function
import BaseHTTPServer import six.moves.BaseHTTPServer
import CGIHTTPServer import six.moves.CGIHTTPServer
import time import time
import httplib import six.moves.http_client
import sys import sys
PORT = 8000 PORT = 8000
class HTTPHandler(CGIHTTPServer.CGIHTTPRequestHandler): class HTTPHandler(six.moves.CGIHTTPServer.CGIHTTPRequestHandler):
""" """
Simple Web Server that can handle query strings in a request URL and Simple Web Server that can handle query strings in a request URL and
can be stopped with a request can be stopped with a request
...@@ -48,7 +48,7 @@ class HTTPHandler(CGIHTTPServer.CGIHTTPRequestHandler): ...@@ -48,7 +48,7 @@ class HTTPHandler(CGIHTTPServer.CGIHTTPRequestHandler):
time.sleep(0.3) time.sleep(0.3)
# Carry on with the rest of the processing... # Carry on with the rest of the processing...
CGIHTTPServer.CGIHTTPRequestHandler.do_GET(self) six.moves.CGIHTTPServer.CGIHTTPRequestHandler.do_GET(self)
def do_QUIT(self): def do_QUIT(self):
self.send_response(200) self.send_response(200)
...@@ -61,7 +61,7 @@ if __name__ == '__main__': ...@@ -61,7 +61,7 @@ if __name__ == '__main__':
port = int(sys.argv[1]) port = int(sys.argv[1])
server_address = ('', port) server_address = ('', port)
httpd = BaseHTTPServer.HTTPServer(server_address, HTTPHandler) httpd = six.moves.BaseHTTPServer.HTTPServer(server_address, HTTPHandler)
print("serving at port", port) print("serving at port", port)
print("To run the entire JsUnit test suite, open") print("To run the entire JsUnit test suite, open")
......
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