mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Use StringIO for PY3
This commit is contained in:
@ -17,13 +17,13 @@ from __future__ import absolute_import
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO, StringIO
|
||||||
|
|
||||||
import jsonrpc # pylint: disable=import-error
|
import jsonrpc # pylint: disable=import-error
|
||||||
from twisted.internet import threads # pylint: disable=import-error
|
from twisted.internet import threads # pylint: disable=import-error
|
||||||
|
|
||||||
from platformio import __main__, __version__, util
|
from platformio import __main__, __version__, util
|
||||||
from platformio.compat import string_types
|
from platformio.compat import PY2, is_bytes, string_types
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from thread import get_ident as thread_get_ident
|
from thread import get_ident as thread_get_ident
|
||||||
@ -45,11 +45,9 @@ class MultiThreadingStdStream(object):
|
|||||||
def write(self, value):
|
def write(self, value):
|
||||||
thread_id = thread_get_ident()
|
thread_id = thread_get_ident()
|
||||||
if thread_id not in self._buffers:
|
if thread_id not in self._buffers:
|
||||||
self._buffers[thread_id] = BytesIO()
|
self._buffers[thread_id] = BytesIO() if PY2 else StringIO()
|
||||||
try:
|
return self._buffers[thread_id].write(
|
||||||
return self._buffers[thread_id].write(value)
|
value.decode() if is_bytes(value) else value)
|
||||||
except TypeError:
|
|
||||||
return self._buffers[thread_id].write(value.encode())
|
|
||||||
|
|
||||||
def get_value_and_close(self):
|
def get_value_and_close(self):
|
||||||
thread_id = thread_get_ident()
|
thread_id = thread_get_ident()
|
||||||
|
Reference in New Issue
Block a user