Skip to content

Commit b6094e1

Browse files
author
Martin Kudlej
committed
reduce pylint issues except of C0114,C0115,C0116,C0302,R0913,R0902,W0221
1 parent d372454 commit b6094e1

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ share/python-wheels/
3232
.installed.cfg
3333
*.egg
3434
MANIFEST
35-
Pipfile.lock
3635

3736
# PyInstaller
3837
# Usually these files are written by a python script from a template

threescale_api/auth.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ def __call__(self, request):
1919
credentials = self.credentials
2020

2121
if self.location == "authorization":
22-
auth = requests.auth.HTTPBasicAuth(credentials["username"], credentials["password"])
22+
credentials = credentials.values()
23+
auth = requests.auth.HTTPBasicAuth(*credentials)
2324
return auth(request)
2425

2526
if self.location == "headers":
2627
request.prepare_headers(credentials)
2728
elif self.location == "query":
2829
request.prepare_url(request.url, credentials)
2930
else:
30-
raise ValueError("Unknown credentials location '%s'" % self.location)
31+
raise ValueError(f"Unknown credentials location '{self.location}'")
3132

3233
return request
3334

@@ -36,7 +37,7 @@ class UserKeyAuth(BaseClientAuth):
3637
"""Provides user_key authentication for api client calls"""
3738

3839
def __init__(self, app, location=None):
39-
super(UserKeyAuth, self).__init__(app, location)
40+
super().__init__(app, location)
4041
self.credentials = {
4142
self.app.service.proxy.list()["auth_user_key"]: self.app["user_key"]
4243
}
@@ -52,7 +53,7 @@ class AppIdKeyAuth(BaseClientAuth):
5253
"""Provides app_id/app_key pair based authentication for api client calls"""
5354

5455
def __init__(self, app, location=None):
55-
super(AppIdKeyAuth, self).__init__(app, location)
56+
super().__init__(app, location)
5657
proxy = self.app.service.proxy.list()
5758
self.credentials = {
5859
proxy["auth_app_id"]: self.app["application_id"],

threescale_api/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool =
262262
self._token = token
263263
self._throws = throws
264264
self._ssl_verify = ssl_verify
265-
log.debug(f"[REST] New instance: {url} token={token} "
266-
f"throws={throws} ssl={ssl_verify}")
265+
log.debug("[REST] New instance: %s token=%s throws=%s ssl=%s", url, token, throws,
266+
ssl_verify)
267267

268268
@property
269269
def url(self) -> str:
@@ -293,8 +293,8 @@ def request(self, method='GET', url=None, path='', params: dict = None,
293293
if throws is None:
294294
throws = self._throws
295295
params.update(access_token=self._token)
296-
log.debug(f"[{method}] ({full_url}) params={params} headers={headers} "
297-
f"{kwargs if kwargs else ''}")
296+
log.debug("[%s] (%s) params={%s} headers={%s} %s", method, full_url, params, headers,
297+
kwargs if kwargs else '')
298298
response = requests.request(method=method, url=full_url, headers=headers,
299299
params=params, verify=self._ssl_verify, **kwargs)
300300
process_response = self._process_response(response, throws=throws)

threescale_api/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def select_by(self, **params) -> List['DefaultResource']:
187187
**params: params used for selection
188188
Returns: List of resources
189189
"""
190-
log.debug(f"[SELECT] By params: {params}")
190+
log.debug("[SELECT] By params: %s", params)
191191

192192
def predicate(item):
193193
for (key, val) in params.items():
@@ -238,7 +238,7 @@ def _create_instance(self, response: requests.Response, klass=None, collection:
238238
klass = klass or self._instance_klass
239239
extracted = self._extract_resource(response, collection)
240240
instance = self._instantiate(extracted=extracted, klass=klass)
241-
log.debug(f"[INSTANCE] Created instance: {instance}")
241+
log.debug("[INSTANCE] Created instance: %s", instance)
242242
return instance
243243

244244
def _extract_resource(self, response, collection) -> Union[List, Dict]:

threescale_api/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class ThreeScaleApiError(Exception):
22
def __init__(self, message, *args):
33
self.message = message
4-
super(ThreeScaleApiError, self).__init__(message, *args)
4+
super().__init__(message, *args)
55

66

77
class ApiClientError(ThreeScaleApiError):
@@ -13,4 +13,4 @@ def __init__(self, code, reason, body, message: str = None):
1313
msg = f"Response({self.code} {reason}): {body}"
1414
if message:
1515
msg += f"; {message}"
16-
super(ApiClientError, self).__init__(msg)
16+
super().__init__(msg)

threescale_api/resources.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def url(self) -> str:
6767
return self.application_plan.plans_url + f'/metrics/{self.metric.entity_id}/limits'
6868

6969
def list_per_app_plan(self, **kwargs):
70-
log.info(f"[LIST] List limits per app plan: {kwargs}")
70+
log.info("[LIST] List limits per app plan: %s", kwargs)
7171
url = self.parent.url + '/limits'
7272
response = self.rest.get(url=url, **kwargs)
7373
instance = self._create_instance(response=response)
@@ -177,7 +177,7 @@ def signup(self, params: dict, **kwargs) -> 'Account':
177177
**kwargs: Optional args
178178
Returns(Account): Account instance
179179
"""
180-
log.info(f"[SIGNUP] Create new Signup: {kwargs}")
180+
log.info("[SIGNUP] Create new Signup: %s", kwargs)
181181
url = self.threescale_client.admin_api_url + '/signup'
182182
response = self.rest.post(url=url, json=params, **kwargs)
183183
instance = self._create_instance(response=response)
@@ -191,7 +191,7 @@ def set_plan(self, entity_id: int, plan_id: int, **kwargs):
191191
**kwargs: Optional args
192192
Returns:
193193
"""
194-
log.info(f"[PLAN] Set plan for an account({entity_id}): {plan_id}")
194+
log.info("[PLAN] Set plan for an account(%s): %s", entity_id, plan_id)
195195
params = dict(plan_id=plan_id)
196196
url = self._entity_url(entity_id=entity_id) + '/change_plan'
197197
response = self.rest.put(url=url, json=params, **kwargs)
@@ -206,7 +206,7 @@ def send_message(self, entity_id: int, body: str, **kwargs) -> Dict:
206206
**kwargs: Optional args
207207
Returns(Dict): Response
208208
"""
209-
log.info(f"[MSG] Send message to account ({entity_id}): {body} {kwargs}")
209+
log.info("[MSG] Send message to account (%s): %s %s", entity_id, body, kwargs)
210210
params = dict(body=body)
211211
url = self._entity_url(entity_id=entity_id) + '/messages'
212212
response = self.rest.post(url=url, json=params, **kwargs)
@@ -252,22 +252,22 @@ def url(self) -> str:
252252
return self.parent.url + '/applications'
253253

254254
def change_plan(self, entity_id: int, plan_id: int, **kwargs):
255-
log.info(f"[PLAN] Change plan for application ({entity_id}) to {plan_id} {kwargs}")
255+
log.info("[PLAN] Change plan for application (%s) to %s %s", entity_id, plan_id, kwargs)
256256
params = dict(plan_id=plan_id)
257257
url = self._entity_url(entity_id=entity_id) + '/change_plan'
258258
response = self.rest.put(url=url, json=params, **kwargs)
259259
instance = utils.extract_response(response=response)
260260
return instance
261261

262262
def customize_plan(self, entity_id: int, **kwargs):
263-
log.info(f"[PLAN] Customize plan for application ({entity_id}) {kwargs}")
263+
log.info("[PLAN] Customize plan for application (%s) %s", entity_id, kwargs)
264264
url = self._entity_url(entity_id=entity_id) + '/customize_plan'
265265
response = self.rest.put(url=url, **kwargs)
266266
instance = utils.extract_response(response=response)
267267
return instance
268268

269269
def decustomize_plan(self, entity_id: int, **kwargs):
270-
log.info(f"[PLAN] Decustomize plan for application ({entity_id}) {kwargs}")
270+
log.info("[PLAN] Decustomize plan for application (%s) %s", entity_id, kwargs)
271271
url = self._entity_url(entity_id=entity_id) + '/decustomize_plan'
272272
response = self.rest.put(url=url, **kwargs)
273273
instance = utils.extract_response(response=response)
@@ -357,8 +357,8 @@ def url(self) -> str:
357357
class Analytics(DefaultClient):
358358
def _list_by_resource(self, resource_id: int, resource_type, metric_name: str = 'hits',
359359
since=None, period: str = 'year', **kwargs):
360-
log.info(f"List analytics by {resource_type} ({resource_id}) f"
361-
f"or metric (#{metric_name})")
360+
log.info("List analytics by %s (%s) for metric (#%s)", resource_type, resource_id,
361+
metric_name)
362362
params = dict(
363363
metric_name=metric_name,
364364
since=since,
@@ -388,9 +388,9 @@ def __init__(self, *args, entity_name='tenant', entity_collection='tenants', **k
388388
super().__init__(*args, entity_name=entity_name,
389389
entity_collection=entity_collection, **kwargs)
390390

391-
def read(self, id, **kwargs):
391+
def read(self, entity_id, **kwargs):
392392
log.debug(self._log_message("[GET] Read Tenant", args=kwargs))
393-
url = self._entity_url(entity_id=id)
393+
url = self._entity_url(entity_id=entity_id)
394394
response = self.rest.get(url=url, **kwargs)
395395
instance = self._create_instance(response=response)
396396
return instance
@@ -440,7 +440,7 @@ def url(self) -> str:
440440
return self.parent.url + '/proxy'
441441

442442
def deploy(self) -> 'Proxy':
443-
log.info(f"[DEPLOY] {self._entity_name} to Staging")
443+
log.info("[DEPLOY] %s to Staging", self._entity_name)
444444
url = f'{self.url}/deploy'
445445
response = self.rest.post(url)
446446
instance = self._create_instance(response=response)
@@ -487,7 +487,8 @@ def list(self, **kwargs):
487487

488488
def promote(self, version: int = 1, from_env: str = 'sandbox', to_env: str = 'production',
489489
**kwargs) -> 'Proxy':
490-
log.info(f"[PROMOTE] {self.service} version {version} from {from_env} to {to_env}")
490+
log.info("[PROMOTE] %s version %s from %s to %s", self.service, version, from_env,
491+
to_env)
491492
url = f'{self.url}/{from_env}/{version}/promote'
492493
params = dict(to=to_env)
493494
kwargs.update()
@@ -496,15 +497,15 @@ def promote(self, version: int = 1, from_env: str = 'sandbox', to_env: str = 'pr
496497
return instance
497498

498499
def latest(self, env: str = "sandbox") -> 'ProxyConfig':
499-
log.info(f"[LATEST] Get latest proxy configuration of {env}")
500+
log.info("[LATEST] Get latest proxy configuration of %s", env)
500501
self._env = env
501502
url = self.url + '/latest'
502503
response = self.rest.get(url=url)
503504
instance = self._create_instance(response=response)
504505
return instance
505506

506507
def version(self, version: int = 1, env: str = "sandbox") -> 'ProxyConfig':
507-
log.info(f"[VERSION] Get proxy configuration of {env} of version {version}")
508+
log.info("[VERSION] Get proxy configuration of %s of version %s", env, version)
508509
self._env = env
509510
url = f'{self.url}/{version}'
510511
response = self.rest.get(url=url)
@@ -873,7 +874,7 @@ def state_update(self, entity_id: int, state: InvoiceState, **kwargs):
873874
Values allowed (depend on the previous state):
874875
cancelled, failed, paid, unpaid, pending, finalized
875876
"""
876-
log.info(f"[Invoice] state changed for invoice ({entity_id}): {state}")
877+
log.info("[Invoice] state changed for invoice (%s): %s", entity_id, state)
877878
params = dict(state=state.value)
878879
url = self._entity_url(entity_id) + '/state'
879880
response = self.rest.put(url=url, json=params, **kwargs)
@@ -882,7 +883,7 @@ def state_update(self, entity_id: int, state: InvoiceState, **kwargs):
882883

883884
def charge(self, entity_id: int):
884885
"""Charge an Invoice."""
885-
log.info(f"[Invoice] charge invoice ({entity_id})")
886+
log.info("[Invoice] charge invoice (%s)", entity_id)
886887
url = self._entity_url(entity_id) + '/charge'
887888
response = self.rest.post(url)
888889
instance = self._create_instance(response=response)
@@ -974,15 +975,13 @@ def service(self) -> 'Service':
974975
def __getitem__(self, key):
975976
if "proxy_configs" in self.entity:
976977
return self.entity["proxy_configs"][key]
977-
else:
978-
return super().__getitem__(key)
978+
return super().__getitem__(key)
979979

980980
# Same problem as in __getitem__.
981981
def __len__(self):
982982
if "proxy_configs" in self.entity:
983983
return len(self.entity["proxy_configs"])
984-
else:
985-
return super().__len__()
984+
return super().__len__()
986985

987986

988987
class Policy(DefaultResource):

threescale_api/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ def delete(self, *args, **kwargs) -> requests.Response:
157157
def request2curl(request: requests.PreparedRequest) -> str:
158158
"""Create curl command corresponding to given request"""
159159

160+
# pylint: disable=consider-using-f-string
160161
cmd = ["curl", "-X %s" % shlex.quote(request.method)]
161162
if request.headers:
163+
# pylint: disable=consider-using-f-string
162164
cmd.extend([
163165
"-H %s" % shlex.quote(f"{key}: {value}")
164166
for key, value in request.headers.items()])
@@ -168,6 +170,7 @@ def request2curl(request: requests.PreparedRequest) -> str:
168170
body = body.decode("utf-8")
169171
if len(body) > 160:
170172
body = body[:160] + "..."
173+
# pylint: disable=consider-using-f-string
171174
cmd.append("-d %s" % shlex.quote(body))
172175
cmd.append(shlex.quote(request.url))
173176

0 commit comments

Comments
 (0)