From 02d88c946844b5b5e51925dd3d3f05a29a8dda01 Mon Sep 17 00:00:00 2001 From: martin2250 Date: Thu, 6 Dec 2018 12:36:25 +0100 Subject: [PATCH 1/2] Fix using file instead of io.IOBase --- adb/adb_commands.py | 2 +- adb/filesync_protocol.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/adb/adb_commands.py b/adb/adb_commands.py index f3667c8..0eca2e3 100644 --- a/adb/adb_commands.py +++ b/adb/adb_commands.py @@ -297,7 +297,7 @@ def Pull(self, device_filename, dest_file=None, timeout_ms=None, progress_callba dest_file = io.BytesIO() elif isinstance(dest_file, str): dest_file = open(dest_file, 'wb') - elif isinstance(dest_file, file): + elif isinstance(dest_file, io.IOBase): pass else: raise ValueError("destfile is of unknown type") diff --git a/adb/filesync_protocol.py b/adb/filesync_protocol.py index d0547f4..e1dbc1c 100644 --- a/adb/filesync_protocol.py +++ b/adb/filesync_protocol.py @@ -18,6 +18,7 @@ """ import collections +import io import os import stat import struct @@ -139,7 +140,7 @@ def Push(cls, connection, datafile, filename, cnxn.Send(b'SEND', fileinfo) if progress_callback: - total_bytes = os.fstat(datafile.fileno()).st_size if isinstance(datafile, file) else -1 + total_bytes = os.fstat(datafile.fileno()).st_size if isinstance(datafile, io.IOBase) else -1 progress = cls._HandleProgress(lambda current: progress_callback(filename, current, total_bytes)) next(progress) From 2ead78a44ca7fe4aab33afd34918451a87d48679 Mon Sep 17 00:00:00 2001 From: martin2250 Date: Sat, 8 Dec 2018 08:56:59 +0100 Subject: [PATCH 2/2] Restore Python2/3 compatibility of Push+Pull methods --- adb/adb_commands.py | 2 +- adb/filesync_protocol.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/adb/adb_commands.py b/adb/adb_commands.py index 0eca2e3..bdf315b 100644 --- a/adb/adb_commands.py +++ b/adb/adb_commands.py @@ -297,7 +297,7 @@ def Pull(self, device_filename, dest_file=None, timeout_ms=None, progress_callba dest_file = io.BytesIO() elif isinstance(dest_file, str): dest_file = open(dest_file, 'wb') - elif isinstance(dest_file, io.IOBase): + elif hasattr(dest_file, 'write'): pass else: raise ValueError("destfile is of unknown type") diff --git a/adb/filesync_protocol.py b/adb/filesync_protocol.py index e1dbc1c..3b36af3 100644 --- a/adb/filesync_protocol.py +++ b/adb/filesync_protocol.py @@ -18,7 +18,6 @@ """ import collections -import io import os import stat import struct @@ -140,7 +139,7 @@ def Push(cls, connection, datafile, filename, cnxn.Send(b'SEND', fileinfo) if progress_callback: - total_bytes = os.fstat(datafile.fileno()).st_size if isinstance(datafile, io.IOBase) else -1 + total_bytes = os.fstat(datafile.fileno()).st_size if hasattr(datafile, 'fileno') else -1 progress = cls._HandleProgress(lambda current: progress_callback(filename, current, total_bytes)) next(progress)