Skip to content

Commit 484da43

Browse files
authored
Merge pull request #84 from mikemanger/remove-old-python-code
Remove old python code
2 parents 4ec9ed6 + 45f4e71 commit 484da43

30 files changed

Lines changed: 604 additions & 648 deletions

lib/createsend/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import
2-
3-
# -*- coding: utf-8 -*-
41
__title__ = 'createsend-python'
52
__author__ = 'Campaign Monitor'
63
__license__ = 'MIT'

lib/createsend/administrator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import json
42

53
from createsend.createsend import CreateSendBase
@@ -11,7 +9,7 @@ class Administrator(CreateSendBase):
119

1210
def __init__(self, auth=None, email_address=None):
1311
self.email_address = email_address
14-
super(Administrator, self).__init__(auth)
12+
super().__init__(auth)
1513

1614
def get(self, email_address=None):
1715
"""Gets an administrator by email address."""

lib/createsend/campaign.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import json
42

53
from createsend.createsend import CreateSendBase
@@ -11,7 +9,7 @@ class Campaign(CreateSendBase):
119

1210
def __init__(self, auth=None, campaign_id=None):
1311
self.campaign_id = campaign_id
14-
super(Campaign, self).__init__(auth)
12+
super().__init__(auth)
1513

1614
def create(self, client_id, subject, name, from_name, from_email, reply_to, html_url,
1715
text_url, list_ids, segment_ids):
@@ -190,4 +188,4 @@ def bounces(self, date="", page=1, page_size=1000, order_field="date", order_dir
190188
return json_to_py(response)
191189

192190
def uri_for(self, action):
193-
return "/campaigns/%s/%s.json" % (self.campaign_id, action)
191+
return f"/campaigns/{self.campaign_id}/{action}.json"

lib/createsend/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import json
42

53
from createsend.createsend import CreateSendBase
@@ -11,7 +9,7 @@ class Client(CreateSendBase):
119

1210
def __init__(self, auth=None, client_id=None):
1311
self.client_id = client_id
14-
super(Client, self).__init__(auth)
12+
super().__init__(auth)
1513

1614
def create(self, company, timezone, country):
1715
"""Creates a client."""
@@ -186,4 +184,4 @@ def journeys(self):
186184
return json_to_py(response)
187185

188186
def uri_for(self, action):
189-
return "/clients/%s/%s.json" % (self.client_id, action)
187+
return f"/clients/{self.client_id}/{action}.json"

lib/createsend/createsend.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from __future__ import absolute_import
2-
31
import sys
42
import platform
53
import base64
64
import gzip
75
import os
86
import socket
97
import json
10-
from six import BytesIO
11-
from six.moves.urllib.parse import parse_qs, urlencode, urlparse
8+
from io import BytesIO
9+
from urllib.parse import parse_qs, urlencode, urlparse
1210

1311
from createsend.utils import VerifiedHTTPSConnection, json_to_py, get_faker
1412

@@ -26,7 +24,7 @@ def __str__(self):
2624
# self.data should contain Code, Message and optionally ResultData
2725
extra = ("\nExtra result data: %s" % self.data.ResultData) if hasattr(
2826
self.data, 'ResultData') else ""
29-
return "The CreateSend API responded with the following error - %s: %s%s" % (self.data.Code, self.data.Message, extra)
27+
return f"The CreateSend API responded with the following error - {self.data.Code}: {self.data.Message}{extra}"
3028

3129

3230
class ClientError(Exception):
@@ -59,7 +57,7 @@ class ExpiredOAuthToken(Unauthorized):
5957
pass
6058

6159

62-
class CreateSendBase(object):
60+
class CreateSendBase:
6361
auth_details = None
6462
timeout = socket._GLOBAL_DEFAULT_TIMEOUT # passed to VerifiedHTTPSConnection
6563

@@ -77,7 +75,7 @@ def authorize_url(self, client_id, redirect_uri, scope, state=None):
7775
]
7876
if state:
7977
params.append(('state', state))
80-
return "%s?%s" % (CreateSend.oauth_uri, urlencode(params))
78+
return f"{CreateSend.oauth_uri}?{urlencode(params)}"
8179

8280
def exchange_token(self, client_id, client_secret, redirect_uri, code):
8381
"""Exchange a provided OAuth code for an OAuth access token, 'expires in'
@@ -95,7 +93,7 @@ def exchange_token(self, client_id, client_secret, redirect_uri, code):
9593
r = json_to_py(response)
9694
if hasattr(r, 'error') and hasattr(r, 'error_description'):
9795
err = "Error exchanging code for access token: "
98-
err += "%s - %s" % (r.error, r.error_description)
96+
err += f"{r.error} - {r.error_description}"
9997
raise Exception(err)
10098
access_token, expires_in, refresh_token = r.access_token, r.expires_in, r.refresh_token
10199
return [access_token, expires_in, refresh_token]
@@ -156,7 +154,7 @@ def make_request(self, method, path, params={}, body="", username=None,
156154
overridden (e.g. when using the apikey route with username and password)."""
157155
if username and password:
158156
headers['Authorization'] = "Basic %s" % base64.b64encode(
159-
("%s:%s" % (username, password)).encode()).decode()
157+
(f"{username}:{password}").encode()).decode()
160158
elif self.auth_details:
161159
if 'api_key' in self.auth_details and self.auth_details['api_key']:
162160
headers['Authorization'] = "Basic %s" % base64.b64encode(
@@ -171,7 +169,7 @@ def make_request(self, method, path, params={}, body="", username=None,
171169
if self.fake_web:
172170
# Check that the actual url which would be requested matches
173171
# self.faker.url.
174-
actual_url = "https://%s%s" % (parsed_base_uri.netloc,
172+
actual_url = "https://{}{}".format(parsed_base_uri.netloc,
175173
self.build_url(parsed_base_uri, path, params))
176174
self.faker.actual_url = actual_url
177175

@@ -186,7 +184,7 @@ def same_urls(url_a, url_b):
186184
a.fragment == b.fragment
187185
)
188186
if not same_urls(self.faker.url, actual_url):
189-
raise Exception("Faker's expected URL (%s) doesn't match actual URL (%s)" % (
187+
raise Exception("Faker's expected URL ({}) doesn't match actual URL ({})".format(
190188
self.faker.url, actual_url))
191189

192190
self.faker.actual_body = body
@@ -195,7 +193,7 @@ def same_bodies(body_a, body_b):
195193
return json.loads(body_a) == json.loads(body_b)
196194
if self.faker.body is not None:
197195
if not same_bodies(self.faker.body, body):
198-
raise Exception("Faker's expected body (%s) doesn't match actual body (%s)" % (
196+
raise Exception("Faker's expected body ({}) doesn't match actual body ({})".format(
199197
self.faker.body, body))
200198

201199
data = self.faker.open() if self.faker else ''
@@ -265,7 +263,7 @@ class CreateSend(CreateSendBase):
265263
user_agent = default_user_agent
266264

267265
def __init__(self, auth=None):
268-
super(CreateSend, self).__init__(auth)
266+
super().__init__(auth)
269267

270268
def clients(self):
271269
"""Gets your clients."""

lib/createsend/journey.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from createsend.createsend import CreateSendBase
42
from createsend.utils import json_to_py
53

@@ -9,7 +7,7 @@ class Journey(CreateSendBase):
97

108
def __init__(self, auth=None, journey_id=None):
119
self.journey_id = journey_id
12-
super(Journey, self).__init__(auth)
10+
super().__init__(auth)
1311

1412
def summary(self):
1513
"""Gets the summary of the journey"""

lib/createsend/journey_email.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from createsend.createsend import CreateSendBase
42
from createsend.utils import json_to_py
53

@@ -9,7 +7,7 @@ class JourneyEmail(CreateSendBase):
97

108
def __init__(self, auth=None, journey_email_id=None):
119
self.journey_email_id = journey_email_id
12-
super(JourneyEmail, self).__init__(auth)
10+
super().__init__(auth)
1311

1412
def bounces(self, date=None, page=None, page_size=None, order_direction=None):
1513
"""Retrieves the bounces for this journey email."""
@@ -46,5 +44,5 @@ def get_journey_email_response(self, date, page, page_size, order_direction, uri
4644
return json_to_py(response)
4745

4846
def uri_for(self, action):
49-
return "/journeys/email/%s/%s.json" % (self.journey_email_id, action)
47+
return f"/journeys/email/{self.journey_email_id}/{action}.json"
5048

lib/createsend/list.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from __future__ import absolute_import
2-
31
import json
4-
from six.moves.urllib.parse import quote
2+
from urllib.parse import quote
53

64
from createsend.createsend import CreateSendBase
75
from createsend.utils import json_to_py
@@ -12,7 +10,7 @@ class List(CreateSendBase):
1210

1311
def __init__(self, auth=None, list_id=None):
1412
self.list_id = list_id
15-
super(List, self).__init__(auth)
13+
super().__init__(auth)
1614

1715
def create(self, client_id, title, unsubscribe_page, confirmed_opt_in,
1816
confirmation_success_page, unsubscribe_setting="AllClientLists"):
@@ -206,4 +204,4 @@ def deactivate_webhook(self, webhook_id):
206204
"webhooks/%s/deactivate" % webhook_id), ' ')
207205

208206
def uri_for(self, action):
209-
return "/lists/%s/%s.json" % (self.list_id, action)
207+
return f"/lists/{self.list_id}/{action}.json"

lib/createsend/person.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import json
42

53
from createsend.createsend import CreateSendBase
@@ -12,7 +10,7 @@ class Person(CreateSendBase):
1210
def __init__(self, auth=None, client_id=None, email_address=None):
1311
self.client_id = client_id
1412
self.email_address = email_address
15-
super(Person, self).__init__(auth)
13+
super().__init__(auth)
1614

1715
def get(self, client_id=None, email_address=None):
1816
"""Gets a person by client ID and email address."""

lib/createsend/segment.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import json
42

53
from createsend.createsend import CreateSendBase
@@ -11,7 +9,7 @@ class Segment(CreateSendBase):
119

1210
def __init__(self, auth=None, segment_id=None):
1311
self.segment_id = segment_id
14-
super(Segment, self).__init__(auth)
12+
super().__init__(auth)
1513

1614
def create(self, list_id, title, rulegroups):
1715
"""Creates a new segment."""
@@ -63,4 +61,4 @@ def delete(self):
6361
response = self._delete("/segments/%s.json" % self.segment_id)
6462

6563
def uri_for(self, action):
66-
return "/segments/%s/%s.json" % (self.segment_id, action)
64+
return f"/segments/{self.segment_id}/{action}.json"

0 commit comments

Comments
 (0)