Commit 9e373b8f authored by Luke Macken's avatar Luke Macken

Decode the subprocess output to get pyrasite.inspect working on py3.

Before this fix, the following exception gets thrown on Python 3.3:

TypeError: Type str doesn't support the buffer API
parent af1f8725
...@@ -13,10 +13,14 @@ ...@@ -13,10 +13,14 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with pyrasite. If not, see <http://www.gnu.org/licenses/>. # along with pyrasite. If not, see <http://www.gnu.org/licenses/>.
# #
# Copyright (C) 2011, 2012 Red Hat, Inc., Luke Macken <lmacken@redhat.com> # Copyright (C) 2011-2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import sys
import subprocess import subprocess
encoding = sys.getdefaultencoding()
def inspect(pid, address): def inspect(pid, address):
"Return the value of an object in a given process at the specified address" "Return the value of an object in a given process at the specified address"
cmd = ' '.join([ cmd = ' '.join([
...@@ -24,6 +28,6 @@ def inspect(pid, address): ...@@ -24,6 +28,6 @@ def inspect(pid, address):
'-eval-command="print (PyObject *)%s"' % address, '-eval-command="print (PyObject *)%s"' % address,
]) ])
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in p.communicate()[0].split('\n'): for line in p.communicate()[0].decode(encoding).split('\n'):
if line.startswith('$1 = '): if line.startswith('$1 = '):
return line[5:] return line[5:]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment