summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-03 23:27:28 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-03 23:27:28 +0200
commit164861df38ac1f597c4139ee20bb08144fd9591e (patch)
treeff88c0a6917948a7c9b246ebf100626b8ddf8fb1
parent4fe26b06dda7357a1928a5e6e7b8b4ae80dae427 (diff)
downloadpsutil-164861df38ac1f597c4139ee20bb08144fd9591e.tar.gz
1040: on python 2 convert all service strings from unicode to bytes
-rw-r--r--psutil/_pswindows.py14
-rwxr-xr-xpsutil/tests/test_windows.py15
2 files changed, 14 insertions, 15 deletions
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 677e3426..cb9cd8be 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -427,9 +427,9 @@ def users():
def win_service_iter():
- """Return a list of WindowsService instances."""
+ """Yields a list of WindowsService instances."""
for name, display_name in cext.winservice_enumerate():
- yield WindowsService(name, display_name)
+ yield WindowsService(py2_strencode(name), py2_strencode(display_name))
def win_service_get(name):
@@ -470,10 +470,10 @@ class WindowsService(object):
cext.winservice_query_config(self._name)
# XXX - update _self.display_name?
return dict(
- display_name=display_name,
- binpath=binpath,
- username=username,
- start_type=start_type)
+ display_name=py2_strencode(display_name),
+ binpath=py2_strencode(binpath),
+ username=py2_strencode(username),
+ start_type=py2_strencode(start_type))
def _query_status(self):
with self._wrap_exceptions():
@@ -550,7 +550,7 @@ class WindowsService(object):
def description(self):
"""Service long description."""
- return cext.winservice_query_descr(self.name())
+ return py2_strencode(cext.winservice_query_descr(self.name()))
# utils
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index 2a883132..7acec9e8 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -28,7 +28,6 @@ except ImportError:
import psutil
from psutil import WINDOWS
-from psutil._compat import basestring
from psutil._compat import callable
from psutil.tests import APPVEYOR
from psutil.tests import get_test_subprocess
@@ -754,19 +753,19 @@ class TestServices(unittest.TestCase):
])
for serv in psutil.win_service_iter():
data = serv.as_dict()
- self.assertIsInstance(data['name'], basestring)
+ self.assertIsInstance(data['name'], str)
self.assertNotEqual(data['name'].strip(), "")
- self.assertIsInstance(data['display_name'], basestring)
- self.assertIsInstance(data['username'], basestring)
+ self.assertIsInstance(data['display_name'], str)
+ self.assertIsInstance(data['username'], str)
self.assertIn(data['status'], valid_statuses)
if data['pid'] is not None:
psutil.Process(data['pid'])
- self.assertIsInstance(data['binpath'], basestring)
- self.assertIsInstance(data['username'], basestring)
- self.assertIsInstance(data['start_type'], basestring)
+ self.assertIsInstance(data['binpath'], str)
+ self.assertIsInstance(data['username'], str)
+ self.assertIsInstance(data['start_type'], str)
self.assertIn(data['start_type'], valid_start_types)
self.assertIn(data['status'], valid_statuses)
- self.assertIsInstance(data['description'], basestring)
+ self.assertIsInstance(data['description'], str)
pid = serv.pid()
if pid is not None:
p = psutil.Process(pid)