Skip to content

Commit

Permalink
python3 compat fixes (#173)
Browse files Browse the repository at this point in the history
* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* python 2&3 compat changes

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>

* fixing issue with python 3 compat

Signed-off-by: Vikrant Balyan (vvb) <[email protected]>
  • Loading branch information
vvb authored Aug 13, 2018
1 parent ce71808 commit b7da33d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 12 additions & 9 deletions ucsmsdk/ucsdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@

from six.moves import urllib as urllib2
from six.moves import http_client as httplib
from six.moves.urllib import request as Request
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import HTTPRedirectHandler, HTTPSHandler



import logging

log = logging.getLogger('ucs')


class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
class SmartRedirectHandler(HTTPRedirectHandler):
"""This class is to handle redirection error."""

def http_error_301(self, req, fp, code, msg, headers):
Expand All @@ -42,11 +45,11 @@ def http_error_302(self, req, fp, code, msg, headers):
return resp_status


class TLSHandler(urllib2.HTTPSHandler):
class TLSHandler(HTTPSHandler):
"""Like HTTPSHandler but more specific"""

def __init__(self):
urllib2.HTTPSHandler.__init__(self)
HTTPSHandler.__init__(self)

def https_open(self, req):
return self.do_open(TLSConnection, req)
Expand Down Expand Up @@ -91,11 +94,11 @@ def connect(self):
ssl_version=ssl.PROTOCOL_TLSv1)


class TLS1Handler(urllib2.HTTPSHandler):
class TLS1Handler(HTTPSHandler):
"""Like HTTPSHandler but more specific"""

def __init__(self):
urllib2.HTTPSHandler.__init__(self)
HTTPSHandler.__init__(self)

def https_open(self, req):
return self.do_open(TLS1Connection, req)
Expand Down Expand Up @@ -220,7 +223,7 @@ def __create_request(self, uri, data=None):
web request object
"""

request_ = urllib2.Request(url=uri, data=data)
request_ = Request.Request(url=uri, data=data)
headers = self.__headers
for header in headers:
request_.add_header(header, headers[header])
Expand Down Expand Up @@ -254,7 +257,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):
if dump_xml:
log.debug('%s ====> %s' % (uri, data))

opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
try:
response = opener.open(request, timeout=timeout)
except Exception as e:
Expand All @@ -263,7 +266,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):

# Fallback to TLSv1 for this server
self.update_handlers(tls_proto="tlsv1")
opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
response = opener.open(request, timeout=timeout)

if type(response) is list:
Expand All @@ -276,7 +279,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):
if dump_xml:
log.debug('%s <==== %s' % (uri, data))

opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
response = opener.open(request, timeout=timeout)
# response = urllib2.urlopen(request)
if read:
Expand Down
5 changes: 3 additions & 2 deletions ucsmsdk/ucseventhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from __future__ import print_function

from six.moves import queue as Queue
from six.moves import queue


from threading import Condition, Lock, Thread
import datetime
Expand Down Expand Up @@ -61,7 +62,7 @@ def __init__(self, params, fmce, capacity, callback):
self.params = params
self.overflow = False
self.error_code = 0
self.event_q = Queue() # infinite size Queue
self.event_q = queue.Queue() # infinite size Queue

def dequeue(self, miliseconds_timeout):
"""Internal method to dequeue the events."""
Expand Down

0 comments on commit b7da33d

Please sign in to comment.