From 1781e317a1ca1f805b962dadfa606de986541df3 Mon Sep 17 00:00:00 2001 From: Kenneth Schiller Date: Sat, 17 Mar 2018 07:01:47 +0900 Subject: [PATCH] Cleaner fix for python 2/3 in adb_device.py (#738) * Cleaner fix for python 2/3 in adb_device.py Cleaner fix for python 2/3 compatibility in adb_device.py * Update adb_device.py --- openhtf/plugs/usb/adb_device.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/openhtf/plugs/usb/adb_device.py b/openhtf/plugs/usb/adb_device.py index 9a67641ca..511ff7d64 100644 --- a/openhtf/plugs/usb/adb_device.py +++ b/openhtf/plugs/usb/adb_device.py @@ -30,10 +30,7 @@ class, subclass, and protocol. """ -try: - import cStringIO as io -except ImportError: - import io +import io import logging import os.path @@ -164,15 +161,14 @@ def pull(self, device_filename, dest_file=None, timeout_ms=None): Returns: The file data if dest_file is not set, None otherwise. """ + should_return_data = dest_file is None if isinstance(dest_file, str): dest_file = open(dest_file, 'w') - elif not dest_file: + elif dest_file is None: dest_file = io.StringIO() self.filesync_service.recv(device_filename, dest_file, timeouts.PolledTimeout.from_millis(timeout_ms)) - # An empty call to cStringIO.StringIO returns an instance of - # cStringIO.OutputType. - if isinstance(dest_file, io.OutputType): + if should_return_data: return dest_file.getvalue() def list(self, device_path, timeout_ms=None):