diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-08-30 04:47:40 -0700 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-08-30 04:47:40 -0700 |
commit | c3bd8b90f66d1dec98c099cd651f3de3a0381b30 (patch) | |
tree | b8d025c4ad13cff618783aa9b7d228a3ffdebc91 | |
parent | 5176c50dc4b67de5d760636a70444ed21c807dc4 (diff) | |
download | psutil-655-windows-unicode.tar.gz |
str-encode NIC names655-windows-unicode
-rw-r--r-- | psutil/_pswindows.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 3e20d3be..2d92486f 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -113,6 +113,18 @@ def _convert_raw_path(s): return os.path.join(driveletter, s[len(rawdrive):]) +def py2_strencode(s, encoding=sys.getfilesystemencoding()): + if PY3 or isinstance(s, str): + return s + else: + try: + return s.encode(encoding) + except UnicodeEncodeError: + # Filesystem codec failed, return the plain unicode + # string (this should never happen). + return s + + # --- public functions @@ -216,6 +228,7 @@ def net_connections(kind, _pid=-1): def net_if_stats(): ret = cext.net_if_stats() for name, items in ret.items(): + name = py2_strencode(name) isup, duplex, speed, mtu = items if hasattr(_common, 'NicDuplex'): duplex = _common.NicDuplex(duplex) @@ -223,35 +236,36 @@ def net_if_stats(): return ret +def net_io_counters(): + ret = cext.net_io_counters() + return dict([(py2_strencode(k), v) for k, v in ret.items()]) + + +def net_if_addrs(): + ret = [] + for items in cext.net_if_addrs(): + items = list(items) + items[0] = py2_strencode(items[0]) + ret.append(items) + return ret + + def users(): """Return currently connected users as a list of namedtuples.""" retlist = [] rawlist = cext.users() for item in rawlist: user, hostname, tstamp = item + user = py2_strencode(user) nt = _common.suser(user, None, hostname, tstamp) retlist.append(nt) return retlist -def py2_strencode(s, encoding=sys.getfilesystemencoding()): - if PY3 or isinstance(s, str): - return s - else: - try: - return s.encode(encoding) - except UnicodeEncodeError: - # Filesystem codec failed, return the plain unicode - # string (this should never happen). - return s - - pids = cext.pids pid_exists = cext.pid_exists -net_io_counters = cext.net_io_counters disk_io_counters = cext.disk_io_counters ppid_map = cext.ppid_map # not meant to be public -net_if_addrs = cext.net_if_addrs def wrap_exceptions(fun): |