Skip to content

Commit

Permalink
Additional Python2/3 compatibility fixes. (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
arsharma1 authored Mar 20, 2018
1 parent 1781e31 commit 489de05
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion openhtf/core/station_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def wait_for_update(self, timeout_s=1):
except xmlrpc.client.Fault as fault:
# TODO(madsci): This is a super kludge, eventually implement the
# ReraisingMixin for ServerProxy, but that's hard, so do this for now.
if 'openhtf.io.station_api.UpdateTimeout' in fault.faultString:
if 'openhtf.core.station_api.UpdateTimeout' in fault.faultString:
return self.cached_state
raise

Expand Down
4 changes: 2 additions & 2 deletions openhtf/plugs/usb/adb_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
class, subclass, and protocol.
"""

import io
import logging
import os.path

Expand All @@ -47,6 +46,7 @@
from openhtf.plugs.usb import usb_exceptions

from openhtf.util import timeouts
import six

# USB interface class, subclass, and protocol for matching against.
CLASS = 0xFF
Expand Down Expand Up @@ -165,7 +165,7 @@ def pull(self, device_filename, dest_file=None, timeout_ms=None):
if isinstance(dest_file, str):
dest_file = open(dest_file, 'w')
elif dest_file is None:
dest_file = io.StringIO()
dest_file = six.StringIO()
self.filesync_service.recv(device_filename, dest_file,
timeouts.PolledTimeout.from_millis(timeout_ms))
if should_return_data:
Expand Down
7 changes: 3 additions & 4 deletions openhtf/plugs/usb/fastboot_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import binascii
import collections
import io
import logging
import os
import struct
Expand Down Expand Up @@ -71,7 +70,7 @@ def send_command(self, command, arg=None):
"""
if arg is not None:
command = '%s:%s' % (command, arg)
self._write(io.StringIO(command), len(command))
self._write(six.StringIO(command), len(command))

def handle_simple_responses(
self, timeout_ms=None, info_cb=DEFAULT_MESSAGE_CALLBACK):
Expand Down Expand Up @@ -260,14 +259,14 @@ def download(self, source_file, source_len=0,
Returns:
Response to a download request, normally nothing.
"""
if isinstance(source_file, str):
if isinstance(source_file, six.string_types):
source_len = os.stat(source_file).st_size
source_file = open(source_file)

if source_len == 0:
# Fall back to storing it all in memory :(
data = source_file.read()
source_file = io.StringIO(data)
source_file = six.StringIO(data)
source_len = len(data)

self._protocol.send_command('download', '%08x' % source_len)
Expand Down
3 changes: 2 additions & 1 deletion openhtf/plugs/usb/filesync_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import sys
import time

from future.utils import raise_with_traceback
from openhtf.plugs.usb import adb_message
from openhtf.plugs.usb import usb_exceptions

Expand Down Expand Up @@ -223,7 +224,7 @@ def _check_for_fail_message(self, transport, exc_info, timeout): # pylint: disa
if sys.exc_info()[0] is usb_exceptions.AdbRemoteError:
raise
# Otherwise reraise the original exception.
raise exc_info[0](exc_info[1]).raise_with_traceback(exc_info[2])
raise_with_traceback(exc_info[0](exc_info[1]), traceback=exc_info[2])

# pylint: disable=too-many-arguments
def send(self, src_file, filename, st_mode=DEFAULT_PUSH_MODE, mtime=None,
Expand Down
1 change: 0 additions & 1 deletion openhtf/plugs/usb/shell_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
# output.getvalue() now contains the output of the arecord command.
"""

import io
import threading
import time

Expand Down

0 comments on commit 489de05

Please sign in to comment.