Skip to content

Commit 8bb6356

Browse files
authored
Fix regressions occuring during PY2 deprecation. (#1011)
* Fix regressions occuring during PY2 deprecation. * Added parenthesis for readability.
1 parent 3e5a7f2 commit 8bb6356

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

openhtf/output/callbacks/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def __init__(self, filename: Text):
4343
self.temp = tempfile.NamedTemporaryFile(delete=False)
4444

4545
def write(self, write_data: Union[Text, bytes]) -> int:
46-
return self.temp.write(six.ensure_binary(write_data))
46+
if isinstance(write_data, str):
47+
write_data = write_data.encode()
48+
return self.temp.write(write_data)
4749

4850
def close(self) -> None:
4951
self.temp.close()
@@ -133,7 +135,7 @@ def __call__(self, test_rec: test_record.TestRecord) -> None:
133135
outfile.write(serialized_record.encode())
134136
elif isinstance(serialized_record, Iterable):
135137
for chunk in serialized_record:
136-
outfile.write(chunk.encode())
138+
outfile.write(chunk.encode() if isinstance(chunk, str) else chunk)
137139
else:
138140
raise TypeError('Expected string or iterable but got {}.'.format(
139141
type(serialized_record)))

openhtf/output/callbacks/mfg_inspector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def __init__(self,
148148
if user and keydata:
149149
self.credentials = oauth2client.client.SignedJwtAssertionCredentials(
150150
service_account_name=self.user,
151-
private_key=self.keydata.encode(),
151+
private_key=(self.keydata.encode()
152+
if isinstance(self.keydata, str) else self.keydata),
152153
scope=self.SCOPE_CODE_URI,
153154
user_agent='OpenHTF Guzzle Upload Client',
154155
token_uri=self.token_uri)

openhtf/util/threads.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Thread library defining a few helpers."""
1515

16+
import _thread
1617
import contextlib
1718
import cProfile
1819
import ctypes
@@ -22,11 +23,6 @@
2223
import sys
2324
import threading
2425

25-
try:
26-
import _thread # pylint: disable=g-import-not-at-top
27-
except ImportError:
28-
import _dummy_thread as _thread # pylint: disable=g-import-not-at-top
29-
3026
_LOG = logging.getLogger(__name__)
3127

3228

0 commit comments

Comments
 (0)