summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 07:43:29 -0700
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 07:43:29 -0700
commit8d946e075f5a2d760b083a7cfacd5d01bfb9f72d (patch)
tree8759456c6dbf0eb7348b6e515486c662625d4904
parente907b34555c0c194559f026218f1910e62e78417 (diff)
downloadpsutil-8d946e075f5a2d760b083a7cfacd5d01bfb9f72d.tar.gz
#650: stringify name and exe
-rw-r--r--docs/index.rst6
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/_pswindows.py16
-rw-r--r--test/_windows.py2
4 files changed, 21 insertions, 5 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 4a2a5b94..9848b068 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -681,12 +681,18 @@ Process class
The process name. The return value is cached after first call.
+ *Changed in 3.2.0:* (Windows, Python 2) in case of non ASCII name the
+ returned type is unicode instead of str.
+
.. method:: exe()
The process executable as an absolute path.
On some systems this may also be an empty string.
The return value is cached after first call.
+ *Changed in 3.2.0:* (Windows, Python 2) in case of non ASCII path the
+ returned type is unicode instead of str.
+
.. method:: cmdline()
The command line this process has been called with.
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 385b80a4..16688362 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -158,7 +158,7 @@ __all__ = [
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
-__version__ = "3.1.2"
+__version__ = "3.2.0"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
_TOTAL_PHYMEM = None
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 2d8babb1..ca48120f 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -234,6 +234,16 @@ def users():
return retlist
+def py2_stringify(s):
+ if PY3:
+ return s
+ else:
+ try:
+ return str(s)
+ except UnicodeEncodeError:
+ return s
+
+
pids = cext.pids
pid_exists = cext.pid_exists
net_io_counters = cext.net_io_counters
@@ -287,9 +297,9 @@ class Process(object):
try:
# Note: this will fail with AD for most PIDs owned
# by another user but it's faster.
- return os.path.basename(self.exe())
+ return py2_stringify(os.path.basename(self.exe()))
except AccessDenied:
- return cext.proc_name(self.pid)
+ return py2_stringify(cext.proc_name(self.pid))
@wrap_exceptions
def exe(self):
@@ -301,7 +311,7 @@ class Process(object):
# see https://github.com/giampaolo/psutil/issues/528
if self.pid in (0, 4):
raise AccessDenied(self.pid, self._name)
- return _convert_raw_path(cext.proc_exe(self.pid))
+ return py2_stringify(_convert_raw_path(cext.proc_exe(self.pid)))
@wrap_exceptions
def cmdline(self):
diff --git a/test/_windows.py b/test/_windows.py
index 93331789..5d6fd366 100644
--- a/test/_windows.py
+++ b/test/_windows.py
@@ -292,7 +292,7 @@ class WindowsSpecificTestCase(unittest.TestCase):
for p in psutil.process_iter():
try:
p.name()
- except psutil.NoSuchProcess():
+ except psutil.NoSuchProcess:
pass