-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
stream.py
51 lines (35 loc) · 1.05 KB
/
stream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import io
import json
import logging
log = logging.getLogger(__name__)
class Stream(object):
__shortname__ = "stream"
"""
This is a base class that should be inherited when implementing
different stream types. Should only be created by plugins.
"""
def __init__(self, session):
self.session = session
def __repr__(self):
return "<Stream()>"
def __json__(self):
return dict(type=type(self).shortname())
def open(self):
"""
Attempts to open a connection to the stream.
Returns a file-like object that can be used to read the stream data.
Raises :exc:`StreamError` on failure.
"""
raise NotImplementedError
@property
def json(self):
obj = self.__json__()
return json.dumps(obj)
@classmethod
def shortname(cls):
return cls.__shortname__
def to_url(self):
raise TypeError("{0} cannot be converted to a URL".format(self.shortname()))
class StreamIO(io.IOBase):
pass
__all__ = ["Stream", "StreamIO"]