Fix import(s) related issues for Python 2/3 compatible code.

fix http/socketserver module import issues
   e.g. before:
     import SocketServer
     import httplib
     import BaseHTTPServer
        after:
     from six.moves import socketserver
     from six.moves import http_client as httplib
     from six.moves import BaseHTTPServer

Story: 2003427
Task: 24609

Change-Id: I82132ab91f56a9038afdd931624559d8c370e231
Signed-off-by: SidneyAn <ran1.an@intel.com>
This commit is contained in:
SidneyAn 2018-12-18 10:05:38 +08:00
parent 730ef6eeaf
commit 90100b72ee
5 changed files with 22 additions and 15 deletions

View File

@ -5,14 +5,14 @@
#
import json
import re
from six.moves import BaseHTTPServer
from six.moves import http_client as httplib
from six.moves import socketserver as SocketServer
from six.moves import urllib
import socket
import struct
import BaseHTTPServer
import SocketServer
from nfv_common import debug
from nfv_common import selobj
from nfv_common import timers

View File

@ -6,14 +6,12 @@
import datetime
import json
import re
from six.moves import BaseHTTPServer
from six.moves import http_client as httplib
from six.moves import socketserver
import socket
import threading
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from SocketServer import ThreadingMixIn
from nfv_common import debug
from nfv_plugins.nfvi_plugins import config
from nfv_plugins.nfvi_plugins.openstack import fm
@ -38,10 +36,10 @@ def _bare_address_string(self):
return "%s" % host
BaseHTTPRequestHandler.address_string = _bare_address_string
BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string
class HTTPRequestHandler(BaseHTTPRequestHandler):
class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""
HTTP Request Handler
"""
@ -569,7 +567,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
self.wfile.write(f.read())
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
class ThreadedHTTPServer(socketserver.ThreadingMixIn, BaseHTTPServer.HTTPServer):
"""
Threaded HTTP Server
"""
@ -577,7 +575,7 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
def shutdown(self):
self.socket.close()
HTTPServer.shutdown(self)
BaseHTTPServer.HTTPServer.shutdown(self)
class SimpleHttpServer(object):

View File

@ -26,6 +26,7 @@ load-plugins=
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# W0107: Unnecessary pass statement (unnecessary-pass)
# W0120 useless-else-on-loop
# W0125 using-constant-test
# W0212 protected-access var starting with _ used outside class or descendant
@ -42,9 +43,12 @@ load-plugins=
# W0621 redefined-outer-name
# W0622 redefined-builtin
# W0703 broad except warning
# W0706: The except handler raises immediately (try-except-raise)
# W1401 anomalous-backslash-in-string
# W1505: Using deprecated method getargspec() (deprecated-method)
disable=C, R, W0120, W0125, W0212, W0221, W0223, W0231, W0235,
W0401, W0404, W0511, W0603, W0612, W0613, W0621, W0622, W0703, W1401
W0401, W0404, W0511, W0603, W0612, W0613, W0621, W0622, W0703, W1401,
W0107, W0706, W1505
[REPORTS]
@ -98,7 +102,13 @@ ignore-mixin-members=yes
# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
# The following VIM objects are ignored: ObjectData, GuestService, Network, SwUpdate
ignored-classes=SQLObject,sqlalchemy,scoped_session,_socketobject,ObjectData,GuestService,Network,SwUpdate
# The following Openstack plugin object is ignored: OpenStackRestAPIException
ignored-classes=SQLObject,sqlalchemy,scoped_session,_socketobject,ObjectData,GuestService,
Network,SwUpdate,OpenStackRestAPIException
# For compatibility of python2 and python 3, we import six.moves module, and
# the following py3 modules are ignored: http.client, urllib.request
ignored-modules=http.client,urllib.request
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular

View File

@ -97,7 +97,6 @@ deps = {[nfv]deps}
mock
testtools
pylint
basepython = python2.7
commands = pylint {[nfv]nfv_client_src_dir} \
{[nfv]nfv_common_src_dir} \
{[nfv]nfv_plugins_src_dir} \

View File

@ -12,9 +12,9 @@
# SPDX-License-Identifier: Apache-2.0
#
import httplib
from paste.proxy import parse_headers
from paste.proxy import TransparentProxy
from six.moves import http_client as httplib
import urllib
from oslo_log import log as logging