Skip to content

Commit

Permalink
Merge pull request #65 from azad-13/master
Browse files Browse the repository at this point in the history
add python3 support and fix Rados.mon_command call for ceph pacific
  • Loading branch information
Crapworks authored Dec 2, 2021
2 parents e447557 + 3f37337 commit 90f1d64
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ class UserConfig(dict):

def _string_decode_hook(self, data):
rv = {}
for key, value in data.iteritems():
for key, value in data.items():
try:
if isinstance(key, unicode):
key = key.encode('utf-8')
if isinstance(value, unicode):
value = value.encode('utf-8')
rv[key] = value
# unicode does not exist if python3 is used
# ignore and don't do encoding, it is not
# needed in python3
except NameError:
pass
rv[key] = value
return rv

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ApiResource(MethodView):
def as_blueprint(cls, name=None):
name = name or cls.endpoint
bp = Blueprint(name, cls.__module__, url_prefix=cls.url_prefix)
for endpoint, options in cls.url_rules.iteritems():
for endpoint, options in cls.url_rules.items():
url_rule = options.get('rule', '')
defaults = options.get('defaults', {})
bp.add_url_rule(url_rule, defaults=defaults, view_func=cls.as_view(endpoint))
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CephClusterCommand(dict):

def __init__(self, cluster, **kwargs):
dict.__init__(self)
ret, buf, err = cluster.mon_command(json.dumps(kwargs), '', timeout=5)
ret, buf, err = cluster.mon_command(json.dumps(kwargs), b'', timeout=5)
if ret != 0:
self['err'] = err
else:
Expand Down
7 changes: 6 additions & 1 deletion app/graphite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from flask import jsonify
from flask import current_app

from urllib2 import urlopen
# import urlopen from urllib.request / Python3
# and fallback to urlopen from urllib2 / Python2
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen

from app.base import ApiResource

Expand Down

0 comments on commit 90f1d64

Please sign in to comment.