mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-25 08:33:22 +03:00
Use dict view objects to avoid issue #758.
This commit is contained in:
parent
3ea76e0e82
commit
d67fd87763
@ -21,6 +21,7 @@
|
||||
# pylint: skip-file
|
||||
"""Python 2/3 compatibility shims."""
|
||||
|
||||
import operator
|
||||
import sys
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
@ -38,6 +39,10 @@ if PY3:
|
||||
text_type = str
|
||||
binary_type = bytes
|
||||
|
||||
viewkeys = operator.methodcaller('keys')
|
||||
viewvalues = operator.methodcaller('values')
|
||||
viewitems = operator.methodcaller('items')
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
@ -73,6 +78,10 @@ else:
|
||||
text_type = unicode
|
||||
binary_type = str
|
||||
|
||||
viewkeys = operator.methodcaller('viewkeys')
|
||||
viewvalues = operator.methodcaller('viewvalues')
|
||||
viewitems = operator.methodcaller('viewitems')
|
||||
|
||||
def iteritems(d):
|
||||
return d.iteritems()
|
||||
|
||||
|
@ -27,7 +27,7 @@ import json
|
||||
from datetime import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
from glances.compat import iterkeys, itervalues, map
|
||||
from glances.compat import iterkeys, itervalues, map, viewkeys
|
||||
from glances.actions import GlancesActions
|
||||
from glances.logger import logger
|
||||
from glances.logs import glances_logs
|
||||
@ -289,7 +289,7 @@ class GlancesPlugin(object):
|
||||
# Stats are stored in a list of dict (ex: NETWORK, FS...)
|
||||
for i in self.get_raw():
|
||||
ret[i[self.get_key()]] = {}
|
||||
for key, _ in i.items():
|
||||
for key in viewkeys(i):
|
||||
value = {'decoration': 'DEFAULT',
|
||||
'optional': False,
|
||||
'additional': False,
|
||||
@ -297,7 +297,7 @@ class GlancesPlugin(object):
|
||||
ret[i[self.get_key()]][key] = value
|
||||
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
|
||||
# Stats are stored in a dict (ex: CPU, LOAD...)
|
||||
for key, _ in self.get_raw().items():
|
||||
for key in viewkeys(self.get_raw()):
|
||||
value = {'decoration': 'DEFAULT',
|
||||
'optional': False,
|
||||
'additional': False,
|
||||
|
Loading…
Reference in New Issue
Block a user