1From 3ff78f1f00973393d1a7ee4e467a2bacf1c807f3 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andr=C3=A9=20Draszik?= <git@andred.net>
3Date: Wed, 5 Feb 2020 16:14:21 +0000
4Subject: [PATCH] smem: fix support for --source option (python3)
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Using --source doesn't work without this patch:
10Traceback (most recent call last):
11  File "./smem", line 727, in <module>
12    showpids()
13  File "./smem", line 299, in showpids
14    showtable(pt.keys(), fields, columns.split(), options.sort or 'pss')
15  File "./smem", line 519, in showtable
16    mt = totalmem()
17  File "./smem", line 118, in totalmem
18    _totalmem = memory()['memtotal']
19  File "./smem", line 193, in memory
20    m = f.match(l)
21TypeError: cannot use a string pattern on a bytes-like object
22
23python3's tarfile returns bytes, whereas all of the rest of
24the code assumes str.
25
26Fix the tarfile usage to convert to str before returning the
27results.
28
29Signed-off-by: André Draszik <git@andred.net>
30Upstream-Status: Inappropriate [upstream wants to support python2 & python3]
31---
32 smem | 4 ++--
33 1 file changed, 2 insertions(+), 2 deletions(-)
34
35diff --git a/smem b/smem
36index 46a3189..54d40dd 100755
37--- a/smem
38+++ b/smem
39@@ -90,9 +90,9 @@ class tardata(procdata):
40                 d,f = ti.name.split('/')
41                 yield d
42     def _read(self, f):
43-        return self.tar.extractfile(f).read()
44+        return self.tar.extractfile(f).read().decode()
45     def _readlines(self, f):
46-        return self.tar.extractfile(f).readlines()
47+        return [l.decode() for l in self.tar.extractfile(f).readlines()]
48     def piduser(self, p):
49         t = self.tar.getmember("%d" % p)
50         if t.uname:
51--
522.23.0.rc1
53
54