@@ -220,36 +220,48 @@ def generate_token(
220
220
expire_time = int (expire_time )
221
221
except (ValueError , TypeError ):
222
222
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
+ )
224
226
)
225
227
else :
226
228
expire_time = int (time .time ()) + (60 * 60 * 24 ) # 1 day
227
229
228
230
# validations
229
231
if not text_type (session_id ):
230
232
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
+ )
232
236
)
233
237
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
+ )
235
241
now = int (time .time ())
236
242
if expire_time < now :
237
243
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
+ )
239
247
)
240
248
if expire_time > now + (60 * 60 * 24 * 30 ): # 30 days
241
249
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 )
245
253
)
246
254
if data and len (data ) > 1000 :
247
255
raise OpenTokException (
248
256
u ("Cannot generate token, data must be less than 1000 characters" )
249
257
)
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
+ ):
251
261
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
+ )
253
265
)
254
266
initial_layout_class_list_serialized = u (" " ).join (initial_layout_class_list )
255
267
if len (initial_layout_class_list_serialized ) > 1000 :
@@ -270,7 +282,9 @@ def generate_token(
270
282
parts = decoded_session_id .decode ("utf-8" ).split (u ("~" ))
271
283
except Exception as e :
272
284
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
+ )
274
288
)
275
289
if self .api_key not in parts :
276
290
raise OpenTokException (
@@ -389,15 +403,21 @@ def create_session(
389
403
options = {}
390
404
if not isinstance (media_mode , MediaModes ):
391
405
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
+ )
393
409
)
394
410
if not isinstance (archive_mode , ArchiveModes ):
395
411
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
+ )
397
415
)
398
416
if archive_mode == ArchiveModes .always and media_mode != MediaModes .routed :
399
417
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
+ )
401
421
)
402
422
403
423
if archive_name is not None :
@@ -478,7 +498,9 @@ def create_session(
478
498
)
479
499
)
480
500
481
- session_id = dom .getElementsByTagName ("session_id" )[0 ].childNodes [0 ].nodeValue
501
+ session_id = (
502
+ dom .getElementsByTagName ("session_id" )[0 ].childNodes [0 ].nodeValue
503
+ )
482
504
return Session (
483
505
self ,
484
506
session_id ,
@@ -596,12 +618,16 @@ def start_archive(
596
618
"""
597
619
if not isinstance (output_mode , OutputModes ):
598
620
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
+ )
600
624
)
601
625
602
626
if resolution and output_mode == OutputModes .individual :
603
627
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
+ )
605
631
)
606
632
607
633
payload = {
@@ -863,7 +889,9 @@ def add_archive_stream(
863
889
else :
864
890
raise RequestError ("An unexpected error occurred." , response .status_code )
865
891
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 :
867
895
"""
868
896
This method will remove streams from the archive with removeStream.
869
897
@@ -1086,7 +1114,9 @@ def force_disconnect(self, session_id, connection_id):
1086
1114
else :
1087
1115
raise RequestError ("An unexpected error occurred" , response .status_code )
1088
1116
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
+ ):
1090
1120
"""
1091
1121
Use this method to change the layout of videos in an OpenTok archive
1092
1122
@@ -1308,7 +1338,9 @@ class names (Strings) to apply to the stream. For example:
1308
1338
else :
1309
1339
raise RequestError ("OpenTok server error." , response .status_code )
1310
1340
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
+ ):
1312
1344
"""
1313
1345
Use this method to start a live streaming broadcast for an OpenTok session. This broadcasts
1314
1346
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.
1391
1423
"""
1392
1424
1393
1425
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
+ ):
1395
1430
if (
1396
1431
options ["outputs" ]["hls" ]["lowLatency" ] == True
1397
1432
and options ["outputs" ]["hls" ]["dvr" ] == True
@@ -1485,7 +1520,8 @@ def stop_broadcast(self, broadcast_id):
1485
1520
raise AuthError ("Authentication error." )
1486
1521
elif response .status_code == 409 :
1487
1522
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."
1489
1525
)
1490
1526
else :
1491
1527
raise RequestError ("OpenTok server error." , response .status_code )
@@ -1539,11 +1575,15 @@ def add_broadcast_stream(
1539
1575
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1540
1576
)
1541
1577
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
+ )
1543
1581
else :
1544
1582
raise RequestError ("An unexpected error occurred." , response .status_code )
1545
1583
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 :
1547
1587
"""
1548
1588
This method will remove streams from the broadcast with removeStream.
1549
1589
@@ -1580,7 +1620,9 @@ def remove_broadcast_stream(self, broadcast_id: str, stream_id: str) -> requests
1580
1620
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1581
1621
)
1582
1622
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
+ )
1584
1626
else :
1585
1627
raise RequestError ("OpenTok server error." , response .status_code )
1586
1628
@@ -1906,12 +1948,16 @@ def connect_audio_to_websocket(
1906
1948
1907
1949
def validate_websocket_options (self , options ):
1908
1950
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
+ )
1910
1954
if "uri" not in options :
1911
1955
raise InvalidWebSocketOptionsError ("Provide a WebSocket URI." )
1912
1956
1913
1957
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 ()
1915
1961
1916
1962
def _create_jwt_auth_header (self ):
1917
1963
payload = {
@@ -1952,7 +1998,9 @@ def mute_all(
1952
1998
else :
1953
1999
options = {"active" : True , "excludedStreams" : []}
1954
2000
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
+ )
1956
2004
1957
2005
if response :
1958
2006
return response
@@ -1987,7 +2035,9 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
1987
2035
options = {"active" : False }
1988
2036
url = self .endpoints .get_mute_all_url (session_id )
1989
2037
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
+ )
1991
2041
1992
2042
try :
1993
2043
if response :
@@ -2065,7 +2115,9 @@ def play_dtmf(
2065
2115
url = self .endpoints .get_dtmf_specific_url (session_id , connection_id )
2066
2116
payload = {"digits" : digits }
2067
2117
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
+ )
2069
2121
2070
2122
if response .status_code == 200 :
2071
2123
return response
@@ -2134,7 +2186,9 @@ def mute_all(
2134
2186
else :
2135
2187
options = {"active" : True , "excludedStreams" : []}
2136
2188
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
+ )
2138
2192
2139
2193
if response :
2140
2194
return response
@@ -2167,7 +2221,9 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
2167
2221
options = {"active" : False }
2168
2222
url = self .endpoints .get_mute_all_url (session_id )
2169
2223
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
+ )
2171
2227
2172
2228
try :
2173
2229
if response :
@@ -2239,7 +2295,9 @@ def play_dtmf(
2239
2295
url = self .endpoints .get_dtmf_specific_url (session_id , connection_id )
2240
2296
payload = {"digits" : digits }
2241
2297
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
+ )
2243
2301
2244
2302
if response .status_code == 200 :
2245
2303
return response
0 commit comments