Skip to content

Commit

Permalink
Cleaner fix for python 2/3 in adb_device.py (#738)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Kenadia authored Mar 16, 2018
1 parent 6dfbc73 commit 1781e31
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions openhtf/plugs/usb/adb_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
class, subclass, and protocol.
"""

try:
import cStringIO as io
except ImportError:
import io
import io
import logging
import os.path

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1781e31

Please sign in to comment.