Skip to content

Commit 1a8760e

Browse files
committed
Style Changes and Linter
1 parent 6931dbb commit 1a8760e

31 files changed

+2725
-1783
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ docs/_build/
4545
venv/
4646

4747
# Mac Desktop files
48-
.DS_Store
48+
.DS_Store
49+
50+
# IDE
51+
.vscode

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
OpenTok Python SDK
33
==================
44

5-
.. image:: https://travis-ci.org/opentok/Opentok-Python-SDK.svg
6-
:target: https://travis-ci.org/opentok/Opentok-Python-SDK
7-
85
The OpenTok Python SDK lets you generate
96
`sessions <http://tokbox.com/opentok/tutorials/create-session/>`_ and
107
`tokens <http://tokbox.com/opentok/tutorials/create-token/>`_ for `OpenTok <http://www.tokbox.com/>`_

dev_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
black
2+
pylint

opentok/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ForceDisconnectError,
88
ArchiveError,
99
SetStreamClassError,
10-
BroadcastError
10+
BroadcastError,
1111
)
1212
from .version import __version__
1313
from .stream import Stream

opentok/archives.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@
33
import json
44
import pytz
55
from enum import Enum
6+
67
if PY3:
78
from datetime import timezone
89

910
# compat
1011
from six.moves import map
1112

12-
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime) or isinstance(obj, date) else None
13+
dthandler = (
14+
lambda obj: obj.isoformat()
15+
if isinstance(obj, datetime) or isinstance(obj, date)
16+
else None
17+
)
18+
1319

1420
class OutputModes(Enum):
1521
"""List of valid settings for the output_mode parameter of the OpenTok.start_archive()
1622
method."""
17-
composed = u('composed')
23+
24+
composed = u("composed")
1825
"""All streams in the archive are recorded to a single (composed) file."""
19-
individual = u('individual')
26+
individual = u("individual")
2027
"""Each stream in the archive is recorded to an individual file."""
2128

29+
2230
class Archive(object):
2331
"""Represents an archive of an OpenTok session.
2432
@@ -87,22 +95,26 @@ class Archive(object):
8795

8896
def __init__(self, sdk, values):
8997
self.sdk = sdk
90-
self.id = values.get('id')
91-
self.name = values.get('name')
92-
self.status = values.get('status')
93-
self.session_id = values.get('sessionId')
94-
self.partner_id = values.get('partnerId')
98+
self.id = values.get("id")
99+
self.name = values.get("name")
100+
self.status = values.get("status")
101+
self.session_id = values.get("sessionId")
102+
self.partner_id = values.get("partnerId")
95103
if PY2:
96-
self.created_at = datetime.fromtimestamp(values.get('createdAt') / 1000, pytz.UTC)
104+
self.created_at = datetime.fromtimestamp(
105+
values.get("createdAt") / 1000, pytz.UTC
106+
)
97107
if PY3:
98-
self.created_at = datetime.fromtimestamp(values.get('createdAt') // 1000, timezone.utc)
99-
self.size = values.get('size')
100-
self.duration = values.get('duration')
101-
self.has_audio = values.get('hasAudio')
102-
self.has_video = values.get('hasVideo')
103-
self.output_mode = OutputModes[values.get('outputMode', 'composed')]
104-
self.url = values.get('url')
105-
self.resolution = values.get('resolution')
108+
self.created_at = datetime.fromtimestamp(
109+
values.get("createdAt") // 1000, timezone.utc
110+
)
111+
self.size = values.get("size")
112+
self.duration = values.get("duration")
113+
self.has_audio = values.get("hasAudio")
114+
self.has_video = values.get("hasVideo")
115+
self.output_mode = OutputModes[values.get("outputMode", "composed")]
116+
self.url = values.get("url")
117+
self.resolution = values.get("resolution")
106118

107119
def stop(self):
108120
"""
@@ -112,7 +124,7 @@ def stop(self):
112124
disconnected from the session being archived.
113125
"""
114126
temp_archive = self.sdk.stop_archive(self.id)
115-
for k,v in iteritems(temp_archive.attrs()):
127+
for k, v in iteritems(temp_archive.attrs()):
116128
setattr(self, k, v)
117129

118130
def delete(self):
@@ -138,21 +150,18 @@ def json(self):
138150
"""
139151
return json.dumps(self.attrs(), default=dthandler, indent=4)
140152

141-
class ArchiveList(object):
142153

154+
class ArchiveList(object):
143155
def __init__(self, sdk, values):
144-
self.count = values.get('count')
145-
self.items = list(map(lambda x: Archive(sdk, x), values.get('items', [])))
156+
self.count = values.get("count")
157+
self.items = list(map(lambda x: Archive(sdk, x), values.get("items", [])))
146158

147159
def __iter__(self):
148160
for x in self.items:
149161
yield x
150162

151163
def attrs(self):
152-
return {
153-
'count': self.count,
154-
'items': map(Archive.attrs, self.items)
155-
}
164+
return {"count": self.count, "items": map(Archive.attrs, self.items)}
156165

157166
def json(self):
158167
return json.dumps(self.attrs(), default=dthandler, indent=4)
@@ -161,7 +170,9 @@ def __getitem__(self, key):
161170
return self.items.get(key)
162171

163172
def __setitem__(self, key, item):
164-
raise ArchiveError(u('Cannot set item {0} for key {1} in Archive object').format(item, key))
173+
raise ArchiveError(
174+
u("Cannot set item {0} for key {1} in Archive object").format(item, key)
175+
)
165176

166177
def __len__(self):
167178
return len(self.items)

opentok/broadcast.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import json
22

3+
34
class Broadcast(object):
45
"""
56
Represents a live streaming broadcast
67
"""
78

89
def __init__(self, kwargs):
9-
self.id = kwargs.get('id')
10-
self.sessionId = kwargs.get('sessionId')
11-
self.projectId = kwargs.get('projectId')
12-
self.createdAt = kwargs.get('createdAt')
13-
self.updatedAt = kwargs.get('updatedAt')
14-
self.resolution = kwargs.get('resolution')
15-
self.status = kwargs.get('status')
16-
self.broadcastUrls = kwargs.get('broadcastUrls')
10+
self.id = kwargs.get("id")
11+
self.sessionId = kwargs.get("sessionId")
12+
self.projectId = kwargs.get("projectId")
13+
self.createdAt = kwargs.get("createdAt")
14+
self.updatedAt = kwargs.get("updatedAt")
15+
self.resolution = kwargs.get("resolution")
16+
self.status = kwargs.get("status")
17+
self.broadcastUrls = kwargs.get("broadcastUrls")
1718

1819
def json(self):
1920
"""

opentok/endpoints.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,94 @@ class Endpoints(object):
33
For internal use.
44
Class that provides the endpoint urls
55
"""
6+
67
def __init__(self, api_url, api_key):
78
self.api_url = api_url
89
self.api_key = api_key
910

1011
def session_url(self):
11-
url = self.api_url + '/session/create'
12+
url = self.api_url + "/session/create"
1213
return url
1314

1415
def archive_url(self, archive_id=None):
15-
url = self.api_url + '/v2/project/' + self.api_key + '/archive'
16+
url = self.api_url + "/v2/project/" + self.api_key + "/archive"
1617
if archive_id:
17-
url = url + '/' + archive_id
18+
url = url + "/" + archive_id
1819
return url
1920

2021
def signaling_url(self, session_id, connection_id=None):
21-
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id
22+
url = self.api_url + "/v2/project/" + self.api_key + "/session/" + session_id
2223

2324
if connection_id:
24-
url += '/connection/' + connection_id
25+
url += "/connection/" + connection_id
2526

26-
url += '/signal'
27+
url += "/signal"
2728
return url
2829

2930
def get_stream_url(self, session_id, stream_id=None):
3031
""" this method returns the url to get streams information """
31-
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id + '/stream'
32+
url = (
33+
self.api_url
34+
+ "/v2/project/"
35+
+ self.api_key
36+
+ "/session/"
37+
+ session_id
38+
+ "/stream"
39+
)
3240
if stream_id:
33-
url = url + '/' + stream_id
41+
url = url + "/" + stream_id
3442
return url
3543

3644
def force_disconnect_url(self, session_id, connection_id):
3745
""" this method returns the force disconnect url endpoint """
3846
url = (
39-
self.api_url + '/v2/project/' + self.api_key + '/session/' +
40-
session_id + '/connection/' + connection_id
47+
self.api_url
48+
+ "/v2/project/"
49+
+ self.api_key
50+
+ "/session/"
51+
+ session_id
52+
+ "/connection/"
53+
+ connection_id
4154
)
4255
return url
4356

4457
def set_archive_layout_url(self, archive_id):
4558
""" this method returns the url to set the archive layout """
46-
url = self.api_url + '/v2/project/' + self.api_key + '/archive/' + archive_id + '/layout'
59+
url = (
60+
self.api_url
61+
+ "/v2/project/"
62+
+ self.api_key
63+
+ "/archive/"
64+
+ archive_id
65+
+ "/layout"
66+
)
4767
return url
4868

4969
def dial_url(self):
5070
""" this method returns the url to initialize a SIP call """
51-
url = self.api_url + '/v2/project/' + self.api_key + '/dial'
71+
url = self.api_url + "/v2/project/" + self.api_key + "/dial"
5272
return url
5373

5474
def set_stream_class_lists_url(self, session_id):
5575
""" this method returns the url to set the stream class list """
56-
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id + '/stream'
76+
url = (
77+
self.api_url
78+
+ "/v2/project/"
79+
+ self.api_key
80+
+ "/session/"
81+
+ session_id
82+
+ "/stream"
83+
)
5784
return url
5885

5986
def broadcast_url(self, broadcast_id=None, stop=False, layout=False):
6087
""" this method returns urls for working with broadcast """
61-
url = self.api_url + '/v2/project/' + self.api_key + '/broadcast'
88+
url = self.api_url + "/v2/project/" + self.api_key + "/broadcast"
6289

6390
if broadcast_id:
64-
url = url + '/' + broadcast_id
91+
url = url + "/" + broadcast_id
6592
if stop:
66-
url = url + '/stop'
93+
url = url + "/stop"
6794
if layout:
68-
url = url + '/layout'
95+
url = url + "/layout"
6996
return url

opentok/exceptions.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,90 @@
11
class OpenTokException(Exception):
2-
"""Defines exceptions thrown by the OpenTok SDK.
3-
"""
2+
"""Defines exceptions thrown by the OpenTok SDK."""
3+
44
pass
55

66

77
class RequestError(OpenTokException):
88
"""Indicates an error during the request. Most likely an error connecting
99
to the OpenTok API servers. (HTTP 500 error).
1010
"""
11+
1112
pass
1213

1314

1415
class AuthError(OpenTokException):
1516
"""Indicates that the problem was likely with credentials. Check your API
1617
key and API secret and try again.
1718
"""
19+
1820
pass
1921

2022

2123
class NotFoundError(OpenTokException):
2224
"""Indicates that the element requested was not found. Check the parameters
2325
of the request.
2426
"""
27+
2528
pass
2629

2730

2831
class ArchiveError(OpenTokException):
2932
"""Indicates that there was a archive specific problem, probably the status
3033
of the requested archive is invalid.
3134
"""
35+
3236
pass
3337

38+
3439
class SignalingError(OpenTokException):
3540
"""Indicates that there was a signaling specific problem, one of the parameter
3641
is invalid or the type|data string doesn't have a correct size"""
42+
3743
pass
3844

45+
3946
class GetStreamError(OpenTokException):
4047
"""Indicates that the data in the request is invalid, or the session_id or stream_id
4148
are invalid"""
49+
4250
pass
4351

52+
4453
class ForceDisconnectError(OpenTokException):
4554
"""
4655
Indicates that there was a force disconnect specific problem:
4756
One of the arguments is invalid or the client specified by the connectionId property
4857
is not connected to the session
4958
"""
59+
5060
pass
5161

62+
5263
class SipDialError(OpenTokException):
5364
"""
5465
Indicates that there was a SIP dial specific problem:
5566
The Session ID passed in is invalid or you attempt to start a SIP call for a session
5667
that does not use the OpenTok Media Router.
5768
"""
69+
5870
pass
5971

72+
6073
class SetStreamClassError(OpenTokException):
6174
"""
6275
Indicates that there is invalid data in the JSON request.
6376
It may also indicate that invalid layout options have been passed
6477
"""
78+
6579
pass
6680

81+
6782
class BroadcastError(OpenTokException):
6883
"""
6984
Indicates that data in your request data is invalid JSON. It may also indicate
7085
that you passed in invalid layout options. Or you have exceeded the limit of five
7186
simultaneous RTMP streams for an OpenTok session. Or you specified and invalid resolution.
7287
Or The broadcast has already started for the session
7388
"""
89+
7490
pass

0 commit comments

Comments
 (0)