Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Python 3 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kazoo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from client import Client
from .client import Client

VERSION = "0.2.0"
11 changes: 5 additions & 6 deletions kazoo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RestClientMetaClass(type):
def __init__(cls, name, bases, dct):
super(RestClientMetaClass, cls).__init__(name, bases, dct)

for key, value in dct.items():
for key, value in list(dct.items()):
if hasattr(value, "plural_name"):
cls._add_resource_methods(key, value, dct)

Expand Down Expand Up @@ -171,11 +171,11 @@ def _generate_resource_func(cls, func_name, resource_field_name,

func = compile(func_definition, __file__, 'exec')
d = {}
exec func in d
exec(func, d)
return d[func_name]


class Client(object):
class Client(metaclass=RestClientMetaClass):
"""The interface to the Kazoo API

This class should be initialized either with a username, password and
Expand Down Expand Up @@ -256,7 +256,6 @@ class Client(object):
GET /accounts/{account_id}/users/hotdesk -> client.get_hotdesk(acct_id)

"""
__metaclass__ = RestClientMetaClass
base_url = "http://api.2600hz.com:8000/v1"
account_id= ""
"""
Expand Down Expand Up @@ -1546,7 +1545,7 @@ def authenticate(self):
return self.auth_token

def _execute_request(self, request, **kwargs):
from exceptions import KazooApiAuthenticationError
from .exceptions import KazooApiAuthenticationError

if request.auth_required:
kwargs["token"] = self.auth_token
Expand Down Expand Up @@ -1654,6 +1653,6 @@ def search(self, data, multi=None, acct_id=None):

def dict_to_string(self, in_dict):
res = ''
for key, value in in_dict.iteritems():
for key, value in in_dict.items():
res = res + key + '=' + value +'&'
return res[:-1]
4 changes: 2 additions & 2 deletions kazoo/request_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_headers(self, token=None):
def _get_url(self, params, base_url):
url = base_url + self._get_url_with_variables_replaced(params)
if self.get_params:
return url + "?" + urllib.urlencode(self.get_params)
return url + "?" + urllib.parse.urlencode(self.get_params)
return url

def _get_url_with_variables_replaced(self, params):
Expand Down Expand Up @@ -146,7 +146,7 @@ def execute(self, base_url):

def _get_hashed_credentials(self):
m = hashlib.md5()
m.update("{0}:{1}".format(self.username, self.password))
m.update("{0}:{1}".format(self.username, self.password).encode())
return m.hexdigest()


Expand Down
4 changes: 2 additions & 2 deletions kazoo/rest_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_full_url(self, params):
def _initialize_extra_view_descriptions(self, view_descs):
self.extra_views = []
for view_desc in view_descs:
if hasattr(view_desc, "has_key"):
if isinstance(view_desc, dict):
result = view_desc
else:
result = {"name": "get_" + view_desc, "path": view_desc}
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_extra_view_request(self, viewname, **kwargs):

def dict_to_string(self, in_dict):
res = ''
for key, value in in_dict.iteritems():
for key, value in in_dict.items():
res = res + key + '=' + value +'&'
return res[:-1]

Expand Down