Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit b721505

Browse files
committed
PEP8 edits via pycodestyle
1 parent e90d38e commit b721505

40 files changed

Lines changed: 200 additions & 140 deletions

CloudFlare/api_decode_from_openapi.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,22 @@ def do_path(cmd, values):
5151
content_type = ','.join(list(request_body['content'].keys()))
5252

5353
if content_type:
54-
v = {'action': action.upper(), 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already, 'content_type': content_type}
54+
v = {
55+
'action': action.upper(),
56+
'cmd': cmd,
57+
'deprecated': deprecated,
58+
'deprecated_date': deprecated_date,
59+
'deprecated_already': deprecated_already,
60+
'content_type': content_type
61+
}
5562
else:
56-
v = {'action': action.upper(), 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already}
63+
v = {
64+
'action': action.upper(),
65+
'cmd': cmd,
66+
'deprecated': deprecated,
67+
'deprecated_date': deprecated_date,
68+
'deprecated_already': deprecated_already
69+
}
5770
cmds.append(v)
5871
return cmds
5972

@@ -81,9 +94,9 @@ def api_decode_from_openapi(content):
8194
cloudflare_url = None
8295
for server in servers:
8396
try:
84-
cloudflare_url = server['url']
97+
cloudflare_url = server['url']
8598
except KeyError as e:
86-
pass
99+
pass
87100
if not cloudflare_url:
88101
raise SyntaxError('OpenAPI json servers/server missing url value')
89102

CloudFlare/cloudflare.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ def _add_headers(self, method, content_type, data, files):
7676
# no content type needed - except we throw in a default just for grin's
7777
self.headers['Content-Type'] = 'application/json'
7878
elif content_type is not None and method in content_type:
79-
# this api endpoint and this method requires a specific content type.
80-
ct = content_type[method]
81-
if isinstance(ct, list):
82-
# How do we choose from more than one content type?
83-
for t in ct:
84-
# we have to match against the data type - arggg! how? XXX/TODO - use first for now
85-
self.headers['Content-Type'] = t
86-
break
87-
else:
88-
self.headers['Content-Type'] = ct
79+
# this api endpoint and this method requires a specific content type.
80+
ct = content_type[method]
81+
if isinstance(ct, list):
82+
# How do we choose from more than one content type?
83+
for t in ct:
84+
# we have to match against the data type - arggg! how? XXX/TODO - use first for now
85+
self.headers['Content-Type'] = t
86+
break
87+
else:
88+
self.headers['Content-Type'] = ct
8989
else:
9090
# default choice
9191
self.headers['Content-Type'] = 'application/json'
@@ -438,8 +438,8 @@ def _raw(self, method, headers, parts, identifiers, params, data_str, data_json,
438438
# NDJSON is a series of JSON elements with newlines between each element
439439
try:
440440
r = []
441-
for l in response_data.splitlines():
442-
r.append(json.loads(l))
441+
for line in response_data.splitlines():
442+
r.append(json.loads(line))
443443
response_data = r
444444
except (ValueError, json.decoder.JSONDecodeError):
445445
# While this should not happen; it's always possible
@@ -569,8 +569,8 @@ def _call(self, method, parts, identifiers, params, data_str, data_json, files):
569569
message = errors['error']
570570
else:
571571
message = ''
572-
##if 'messages' in response_data:
573-
## errors['error_chain'] = response_data['messages']
572+
# if 'messages' in response_data:
573+
# errors['error_chain'] = response_data['messages']
574574
if 'error_chain' in errors:
575575
error_chain = errors['error_chain']
576576
for error in error_chain:
@@ -643,7 +643,7 @@ def api_from_openapi(self, url=None):
643643
self.logger.debug('OpenAPI bad json file: %s', e)
644644
raise CloudFlareAPIError(0, 'OpenAPI bad json file: %s' % (e)) from None
645645

646-
#if self.base_url != cloudflare_url:
646+
# if self.base_url != cloudflare_url:
647647
# # XXX/TODO should this be recorded or throw an error?
648648
# pass
649649

@@ -823,7 +823,7 @@ def add(self, t, p1, p2=None, p3=None, p4=None, p5=None, content_type=None):
823823
name = a[-1]
824824
try:
825825
if keyword.iskeyword(name):
826-
## add the keyword appended with an extra underscore so it can used with Python code
826+
# add the keyword appended with an extra underscore so it can used with Python code
827827
f = getattr(branch, name + '_')
828828
else:
829829
if '-' in name:
@@ -852,7 +852,7 @@ def add(self, t, p1, p2=None, p3=None, p4=None, p5=None, content_type=None):
852852
raise CloudFlareAPIError(0, 'api load type mismatch')
853853

854854
if keyword.iskeyword(name):
855-
## add the keyword appended with an extra underscore so it can used with Python code
855+
# add the keyword appended with an extra underscore so it can used with Python code
856856
setattr(branch, name + '_', f)
857857
else:
858858
if '-' in name:
@@ -888,7 +888,7 @@ def _api_list(self, m=None, s=''):
888888
if 'delete' in d or 'get' in d or 'patch' in d or 'post' in d or 'put' in d:
889889
# only show the result if a call exists for this part
890890
if n[-1] == '_':
891-
if keyword.iskeyword(n[:-1]):
891+
if keyword.iskeyword(n[:-1]):
892892
# should always be a keyword - but now nothing needs to be done
893893
pass
894894
# remove the extra keyword postfix'ed with underscore

CloudFlare/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class CodeMessage():
99
def __init__(self, code, message):
1010
self.code = code
1111
self.message = message
12+
1213
def __int__(self):
1314
return self.code
15+
1416
def __str__(self):
1517
return self.message
1618

CloudFlare/logging_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CFlogger():
1919
def __init__(self, level):
2020
""" Logging for Cloudflare API"""
2121
self.logger_level = self._get_logging_level(level)
22-
#logging.basicConfig(level=self.logger_level)
22+
# logging.basicConfig(level=self.logger_level)
2323
if CFlogger.request_logger is None:
2424
CFlogger.request_logger = logging.getLogger("requests.packages.urllib3")
2525
CFlogger.request_logger.setLevel(self.logger_level)

CloudFlare/read_configs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def read_configs(profile=None):
3636
os.path.expanduser('~/.cloudflare.cfg'),
3737
os.path.expanduser('~/.cloudflare/cloudflare.cfg')
3838
])
39-
except:
39+
except OSError:
4040
raise ReadConfigError("%s: configuration file error" % ('.cloudflare.cfg')) from None
4141

4242
if len(cp.sections()) == 0 and profile is not None and len(profile) > 0:
@@ -50,7 +50,7 @@ def read_configs(profile=None):
5050
if cp.has_section('Cloudflare'):
5151
profile = 'Cloudflare'
5252

53-
## still not found - then set to to CloudFlare for legacy reasons
53+
# still not found - then set to to CloudFlare for legacy reasons
5454
if profile is None:
5555
profile = "CloudFlare"
5656

CloudFlare/tests/test_issue114.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sys.path.insert(0, os.path.abspath('..'))
88
import CloudFlare
99

10-
# CloudFlare(email=None, key=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None, base_url=None, global_request_timeout=5, max_request_retries=5)
10+
# CloudFlare(email=None, key=None, token=None, certtoken=None, debug=False, ...)
1111

1212
cf = None
1313

@@ -19,83 +19,107 @@ class TestCloudflare:
1919
def test_email_key_token000(self):
2020
""" test_email_key_token### """
2121
self._run(0, 0, 0)
22+
2223
def test_email_key_token001(self):
2324
""" test_email_key_token### """
2425
self._run(0, 0, 1)
26+
2527
def test_email_key_token002(self):
2628
""" test_email_key_token### """
2729
self._run(0, 0, 2)
30+
2831
def test_email_key_token010(self):
2932
""" test_email_key_token### """
3033
self._run(0, 1, 0)
34+
3135
def test_email_key_token011(self):
3236
""" test_email_key_token### """
3337
self._run(0, 1, 1)
38+
3439
def test_email_key_token012(self):
3540
""" test_email_key_token### """
3641
self._run(0, 1, 2)
42+
3743
def test_email_key_token020(self):
3844
""" test_email_key_token### """
3945
self._run(0, 2, 0)
46+
4047
def test_email_key_token021(self):
4148
""" test_email_key_token### """
4249
self._run(0, 2, 1)
50+
4351
def test_email_key_token022(self):
4452
""" test_email_key_token### """
4553
self._run(0, 2, 2)
4654

4755
def test_email_key_token100(self):
4856
""" test_email_key_token### """
4957
self._run(1, 1, 0)
58+
5059
def test_email_key_token101(self):
5160
""" test_email_key_token### """
5261
self._run(1, 1, 1)
62+
5363
def test_email_key_token102(self):
5464
""" test_email_key_token### """
5565
self._run(1, 1, 2)
66+
5667
def test_email_key_token110(self):
5768
""" test_email_key_token### """
5869
self._run(1, 1, 1)
70+
5971
def test_email_key_token111(self):
6072
""" test_email_key_token### """
6173
self._run(1, 1, 1)
74+
6275
def test_email_key_token112(self):
6376
""" test_email_key_token### """
6477
self._run(1, 1, 2)
78+
6579
def test_email_key_token120(self):
6680
""" test_email_key_token### """
6781
self._run(1, 2, 1)
82+
6883
def test_email_key_token121(self):
6984
""" test_email_key_token### """
7085
self._run(1, 2, 1)
86+
7187
def test_email_key_token122(self):
7288
""" test_email_key_token### """
7389
self._run(1, 2, 2)
7490

7591
def test_email_key_token200(self):
7692
""" test_email_key_token### """
7793
self._run(2, 0, 0)
94+
7895
def test_email_key_token201(self):
7996
""" test_email_key_token### """
8097
self._run(2, 0, 1)
98+
8199
def test_email_key_token202(self):
82100
""" test_email_key_token### """
83101
self._run(2, 0, 2)
102+
84103
def test_email_key_token210(self):
85104
""" test_email_key_token### """
86105
self._run(2, 1, 2)
106+
87107
def test_email_key_token211(self):
88108
""" test_email_key_token### """
89109
self._run(2, 1, 1)
110+
90111
def test_email_key_token212(self):
91112
""" test_email_key_token### """
92113
self._run(2, 1, 2)
114+
93115
def test_email_key_token220(self):
94116
""" test_email_key_token### """
95117
self._run(2, 2, 2)
118+
96119
def test_email_key_token221(self):
97120
""" test_email_key_token### """
98121
self._run(2, 2, 1)
122+
99123
def test_email_key_token222(self):
100124
""" test_email_key_token### """
101125
self._run(2, 2, 2)
@@ -120,15 +144,16 @@ def _run(self, token_index, key_index, email_index):
120144

121145
try:
122146
cf = CloudFlare.CloudFlare(email=email, key=key, token=token, debug=debug, profile=profile)
123-
except Exception as e:
124-
print('Error: %s' % (e))
147+
except CloudFlare.exceptions.CloudFlareAPIError as e:
148+
print('%s: Error %d=%s' % ('CloudFlare', int(e), str(e)), file=sys.stderr)
125149
# don't know what to do; but, lets continue anyway
126150
return
127151
assert isinstance(cf, CloudFlare.CloudFlare)
128152

129153
try:
130154
r = cf.zones.get(params={'per_page':1})
131-
except:
155+
except CloudFlare.exceptions.CloudFlareAPIError as e:
156+
print('%s: Error %d=%s' % ('/zones', int(e), str(e)), file=sys.stderr)
132157
r = None
133158

134159
if email is None and key is None and token == self._token:
@@ -167,7 +192,7 @@ def _run(self, token_index, key_index, email_index):
167192
def _setup(self):
168193
""" setup """
169194
# Force no profile to be picked
170-
self._profile=''
195+
self._profile = ''
171196
# read in email/key/token from config file(s)
172197
_config_files = [
173198
'.cloudflare.cfg',
@@ -180,12 +205,12 @@ def _setup(self):
180205
for filename in _config_files:
181206
try:
182207
with open(filename, 'r') as fd:
183-
for l in fd:
208+
for line in fd:
184209
if email and key and token:
185210
break
186-
if l[0] == '#':
211+
if line[0] == '#':
187212
continue
188-
a = l.split()
213+
a = line.split()
189214
if len(a) < 3:
190215
continue
191216
if a[1] != '=':

CloudFlare/tests/test_loa_documents.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ def test_addressing_prefixs():
5656
assert 'asn' in p
5757
assert 'advertised' in p
5858
assert 'approved' in p
59-
print('%s: cidr=%s asn=%s advertised=%s approved=%s' % (p['id'], p['cidr'], p['asn'], p['advertised'], p['approved']), file=sys.stderr)
59+
print('%s: cidr=%s asn=%s advertised=%s approved=%s' % (
60+
p['id'],
61+
p['cidr'],
62+
p['asn'],
63+
p['advertised'],
64+
p['approved']
65+
), file=sys.stderr)
6066

6167
def test_addressing_loa_documents():
6268
""" test_addressing_loa_documents """
@@ -68,7 +74,12 @@ def test_addressing_loa_documents():
6874
assert 'filename' in loa_document
6975
assert 'verified' in loa_document
7076
assert 'size_bytes' in loa_document
71-
print('%s: filename=%s size_bytes=%d verified=%s' % (loa_document['id'], loa_document['filename'], loa_document['size_bytes'], loa_document['verified']), file=sys.stderr)
77+
print('%s: filename=%s size_bytes=%d verified=%s' % (
78+
loa_document['id'],
79+
loa_document['filename'],
80+
loa_document['size_bytes'],
81+
loa_document['verified']
82+
), file=sys.stderr)
7283

7384
def test_addressing_loa_documents_upload(filename=None):
7485
""" test_addressing_loa_documents_upload """
@@ -94,7 +105,12 @@ def test_addressing_loa_documents_upload(filename=None):
94105
assert 'filename' in loa_document
95106
assert 'verified' in loa_document
96107
assert 'size_bytes' in loa_document
97-
print('%s: filename=%s size_bytes=%d verified=%s' % (loa_document['id'], loa_document['filename'], loa_document['size_bytes'], loa_document['verified']), file=sys.stderr)
108+
print('%s: filename=%s size_bytes=%d verified=%s' % (
109+
loa_document['id'],
110+
loa_document['filename'],
111+
loa_document['size_bytes'],
112+
loa_document['verified']
113+
), file=sys.stderr)
98114
assert size_bytes == loa_document['size_bytes']
99115

100116
def ispdf(s):
@@ -126,7 +142,12 @@ def test_addressing_loa_documents_download():
126142
assert 'verified' in loa_document
127143
assert 'size_bytes' in loa_document
128144
assert isinstance(loa_document['size_bytes'], int)
129-
print('%s: filename=%s size_bytes=%d verified=%s' % (loa_document['id'], loa_document['filename'], loa_document['size_bytes'], loa_document['verified']), file=sys.stderr)
145+
print('%s: filename=%s size_bytes=%d verified=%s' % (
146+
loa_document['id'],
147+
loa_document['filename'],
148+
loa_document['size_bytes'],
149+
loa_document['verified']
150+
), file=sys.stderr)
130151
loa_document_identifier = loa_document['id']
131152
size_bytes = loa_document['size_bytes']
132153
pdf_content = cf.accounts.addressing.loa_documents.download(account_id, loa_document_identifier)

CloudFlare/tests/test_load_balancers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_load_balancers_create():
176176
return
177177
dns_name = str(uuid.uuid1())
178178
balancer_data = {
179-
'default_pools': [ pool_id ],
179+
'default_pools': [pool_id],
180180
'fallback_pool': pool_id,
181181
'name': dns_name + '.' + zone_name,
182182
'description': dns_name,

0 commit comments

Comments
 (0)