Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.
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
8 changes: 4 additions & 4 deletions cloudify_rest_client/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import os
import tempfile
import shutil
import urllib
import urlparse
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import contextlib

from cloudify_rest_client import utils
Expand Down Expand Up @@ -95,13 +95,13 @@ def _upload(self,
query_params = {'visibility': visibility}
if application_file_name is not None:
query_params['application_file_name'] = \
urllib.quote(application_file_name)
urllib.parse.quote(application_file_name)

uri = '/{self._uri_prefix}/{id}'.format(self=self, id=blueprint_id)

# For a Windows path (e.g. "C:\aaa\bbb.zip") scheme is the
# drive letter and therefore the 2nd condition is present
if urlparse.urlparse(archive_location).scheme and \
if urllib.parse.urlparse(archive_location).scheme and \
not os.path.exists(archive_location):
# archive location is URL
query_params['blueprint_archive_url'] = archive_location
Expand Down
9 changes: 4 additions & 5 deletions cloudify_rest_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def __init__(self, host, port=DEFAULT_PORT,
self.host = host
self.protocol = protocol
self.api_version = api_version

self.headers = headers.copy() if headers else {}
if not self.headers.get('Content-type'):
self.headers['Content-type'] = 'application/json'
Expand Down Expand Up @@ -162,13 +161,13 @@ def _do_request(self, requests_method, request_url, body, params, headers,
timeout=timeout or self.default_timeout_sec,
auth=auth)
if self.logger.isEnabledFor(logging.DEBUG):
for hdr, hdr_content in response.request.headers.iteritems():
for hdr, hdr_content in list(response.request.headers.items()):
self.logger.debug('request header: %s: %s'
% (hdr, hdr_content))
self.logger.debug('reply: "%s %s" %s'
% (response.status_code,
response.reason, response.content))
for hdr, hdr_content in response.headers.iteritems():
for hdr, hdr_content in list(response.headers.items()):
self.logger.debug('response header: %s: %s'
% (hdr, hdr_content))

Expand Down Expand Up @@ -227,7 +226,7 @@ def do_request(self,
body = json.dumps(data) if is_dict_data else data
if self.logger.isEnabledFor(logging.DEBUG):
log_message = 'Sending request: {0} {1}'.format(
requests_method.func_name.upper(),
requests_method.__name__.upper(),
request_url)
if is_dict_data:
log_message += '; body: {0}'.format(body)
Expand Down Expand Up @@ -317,7 +316,7 @@ def _get_auth_header(self, username, password):
if not username or not password:
return None
credentials = '{0}:{1}'.format(username, password)
encoded_credentials = urlsafe_b64encode(credentials)
encoded_credentials = urlsafe_b64encode(credentials.encode('utf-8')).decode('utf-8')
return BASIC_AUTH_PREFIX + ' ' + encoded_credentials

def _set_header(self, key, value, log_value=True):
Expand Down
10 changes: 5 additions & 5 deletions cloudify_rest_client/deployment_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import os
import json
import urllib
import urllib.request, urllib.parse, urllib.error
import shutil
import urlparse
import urllib.parse
import tempfile

from mimetypes import MimeTypes
Expand Down Expand Up @@ -149,11 +149,11 @@ def _update_from_archive(deployment_id,

if application_file_name:
params['application_file_name'] = \
urllib.quote(application_file_name)
urllib.parse.quote(application_file_name)

# For a Windows path (e.g. "C:\aaa\bbb.zip") scheme is the
# drive letter and therefore the 2nd condition is present
if all([urlparse.urlparse(archive_path).scheme,
if all([urllib.parse.urlparse(archive_path).scheme,
not os.path.exists(archive_path)]):
# archive location is URL
params['blueprint_archive_url'] = archive_path
Expand All @@ -162,7 +162,7 @@ def _update_from_archive(deployment_id,
os.path.basename(archive_path),
open(archive_path, 'rb'),
# Guess the archive mime type
mime_types.guess_type(urllib.pathname2url(archive_path)))
mime_types.guess_type(urllib.request.pathname2url(archive_path)))

return data_form, params

Expand Down
4 changes: 3 additions & 1 deletion cloudify_rest_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def __init__(self, message, server_traceback=None,
self.error_code = error_code
self.server_traceback = server_traceback
self.response = response
self.message = message

def __str__(self):
if self.status_code != -1:
return '{0}: {1}'.format(self.status_code, self.message)
formatted_error = '{0}: {1}'.format(self.status_code, self.message)
return formatted_error
return self.message


Expand Down
4 changes: 2 additions & 2 deletions cloudify_rest_client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# * limitations under the License.

import os
import urlparse
import urllib.parse
import contextlib

from cloudify_rest_client import bytes_stream_utils
Expand Down Expand Up @@ -222,7 +222,7 @@ def upload(self,
assert plugin_path
query_params = {'visibility': visibility}
timeout = self.api.default_timeout_sec
if urlparse.urlparse(plugin_path).scheme and \
if urllib.parse.urlparse(plugin_path).scheme and \
not os.path.exists(plugin_path):
query_params['plugin_archive_url'] = plugin_path
data = None
Expand Down
2 changes: 1 addition & 1 deletion cloudify_rest_client/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def update(self, key, value=None, visibility=None, is_hidden_value=None):
}

# Remove the keys with value None
data = dict((k, v) for k, v in data.iteritems() if v is not None)
data = dict((k, v) for k, v in list(data.items()) if v is not None)
response = self.api.patch('/secrets/{0}'.format(key), data=data)
return Secret(response)

Expand Down
4 changes: 2 additions & 2 deletions cloudify_rest_client/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# * limitations under the License.

import os
import urlparse
import urllib.parse
import contextlib

from cloudify_rest_client import bytes_stream_utils
Expand Down Expand Up @@ -192,7 +192,7 @@ def upload(self,
uri = '/snapshots/{0}/archive'.format(snapshot_id)
query_params = {}

if urlparse.urlparse(snapshot_path).scheme and \
if urllib.parse.urlparse(snapshot_path).scheme and \
not os.path.exists(snapshot_path):
query_params['snapshot_archive_url'] = snapshot_path
data = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from setuptools import setup, find_packages

setup(
name='cloudify-rest-client',
name='cloudify_rest_client',
version='4.4.dev1',
author='cosmo-admin',
author_email='cosmo-admin@gigaspaces.com',
Expand Down