-
Notifications
You must be signed in to change notification settings - Fork 59
/
base_transport_async.py
76 lines (54 loc) · 1.6 KB
/
base_transport_async.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (c) 2020 Jeff Irion and contributors
#
# This file is part of the adb-shell package.
"""A base class for transports used to communicate with a device.
* :class:`BaseTransportAsync`
* :meth:`BaseTransportAsync.bulk_read`
* :meth:`BaseTransportAsync.bulk_write`
* :meth:`BaseTransportAsync.close`
* :meth:`BaseTransportAsync.connect`
"""
from abc import ABC, abstractmethod
class BaseTransportAsync(ABC):
"""A base transport class.
"""
@abstractmethod
async def close(self):
"""Close the connection.
"""
@abstractmethod
async def connect(self, transport_timeout_s=None):
"""Create a connection to the device.
Parameters
----------
transport_timeout_s : float, None
A connection timeout
"""
@abstractmethod
async def bulk_read(self, numbytes, transport_timeout_s=None):
"""Read data from the device.
Parameters
----------
numbytes : int
The maximum amount of data to be received
transport_timeout_s : float, None
A timeout for the read operation
Returns
-------
bytes
The received data
"""
@abstractmethod
async def bulk_write(self, data, transport_timeout_s=None):
"""Send data to the device.
Parameters
----------
data : bytes
The data to be sent
transport_timeout_s : float, None
A timeout for the write operation
Returns
-------
int
The number of bytes sent
"""