Skip to content

Commit ffad830

Browse files
committed
Unicode Updates
Remove specific uses of Unicode strings and ‘default’ the package to prefer the usage of ‘str’ strings.
1 parent d518131 commit ffad830

File tree

17 files changed

+318
-379
lines changed

17 files changed

+318
-379
lines changed

ciscosparkapi/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1+
# -*- coding: utf-8 -*-
12
"""Python API wrapper for the Cisco Spark APIs."""
23

34

45
from __future__ import absolute_import
5-
from __future__ import unicode_literals
6-
from past.builtins import basestring
76
from builtins import object
8-
9-
# Versioneer version control
10-
from ._version import get_versions
11-
__version__ = get_versions()['version']
12-
del get_versions
7+
from six import string_types
138

149
import os
1510

@@ -25,6 +20,12 @@
2520
from .api.webhooks import Webhook, WebhooksAPI
2621

2722

23+
# Versioneer version control
24+
from ._version import get_versions
25+
__version__ = get_versions()['version']
26+
del get_versions
27+
28+
2829
DEFAULT_BASE_URL = 'https://api.ciscospark.com/v1/'
2930

3031

@@ -50,10 +51,10 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
5051
via one of these two methods.
5152
5253
Args:
53-
access_token(unicode, str): The access token to be used for API
54+
access_token(string_types): The access token to be used for API
5455
calls to the Cisco Spark service. Defaults to checking for a
5556
SPARK_ACCESS_TOKEN environment variable.
56-
base_url(unicode, str): The base URL to be prefixed to the
57+
base_url(string_types): The base URL to be prefixed to the
5758
individual API endpoint suffixes.
5859
Defaults to ciscosparkapi.DEFAULT_BASE_URL.
5960
timeout(int): Timeout (in seconds) for RESTful HTTP requests.
@@ -65,21 +66,21 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
6566
Raises:
6667
AssertionError: If the parameter types are incorrect.
6768
ciscosparkapiException: If an access token is not provided via the
68-
access_token argument or SPARK_ACCESS_TOKEN environement
69+
access_token argument or SPARK_ACCESS_TOKEN environment
6970
variable.
7071
7172
"""
7273
# Process args
73-
assert access_token is None or isinstance(access_token, basestring)
74-
assert isinstance(base_url, basestring)
74+
assert access_token is None or isinstance(access_token, string_types)
75+
assert isinstance(base_url, string_types)
7576
assert isinstance(timeout, int)
7677
spark_access_token = os.environ.get('SPARK_ACCESS_TOKEN', None)
7778
access_token = access_token if access_token else spark_access_token
7879
if not access_token:
7980
error_message = "You must provide an access token to interact " \
8081
"with the Cisco Spark APIs, either via the " \
8182
"access_token argument or via a " \
82-
"SPARK_ACCESS_TOKEN environement variable. " \
83+
"SPARK_ACCESS_TOKEN environment variable. " \
8384
"None provided."
8485
raise ciscosparkapiException(error_message)
8586
session_args = {u'timeout': timeout}

ciscosparkapi/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12

23
# This file helps to compute a version number in source trees obtained from
34
# git-archive tarball (such as those provided by githubs download-from-tag
@@ -10,7 +11,6 @@
1011

1112
"""Git implementation of _version.py."""
1213
from __future__ import print_function
13-
from __future__ import unicode_literals
1414
from builtins import str
1515
from builtins import object
1616

ciscosparkapi/api/accesstokens.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""Cisco Spark Access-Tokens-API wrapper classes.
23
34
Classes:
@@ -9,22 +10,21 @@
910
"""
1011

1112

12-
from __future__ import unicode_literals
1313
from future import standard_library
1414
standard_library.install_aliases()
15-
from past.builtins import basestring
1615
from builtins import object
16+
from six import string_types
1717

1818
import urllib.parse
1919

2020
import requests
2121

22-
from ciscosparkapi.helper import utf8, ERC, validate_base_url, \
22+
from ciscosparkapi.helper import ERC, validate_base_url, \
2323
check_response_code, extract_and_parse_json
2424
from ciscosparkapi.sparkdata import SparkData
2525

2626

27-
API_ENDPOINT = u"access_token"
27+
API_ENDPOINT = "access_token"
2828

2929

3030
class AccessToken(SparkData):
@@ -34,7 +34,7 @@ def __init__(self, json):
3434
"""Init a new AccessToken data object from a JSON dictionary or string.
3535
3636
Args:
37-
json(dict, unicode, str): Input JSON object.
37+
json(dict, string_types): Input JSON object.
3838
3939
Raises:
4040
TypeError: If the input object is not a dictionary or string.
@@ -45,22 +45,22 @@ def __init__(self, json):
4545
@property
4646
def access_token(self):
4747
"""Cisco Spark access_token."""
48-
return self._json.get(u'access_token')
48+
return self._json.get('access_token')
4949

5050
@property
5151
def expires_in(self):
5252
"""Access token expires_in number of seconds."""
53-
return self._json.get(u'expires_in')
53+
return self._json.get('expires_in')
5454

5555
@property
5656
def refresh_token(self):
5757
"""refresh_token used to request a new/refreshed access_token."""
58-
return self._json.get(u'refresh_token')
58+
return self._json.get('refresh_token')
5959

6060
@property
6161
def refresh_token_expires_in(self):
6262
"""refresh_token_expires_in number of seconds."""
63-
return self._json.get(u'refresh_token_expires_in')
63+
return self._json.get('refresh_token_expires_in')
6464

6565

6666
class AccessTokensAPI(object):
@@ -75,21 +75,21 @@ def __init__(self, base_url, timeout=None):
7575
"""Init a new AccessTokensAPI object with the provided RestSession.
7676
7777
Args:
78-
base_url(unicode, str): The base URL the API endpoints.
78+
base_url(string_types): The base URL the API endpoints.
7979
timeout(int): Timeout in seconds for the API requests.
8080
8181
Raises:
8282
AssertionError: If the parameter types are incorrect.
8383
8484
"""
85-
assert isinstance(base_url, basestring)
85+
assert isinstance(base_url, string_types)
8686
assert timeout is None or isinstance(timeout, int)
8787
super(AccessTokensAPI, self).__init__()
88-
self._base_url = validate_base_url(base_url)
88+
self._base_url = str(validate_base_url(base_url))
8989
self._timeout = timeout
9090
self._endpoint_url = urllib.parse.urljoin(self.base_url, API_ENDPOINT)
9191
self._request_kwargs = {}
92-
self._request_kwargs[u"timeout"] = timeout
92+
self._request_kwargs["timeout"] = timeout
9393

9494
@property
9595
def base_url(self):
@@ -106,13 +106,13 @@ def get(self, client_id, client_secret, code, redirect_uri):
106106
invoke the APIs.
107107
108108
Args:
109-
client_id(unicode, str): Provided when you created your
109+
client_id(string_types): Provided when you created your
110110
integration.
111-
client_secret(unicode, str): Provided when you created your
111+
client_secret(string_types): Provided when you created your
112112
integration.
113-
code(unicode, str): The Authorization Code provided by the user
113+
code(string_types): The Authorization Code provided by the user
114114
OAuth process.
115-
redirect_uri(unicode, str): The redirect URI used in the user OAuth
115+
redirect_uri(string_types): The redirect URI used in the user OAuth
116116
process.
117117
118118
Returns:
@@ -125,17 +125,17 @@ def get(self, client_id, client_secret, code, redirect_uri):
125125
126126
"""
127127
# Process args
128-
assert isinstance(client_id, basestring)
129-
assert isinstance(client_secret, basestring)
130-
assert isinstance(code, basestring)
131-
assert isinstance(redirect_uri, basestring)
128+
assert isinstance(client_id, string_types)
129+
assert isinstance(client_secret, string_types)
130+
assert isinstance(code, string_types)
131+
assert isinstance(redirect_uri, string_types)
132132
# Build request parameters
133133
data = {}
134-
data[u"grant_type"] = u"authorization_code"
135-
data[u"client_id"] = utf8(client_id)
136-
data[u"client_secret"] = utf8(client_secret)
137-
data[u"code"] = utf8(code)
138-
data[u"redirect_uri"] = utf8(redirect_uri)
134+
data["grant_type"] = "authorization_code"
135+
data["client_id"] = client_id
136+
data["client_secret"] = client_secret
137+
data["code"] = code
138+
data["redirect_uri"] = redirect_uri
139139
# API request
140140
response = requests.post(self._endpoint_url, data=data,
141141
**self._request_kwargs)
@@ -148,11 +148,11 @@ def refresh(self, client_id, client_secret, refresh_token):
148148
"""Return a refreshed Access Token via the provided refresh_token.
149149
150150
Args:
151-
client_id(unicode, str): Provided when you created your
151+
client_id(string_types): Provided when you created your
152152
integration.
153-
client_secret(unicode, str): Provided when you created your
153+
client_secret(string_types): Provided when you created your
154154
integration.
155-
refresh_token(unicode, str): Provided when you requested the Access
155+
refresh_token(string_types): Provided when you requested the Access
156156
Token.
157157
158158
Returns:
@@ -165,15 +165,15 @@ def refresh(self, client_id, client_secret, refresh_token):
165165
166166
"""
167167
# Process args
168-
assert isinstance(client_id, basestring)
169-
assert isinstance(client_secret, basestring)
170-
assert isinstance(refresh_token, basestring)
168+
assert isinstance(client_id, string_types)
169+
assert isinstance(client_secret, string_types)
170+
assert isinstance(refresh_token, string_types)
171171
# Build request parameters
172172
data = {}
173-
data[u"grant_type"] = u"refresh_token"
174-
data[u"client_id"] = utf8(client_id)
175-
data[u"client_secret"] = utf8(client_secret)
176-
data[u"refresh_token"] = utf8(refresh_token)
173+
data["grant_type"] = "refresh_token"
174+
data["client_id"] = client_id
175+
data["client_secret"] = client_secret
176+
data["refresh_token"] = refresh_token
177177
# API request
178178
response = requests.post(self._endpoint_url, data=data,
179179
**self._request_kwargs)

0 commit comments

Comments
 (0)