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 77 78 79 80 81 82 83 84 85
|
# Copyright (c) 2021 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:`BaseTransport`
* :meth:`BaseTransport.bulk_read`
* :meth:`BaseTransport.bulk_write`
* :meth:`BaseTransport.close`
* :meth:`BaseTransport.connect`
"""
try:
from abc import ABC, abstractmethod
except ImportError: # pragma: no cover
from abc import ABCMeta, abstractmethod
class ABC(object): # pylint: disable=too-few-public-methods
"""A Python2-compatible `ABC` class.
"""
__metaclass__ = ABCMeta
class BaseTransport(ABC):
"""A base transport class.
"""
@abstractmethod
def close(self):
"""Close the connection.
"""
@abstractmethod
def connect(self, transport_timeout_s):
"""Create a connection to the device.
Parameters
----------
transport_timeout_s : float, None
A connection timeout
"""
@abstractmethod
def bulk_read(self, numbytes, transport_timeout_s):
"""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
def bulk_write(self, data, transport_timeout_s):
"""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
"""
|