From 7681cf91ea2e3c45a47aa580858b10964021b494 Mon Sep 17 00:00:00 2001 From: IWAMOTO Toshihiro Date: Mon, 22 Jun 2015 12:09:31 +0900 Subject: [PATCH] python3: Fix import issues with python2 Fix issues introduced in commit c3c2112cb16a60271f4eb595f82721b1f1adc633, reported by Satoshi KOBAYASHI on ryu-devel. Use six.moves to handle module name changes. Signed-off-by: IWAMOTO Toshihiro Signed-off-by: FUJITA Tomonori --- ryu/app/client.py | 22 +++++++++++----------- ryu/app/rest_conf_switch.py | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ryu/app/client.py b/ryu/app/client.py index e14b3129..98752cee 100644 --- a/ryu/app/client.py +++ b/ryu/app/client.py @@ -18,9 +18,9 @@ # This module is *not* used by ryu-manager. # Imported and used by OpenStack Ryu plug-in and agent. -import http.client +from six.moves import http_client import json -import urllib.parse +from six.moves import urllib_parse def ignore_http_not_found(func): @@ -30,9 +30,9 @@ def ignore_http_not_found(func): """ try: func() - except http.client.HTTPException as e: + except http_client.HTTPException as e: res = e.args[0] - if res.status != http.client.NOT_FOUND: + if res.status != http_client.NOT_FOUND: raise @@ -40,13 +40,13 @@ class RyuClientBase(object): def __init__(self, version, address): super(RyuClientBase, self).__init__() self.version = version - res = urllib.parse.SplitResult('', address, '', '', '') + res = urllib_parse.SplitResult('', address, '', '', '') self.host = res.hostname self.port = res.port self.url_prefix = '/' + self.version + '/' def _do_request(self, method, action, body=None): - conn = http.client.HTTPConnection(self.host, self.port) + conn = http_client.HTTPConnection(self.host, self.port) url = self.url_prefix + action headers = {} if body is not None: @@ -54,13 +54,13 @@ class RyuClientBase(object): headers['Content-Type'] = 'application/json' conn.request(method, url, body, headers) res = conn.getresponse() - if res.status in (http.client.OK, - http.client.CREATED, - http.client.ACCEPTED, - http.client.NO_CONTENT): + if res.status in (http_client.OK, + http_client.CREATED, + http_client.ACCEPTED, + http_client.NO_CONTENT): return res - raise http.client.HTTPException( + raise http_client.HTTPException( res, 'code %d reason %s' % (res.status, res.reason), res.getheaders(), res.read()) diff --git a/ryu/app/rest_conf_switch.py b/ryu/app/rest_conf_switch.py index 011a407d..e397a37b 100644 --- a/ryu/app/rest_conf_switch.py +++ b/ryu/app/rest_conf_switch.py @@ -21,7 +21,7 @@ This module provides a set of REST API for switch configuration. Used by OpenStack Ryu agent. """ -import http.client +from six.moves import http_client import json import logging from webob import Response @@ -72,7 +72,7 @@ class ConfSwitchController(ControllerBase): try: ret = func(dpid) except KeyError: - return Response(status=http.client.NOT_FOUND, + return Response(status=http_client.NOT_FOUND, body='no dpid is found %s' % dpid_lib.dpid_to_str(dpid)) @@ -84,7 +84,7 @@ class ConfSwitchController(ControllerBase): return None def _ret(_ret): - return Response(status=http.client.ACCEPTED) + return Response(status=http_client.ACCEPTED) return self._do_switch(dpid, _delete_switch, _ret) @@ -104,7 +104,7 @@ class ConfSwitchController(ControllerBase): try: ret = func(dpid, key) except KeyError: - return Response(status=http.client.NOT_FOUND, + return Response(status=http_client.NOT_FOUND, body='no dpid/key is found %s %s' % (dpid_lib.dpid_to_str(dpid), key)) return ret_func(ret) @@ -116,7 +116,7 @@ class ConfSwitchController(ControllerBase): return None def _ret(_ret): - return Response(status=http.client.CREATED) + return Response(status=http_client.CREATED) return self._do_key(dpid, key, _set_val, _ret)