Skip to content

Commit 6a5fbb3

Browse files
committed
flake8 linting fixes
1 parent b92d8ab commit 6a5fbb3

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

qencode/custom_params.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class CustomTranscodingParams(object):
88
"""CustomTranscodingParams
99
1010
:var source: String. Source video URI. Can be http(s) url or tus uri
11-
:var format: String. A list of objects, each describing params for a single output video stream (MP4, WEBM, HLS or MPEG-DASH)
12-
13-
"""
11+
:var format: String. A list of objects, each describing params for a single output
12+
video stream (MP4, WEBM, HLS or MPEG-DASH)
13+
"""
1414

1515
def __init__(self):
1616
self.source = None
@@ -143,11 +143,11 @@ def validate_params(self):
143143
self.error = True
144144
self.message = 'Params is required'
145145
return
146-
if not 'source' in self.params.__dict__:
146+
if 'source' not in self.params.__dict__:
147147
self.error = True
148148
self.message = 'Params: source is required'
149149
return
150-
if not 'format' in self.params.__dict__:
150+
if 'format' not in self.params.__dict__:
151151
self.error = True
152152
self.message = 'Params: format is required'
153153
return

qencode/task.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import json
22
import time
33

4-
from const import *
5-
from custom_params import CustomTranscodingParams, Query
6-
from utils import is_json, rm_key_if_null
4+
from . import const as constants
5+
from ._compat import string_types
6+
from .custom_params import CustomTranscodingParams, Query
7+
from .utils import is_json, rm_key_if_null
78

89

910
class Task(object):
@@ -19,19 +20,20 @@ def __init__(self, access_token, connect, debug=False, **kwargs):
1920
self._debug = debug
2021
self.message = ''
2122
self.error = None
22-
self.repeat = kwargs.get('repeats') if kwargs.get('repeats') else REPEAT
23+
self.repeat = (
24+
kwargs.get('repeats') if kwargs.get('repeats') else constants.REPEAT
25+
)
2326
self._create_task(1)
2427

2528
def start(self, profiles, video_url, **kwargs):
26-
"""Creating task and starting encode
27-
28-
:param profiles: String or List object. Profile uuid
29-
:param transfer_method: String. Transfer method uuid
30-
:param video_url: String. Url of source video
31-
:param payload: String.
32-
:return: None
33-
34-
"""
29+
"""Creating task and starting encode.
30+
31+
:param profiles: String or List object. Profile uuid
32+
:param transfer_method: String. Transfer method uuid
33+
:param video_url: String. Url of source video
34+
:param payload: String.
35+
:return: None
36+
"""
3537
if not self.error:
3638
# self._create_task(1)
3739
data = self._prepare_data(profiles, video_url, **kwargs)
@@ -42,11 +44,11 @@ def start(self, profiles, video_url, **kwargs):
4244
def custom_start(self, data, **kwargs):
4345
"""Creating task and starting encode
4446
45-
:param query: JSON object for query param. For examples: https://docs.qencode.com
46-
:param payload: String.
47-
:return: None
48-
49-
"""
47+
:param query:
48+
JSON object for query param. For examples: https://docs.qencode.com
49+
:param payload: String.
50+
:return: None
51+
"""
5052
if data is None:
5153
self.error = True
5254
self.message = 'Params is required'
@@ -75,20 +77,20 @@ def progress_changed(self, callback, *args, **kwargs):
7577
if status['error']:
7678
return callback(status, *args, **kwargs)
7779
callback(status, *args, **kwargs)
78-
if status.get('status') in COMPLETED_STATUS:
80+
if status.get('status') in constants.COMPLETED_STATUS:
7981
break
80-
time.sleep(SLEEP_REGULAR)
82+
time.sleep(constants.SLEEP_REGULAR)
8183

8284
def task_completed(self, callback, *args, **kwargs):
8385
while 1:
8486
status = self._status()
8587
if status['error']:
8688
return callback(status, *args, **kwargs)
87-
if status.get('status') in COMPLETED_STATUS:
89+
if status.get('status') in constants.COMPLETED_STATUS:
8890
return callback(status, *args, **kwargs)
89-
if status.get('status') in COMPLETED_STATUS:
91+
if status.get('status') in constants.COMPLETED_STATUS:
9092
break
91-
time.sleep(SLEEP_REGULAR)
93+
time.sleep(constants.SLEEP_REGULAR)
9294

9395
def _prepare_query(self, params):
9496
if isinstance(params, CustomTranscodingParams):
@@ -108,20 +110,19 @@ def _prepare_query(self, params):
108110
query = rm_key_if_null(params)
109111
return json.dumps(query)
110112

111-
if isinstance(params, basestring):
113+
if isinstance(params, string_types):
112114
if is_json(params):
113115
query = rm_key_if_null(params)
114116
return query
115117
else:
116118
self.error = True
119+
error_msg = "JSON is not well formatted"
117120
try:
118-
self.message = "JSON is not well formatted: {0} Is not defined".format(
119-
params
120-
)
121-
except Exception as e:
121+
self.message = "{}: {} Is not defined".format(error_msg, params)
122+
except Exception:
122123
pass
123124
finally:
124-
self.message = "JSON is not well formatted"
125+
self.message = error_msg
125126

126127
def _prepare_data(self, profiles, video_url, **kwargs):
127128
data = dict(
@@ -157,8 +158,8 @@ def _create_task(self, count):
157158
self.message = res.get('message')
158159

159160
if self.error and self.error == 8:
160-
if count < REPEAT:
161-
time.sleep(SLEEP_ERROR)
161+
if count < constants.REPEAT:
162+
time.sleep(constants.SLEEP_ERROR)
162163
self._create_task(count + 1)
163164

164165
def _start_encode(self, api_name, data):
@@ -174,7 +175,7 @@ def _status(self):
174175
response = self.connect.post(self.status_url, dict(task_tokens=self.task_token))
175176
status = None
176177

177-
if response['error'] == ERROR_BAD_TOKENS:
178+
if response['error'] == constants.ERROR_BAD_TOKENS:
178179
raise ValueError('Bad token: ' + str(self.task_token))
179180

180181
if 'statuses' in response and self.task_token in response['statuses']:

qencode/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import logging
33
import sys
44

5+
from ._compat import string_types
6+
57

68
def is_number(s):
79
try:
810
float(s)
911
return True
10-
except:
12+
except Exception:
1113
return False
1214

1315

@@ -34,7 +36,7 @@ def rm_attributes_if_null(class_obj):
3436
def rm_key_if_null(obj):
3537
if isinstance(obj, dict):
3638
return _rm_key(obj)
37-
elif isinstance(obj, basestring):
39+
elif isinstance(obj, string_types):
3840
res = _rm_key(json.loads(obj))
3941
return json.dumps(res)
4042

0 commit comments

Comments
 (0)