Skip to content

Commit 99e8eeb

Browse files
committed
pylint made me do this! - yet there is still more to do
1 parent 25cd7b9 commit 99e8eeb

File tree

8 files changed

+85
-93
lines changed

8 files changed

+85
-93
lines changed

CloudFlare/api_extras.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ def api_extras(self, extras=None):
5454
setattr(current, element,
5555
self._add_with_auth(self._base, api_call_part1))
5656
current = getattr(current, element)
57-

CloudFlare/api_v4.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def api_v4(self):
88
user_audit_logs(self)
99
user_load_balancers(self)
1010
user_load_balancing_analytics(self)
11+
user_tokens_verify(self)
1112
user_virtual_dns(self)
1213
user_workers(self)
1314

@@ -315,7 +316,6 @@ def user_virtual_dns(self):
315316
self.add('VOID', "user/virtual_dns", "dns_analytics")
316317
self.add('AUTH', "user/virtual_dns", "dns_analytics/report")
317318
self.add('AUTH', "user/virtual_dns", "dns_analytics/report/bytime")
318-
return
319319

320320
def user_workers(self):
321321
""" API core commands for Cloudflare API"""
@@ -330,7 +330,6 @@ def organizations_virtual_dns(self):
330330
self.add('VOID', "organizations", "virtual_dns", "dns_analytics")
331331
self.add('AUTH', "organizations", "virtual_dns", "dns_analytics/report")
332332
self.add('AUTH', "organizations", "virtual_dns", "dns_analytics/report/bytime")
333-
return
334333

335334
def user_audit_logs(self):
336335
""" API core commands for Cloudflare API"""
@@ -344,6 +343,12 @@ def user_load_balancing_analytics(self):
344343
self.add('AUTH', "user", "load_balancing_analytics/events")
345344
self.add('AUTH', "user", "load_balancing_analytics/entities")
346345

346+
def user_tokens_verify(self):
347+
""" API core commands for Cloudflare API"""
348+
349+
self.add('VOID', "user/tokens")
350+
self.add('AUTH', "user/tokens/verify")
351+
347352
def organizations_audit_logs(self):
348353
""" API core commands for Cloudflare API"""
349354

@@ -416,4 +421,3 @@ def memberships(self):
416421
""" API core commands for Cloudflare API"""
417422

418423
self.add('AUTH', "memberships")
419-

CloudFlare/cloudflare.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def call_with_auth(self, method, parts,
7979
headers = {}
8080
self._add_headers(headers)
8181
self._add_auth_headers(headers)
82-
if type(data) == str:
82+
if isinstance(data, str):
8383
# passing javascript vs JSON
8484
headers['Content-Type'] = 'application/javascript'
8585
if files:
@@ -99,7 +99,7 @@ def call_with_auth_unwrapped(self, method, parts,
9999
headers = {}
100100
self._add_headers(headers)
101101
self._add_auth_headers(headers)
102-
if type(data) == str:
102+
if isinstance(data, str):
103103
# passing javascript vs JSON
104104
headers['Content-Type'] = 'application/javascript'
105105
if files:
@@ -195,7 +195,7 @@ def _network(self, method, headers, parts,
195195
params=params,
196196
data=data)
197197
elif method == 'POST':
198-
if type(data) == str:
198+
if isinstance(data, str):
199199
response = self.session.post(url,
200200
headers=headers,
201201
params=params,
@@ -208,7 +208,7 @@ def _network(self, method, headers, parts,
208208
json=data,
209209
files=files)
210210
elif method == 'PUT':
211-
if type(data) == str:
211+
if isinstance(data, str):
212212
response = self.session.put(url,
213213
headers=headers,
214214
params=params,
@@ -219,7 +219,7 @@ def _network(self, method, headers, parts,
219219
params=params,
220220
json=data)
221221
elif method == 'DELETE':
222-
if type(data) == str:
222+
if isinstance(data, str):
223223
response = self.session.delete(url,
224224
headers=headers,
225225
params=params,
@@ -230,7 +230,7 @@ def _network(self, method, headers, parts,
230230
params=params,
231231
json=data)
232232
elif method == 'PATCH':
233-
if type(data) == str:
233+
if isinstance(data, str):
234234
response = self.session.request('PATCH', url,
235235
headers=headers,
236236
params=params,
@@ -265,7 +265,7 @@ def _network(self, method, headers, parts,
265265
response_type = 'application/octet-stream'
266266
response_code = response.status_code
267267
response_data = response.content
268-
if type(response_data) != str:
268+
if not isinstance(response_data, str):
269269
response_data = response_data.decode("utf-8")
270270

271271
if self.logger:
@@ -829,7 +829,7 @@ def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=Fals
829829

830830
# class creation values override configuration values
831831
try:
832-
[conf_email, conf_token, conf_certtoken, extras] = read_configs(profile)
832+
[conf_email, conf_token, conf_certtoken, extras, profile] = read_configs(profile)
833833
except:
834834
raise CloudFlareAPIError(0, 'profile/configuration read error')
835835

@@ -873,23 +873,24 @@ def __str__(self):
873873
""" Cloudflare v4 API"""
874874

875875
if self._base.email is None:
876-
return '["%s"]' % ('REDACTED')
876+
s = '["%s","%s"]' % (self._base.profile, 'REDACTED')
877877
else:
878-
return '["%s","%s","%s"]' % (self._base.profile, self._base.email, 'REDACTED')
878+
s = '["%s","%s","%s"]' % (self._base.profile, self._base.email, 'REDACTED')
879+
return s
879880

880881
def __repr__(self):
881882
""" Cloudflare v4 API"""
882883

883884
if self._base.email is None:
884-
return '%s,%s(%s,"%s","%s","%s",%s,"%s")' % (
885+
s = '%s,%s("%s","%s","%s","%s",%s,"%s")' % (
885886
self.__module__, type(self).__name__,
886887
self._base.profile, 'REDACTED', 'REDACTED',
887888
self._base.base_url, self._base.raw, self._base.user_agent
888889
)
889890
else:
890-
return '%s,%s(%s,"%s","%s","%s","%s",%s,"%s")' % (
891+
s = '%s,%s("%s","%s","%s","%s","%s",%s,"%s")' % (
891892
self.__module__, type(self).__name__,
892893
self._base.profile, self._base.email, 'REDACTED', 'REDACTED',
893894
self._base.base_url, self._base.raw, self._base.user_agent
894895
)
895-
896+
return s

CloudFlare/exceptions.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, code, message, error_chain=None):
1919

2020
self.evalue = self.CodeMessage(int(code), str(message))
2121
self.error_chain = None
22-
if error_chain != None:
22+
if error_chain is not None:
2323
self.error_chain = []
2424
for evalue in error_chain:
2525
self.error_chain.append(
@@ -41,8 +41,7 @@ def __len__(self):
4141

4242
if self.error_chain is None:
4343
return 0
44-
else:
45-
return len(self.error_chain)
44+
return len(self.error_chain)
4645

4746
def __getitem__(self, ii):
4847
""" Cloudflare API errors can contain a chain of errors"""
@@ -53,23 +52,18 @@ def __iter__(self):
5352
""" Cloudflare API errors can contain a chain of errors"""
5453

5554
if self.error_chain is None:
56-
raise StopIteration
55+
return
5756
for evalue in self.error_chain:
5857
yield evalue
5958

6059
def next(self):
6160
""" Cloudflare API errors can contain a chain of errors"""
6261

6362
if self.error_chain is None:
64-
raise StopIteration()
63+
raise StopIteration
6564

6665
class CloudFlareAPIError(CloudFlareError):
6766
""" errors for Cloudflare API"""
6867

69-
pass
70-
7168
class CloudFlareInternalError(CloudFlareError):
7269
""" errors for Cloudflare API"""
73-
74-
pass
75-

CloudFlare/logging_helper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ def _get_logging_level(self, level):
4747
""" Logging for Cloudflare API"""
4848
if level is True:
4949
return logging.DEBUG
50-
else:
51-
return logging.INFO
50+
return logging.INFO

CloudFlare/read_configs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def read_configs(profile=None):
3030
if len(config.sections()) == 0:
3131
## no config file found - so env values (even if empty) should be returned
3232
## this isn't an error
33-
return [email, token, certtoken, extras]
33+
return [email, token, certtoken, extras, profile]
3434

3535
if profile not in config.sections():
3636
## section is missing - this is an error
@@ -63,5 +63,4 @@ def read_configs(profile=None):
6363
if extras:
6464
extras = extras.split(' ')
6565

66-
return [email, token, certtoken, extras]
67-
66+
return [email, token, certtoken, extras, profile]

0 commit comments

Comments
 (0)