Skip to content

Commit 1f23e2d

Browse files
committed
reverting black to 88 lines
1 parent 7c3415f commit 1f23e2d

File tree

3 files changed

+157
-54
lines changed

3 files changed

+157
-54
lines changed

opentok/opentok.py

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -220,36 +220,48 @@ def generate_token(
220220
expire_time = int(expire_time)
221221
except (ValueError, TypeError):
222222
raise OpenTokException(
223-
u("Cannot generate token, invalid expire time {0}").format(expire_time)
223+
u("Cannot generate token, invalid expire time {0}").format(
224+
expire_time
225+
)
224226
)
225227
else:
226228
expire_time = int(time.time()) + (60 * 60 * 24) # 1 day
227229

228230
# validations
229231
if not text_type(session_id):
230232
raise OpenTokException(
231-
u("Cannot generate token, session_id was not valid {0}").format(session_id)
233+
u("Cannot generate token, session_id was not valid {0}").format(
234+
session_id
235+
)
232236
)
233237
if not isinstance(role, Roles):
234-
raise OpenTokException(u("Cannot generate token, {0} is not a valid role").format(role))
238+
raise OpenTokException(
239+
u("Cannot generate token, {0} is not a valid role").format(role)
240+
)
235241
now = int(time.time())
236242
if expire_time < now:
237243
raise OpenTokException(
238-
u("Cannot generate token, expire_time is not in the future {0}").format(expire_time)
244+
u("Cannot generate token, expire_time is not in the future {0}").format(
245+
expire_time
246+
)
239247
)
240248
if expire_time > now + (60 * 60 * 24 * 30): # 30 days
241249
raise OpenTokException(
242-
u("Cannot generate token, expire_time is not in the next 30 days {0}").format(
243-
expire_time
244-
)
250+
u(
251+
"Cannot generate token, expire_time is not in the next 30 days {0}"
252+
).format(expire_time)
245253
)
246254
if data and len(data) > 1000:
247255
raise OpenTokException(
248256
u("Cannot generate token, data must be less than 1000 characters")
249257
)
250-
if initial_layout_class_list and not all(text_type(c) for c in initial_layout_class_list):
258+
if initial_layout_class_list and not all(
259+
text_type(c) for c in initial_layout_class_list
260+
):
251261
raise OpenTokException(
252-
u("Cannot generate token, all items in initial_layout_class_list must be strings")
262+
u(
263+
"Cannot generate token, all items in initial_layout_class_list must be strings"
264+
)
253265
)
254266
initial_layout_class_list_serialized = u(" ").join(initial_layout_class_list)
255267
if len(initial_layout_class_list_serialized) > 1000:
@@ -270,7 +282,9 @@ def generate_token(
270282
parts = decoded_session_id.decode("utf-8").split(u("~"))
271283
except Exception as e:
272284
raise OpenTokException(
273-
u("Cannot generate token, the session_id {0} was not valid").format(session_id)
285+
u("Cannot generate token, the session_id {0} was not valid").format(
286+
session_id
287+
)
274288
)
275289
if self.api_key not in parts:
276290
raise OpenTokException(
@@ -389,15 +403,21 @@ def create_session(
389403
options = {}
390404
if not isinstance(media_mode, MediaModes):
391405
raise OpenTokException(
392-
u("Cannot create session, {0} is not a valid media mode").format(media_mode)
406+
u("Cannot create session, {0} is not a valid media mode").format(
407+
media_mode
408+
)
393409
)
394410
if not isinstance(archive_mode, ArchiveModes):
395411
raise OpenTokException(
396-
u("Cannot create session, {0} is not a valid archive mode").format(archive_mode)
412+
u("Cannot create session, {0} is not a valid archive mode").format(
413+
archive_mode
414+
)
397415
)
398416
if archive_mode == ArchiveModes.always and media_mode != MediaModes.routed:
399417
raise OpenTokException(
400-
u("A session with always archive mode must also have the routed media mode.")
418+
u(
419+
"A session with always archive mode must also have the routed media mode."
420+
)
401421
)
402422

403423
if archive_name is not None:
@@ -478,7 +498,9 @@ def create_session(
478498
)
479499
)
480500

481-
session_id = dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
501+
session_id = (
502+
dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
503+
)
482504
return Session(
483505
self,
484506
session_id,
@@ -596,12 +618,16 @@ def start_archive(
596618
"""
597619
if not isinstance(output_mode, OutputModes):
598620
raise OpenTokException(
599-
u("Cannot start archive, {0} is not a valid output mode").format(output_mode)
621+
u("Cannot start archive, {0} is not a valid output mode").format(
622+
output_mode
623+
)
600624
)
601625

602626
if resolution and output_mode == OutputModes.individual:
603627
raise OpenTokException(
604-
u("Invalid parameters: Resolution cannot be supplied for individual output mode.")
628+
u(
629+
"Invalid parameters: Resolution cannot be supplied for individual output mode."
630+
)
605631
)
606632

607633
payload = {
@@ -863,7 +889,9 @@ def add_archive_stream(
863889
else:
864890
raise RequestError("An unexpected error occurred.", response.status_code)
865891

866-
def remove_archive_stream(self, archive_id: str, stream_id: str) -> requests.Response:
892+
def remove_archive_stream(
893+
self, archive_id: str, stream_id: str
894+
) -> requests.Response:
867895
"""
868896
This method will remove streams from the archive with removeStream.
869897
@@ -1086,7 +1114,9 @@ def force_disconnect(self, session_id, connection_id):
10861114
else:
10871115
raise RequestError("An unexpected error occurred", response.status_code)
10881116

1089-
def set_archive_layout(self, archive_id, layout_type, stylesheet=None, screenshare_type=None):
1117+
def set_archive_layout(
1118+
self, archive_id, layout_type, stylesheet=None, screenshare_type=None
1119+
):
10901120
"""
10911121
Use this method to change the layout of videos in an OpenTok archive
10921122
@@ -1308,7 +1338,9 @@ class names (Strings) to apply to the stream. For example:
13081338
else:
13091339
raise RequestError("OpenTok server error.", response.status_code)
13101340

1311-
def start_broadcast(self, session_id, options, stream_mode=BroadcastStreamModes.auto):
1341+
def start_broadcast(
1342+
self, session_id, options, stream_mode=BroadcastStreamModes.auto
1343+
):
13121344
"""
13131345
Use this method to start a live streaming broadcast for an OpenTok session. This broadcasts
13141346
the session to an HLS (HTTP live streaming) or to RTMP streams. To successfully start
@@ -1391,7 +1423,10 @@ def start_broadcast(self, session_id, options, stream_mode=BroadcastStreamModes.
13911423
"""
13921424

13931425
if "hls" in options["outputs"]:
1394-
if "lowLatency" in options["outputs"]["hls"] and "dvr" in options["outputs"]["hls"]:
1426+
if (
1427+
"lowLatency" in options["outputs"]["hls"]
1428+
and "dvr" in options["outputs"]["hls"]
1429+
):
13951430
if (
13961431
options["outputs"]["hls"]["lowLatency"] == True
13971432
and options["outputs"]["hls"]["dvr"] == True
@@ -1485,7 +1520,8 @@ def stop_broadcast(self, broadcast_id):
14851520
raise AuthError("Authentication error.")
14861521
elif response.status_code == 409:
14871522
raise BroadcastError(
1488-
"The broadcast (with the specified ID) was not found or it has already " "stopped."
1523+
"The broadcast (with the specified ID) was not found or it has already "
1524+
"stopped."
14891525
)
14901526
else:
14911527
raise RequestError("OpenTok server error.", response.status_code)
@@ -1539,11 +1575,15 @@ def add_broadcast_stream(
15391575
"Your broadcast is configured with a streamMode that does not support stream manipulation."
15401576
)
15411577
elif response.status_code == 409:
1542-
raise BroadcastError("The broadcast has already started for the session.")
1578+
raise BroadcastError(
1579+
"The broadcast has already started for the session."
1580+
)
15431581
else:
15441582
raise RequestError("An unexpected error occurred.", response.status_code)
15451583

1546-
def remove_broadcast_stream(self, broadcast_id: str, stream_id: str) -> requests.Response:
1584+
def remove_broadcast_stream(
1585+
self, broadcast_id: str, stream_id: str
1586+
) -> requests.Response:
15471587
"""
15481588
This method will remove streams from the broadcast with removeStream.
15491589
@@ -1580,7 +1620,9 @@ def remove_broadcast_stream(self, broadcast_id: str, stream_id: str) -> requests
15801620
"Your broadcast is configured with a streamMode that does not support stream manipulation."
15811621
)
15821622
elif response.status_code == 409:
1583-
raise BroadcastError("The broadcast has already started for the session.")
1623+
raise BroadcastError(
1624+
"The broadcast has already started for the session."
1625+
)
15841626
else:
15851627
raise RequestError("OpenTok server error.", response.status_code)
15861628

@@ -1906,12 +1948,16 @@ def connect_audio_to_websocket(
19061948

19071949
def validate_websocket_options(self, options):
19081950
if type(options) is not dict:
1909-
raise InvalidWebSocketOptionsError("Must pass WebSocket options as a dictionary.")
1951+
raise InvalidWebSocketOptionsError(
1952+
"Must pass WebSocket options as a dictionary."
1953+
)
19101954
if "uri" not in options:
19111955
raise InvalidWebSocketOptionsError("Provide a WebSocket URI.")
19121956

19131957
def _sign_string(self, string, secret):
1914-
return hmac.new(secret.encode("utf-8"), string.encode("utf-8"), hashlib.sha1).hexdigest()
1958+
return hmac.new(
1959+
secret.encode("utf-8"), string.encode("utf-8"), hashlib.sha1
1960+
).hexdigest()
19151961

19161962
def _create_jwt_auth_header(self):
19171963
payload = {
@@ -1952,7 +1998,9 @@ def mute_all(
19521998
else:
19531999
options = {"active": True, "excludedStreams": []}
19542000

1955-
response = requests.post(url, headers=self.get_headers(), data=json.dumps(options))
2001+
response = requests.post(
2002+
url, headers=self.get_headers(), data=json.dumps(options)
2003+
)
19562004

19572005
if response:
19582006
return response
@@ -1987,7 +2035,9 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
19872035
options = {"active": False}
19882036
url = self.endpoints.get_mute_all_url(session_id)
19892037

1990-
response = requests.post(url, headers=self.get_headers(), data=json.dumps(options))
2038+
response = requests.post(
2039+
url, headers=self.get_headers(), data=json.dumps(options)
2040+
)
19912041

19922042
try:
19932043
if response:
@@ -2065,7 +2115,9 @@ def play_dtmf(
20652115
url = self.endpoints.get_dtmf_specific_url(session_id, connection_id)
20662116
payload = {"digits": digits}
20672117

2068-
response = requests.post(url, headers=self.get_json_headers(), data=json.dumps(payload))
2118+
response = requests.post(
2119+
url, headers=self.get_json_headers(), data=json.dumps(payload)
2120+
)
20692121

20702122
if response.status_code == 200:
20712123
return response
@@ -2134,7 +2186,9 @@ def mute_all(
21342186
else:
21352187
options = {"active": True, "excludedStreams": []}
21362188

2137-
response = requests.post(url, headers=self.get_headers(), data=json.dumps(options))
2189+
response = requests.post(
2190+
url, headers=self.get_headers(), data=json.dumps(options)
2191+
)
21382192

21392193
if response:
21402194
return response
@@ -2167,7 +2221,9 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
21672221
options = {"active": False}
21682222
url = self.endpoints.get_mute_all_url(session_id)
21692223

2170-
response = requests.post(url, headers=self.get_headers(), data=json.dumps(options))
2224+
response = requests.post(
2225+
url, headers=self.get_headers(), data=json.dumps(options)
2226+
)
21712227

21722228
try:
21732229
if response:
@@ -2239,7 +2295,9 @@ def play_dtmf(
22392295
url = self.endpoints.get_dtmf_specific_url(session_id, connection_id)
22402296
payload = {"digits": digits}
22412297

2242-
response = requests.post(url, headers=self.get_json_headers(), data=json.dumps(payload))
2298+
response = requests.post(
2299+
url, headers=self.get_json_headers(), data=json.dumps(payload)
2300+
)
22432301

22442302
if response.status_code == 200:
22452303
return response

0 commit comments

Comments
 (0)