summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-04 06:29:36 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-04 06:29:36 +0200
commitec42f77f5ab929e6557b44810c92313e9d0d89d6 (patch)
tree13af30b314f129347a57b0f0af76932d6caef705
parent8393e9c78068d0cd168251927d7952019af575db (diff)
downloadpsutil-ec42f77f5ab929e6557b44810c92313e9d0d89d6.tar.gz
fix #1051: make disk_usage() on python 3 able to deal with bytes
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_pswindows.py10
-rwxr-xr-xpsutil/tests/test_system.py8
3 files changed, 7 insertions, 12 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 30bdecc3..52c48c73 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -15,6 +15,7 @@
Process.as_dict(): "attrs" and "ad_value". With this you can iterate over all
processes in one shot without needing to catch NoSuchProcess and do list/dict
comprehensions.
+- 1051_: disk_usage() on Python 3 is now able to accept bytes.
**Bug fixes**
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index e284bb69..c0d6d001 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -239,13 +239,9 @@ disk_io_counters = cext.disk_io_counters
def disk_usage(path):
"""Return disk usage associated with path."""
- try:
- total, free = cext.disk_usage(path)
- except WindowsError:
- if not os.path.exists(path):
- msg = "No such file or directory: '%s'" % path
- raise OSError(errno.ENOENT, msg)
- raise
+ if PY3 and isinstance(path, bytes):
+ path = path.decode(FS_ENCODING)
+ total, free = cext.disk_usage(path)
used = total - free
percent = usage_percent(used, total, _round=1)
return _common.sdiskusage(total, used, free, percent)
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 19f997a8..bb485296 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -463,11 +463,9 @@ class TestSystemAPIs(unittest.TestCase):
if ASCII_FS:
with self.assertRaises(UnicodeEncodeError):
psutil.disk_usage(TESTFN_UNICODE)
- else:
- safe_rmpath(TESTFN_UNICODE)
- self.addCleanup(safe_rmpath, TESTFN_UNICODE)
- os.mkdir(TESTFN_UNICODE)
- psutil.disk_usage(TESTFN_UNICODE)
+
+ def test_disk_usage_bytes(self):
+ psutil.disk_usage(b'.')
def test_disk_partitions(self):
# all = False