def _GetValueAndType(self, key):
"""Fetch value from memcache and detect its type.
Args:
key: String
Returns:
(value, type), value is a Python object or None if the key was not set in
the cache, type is a string describing the type of the value.
"""
try:
value = memcache.get(key)
except (pickle.UnpicklingError, AttributeError, EOFError, ImportError,
IndexError), e:
msg = 'Failed to retrieve value from cache: %s' % e
return msg, 'error'
if value is None:
return None, self.DEFAULT_TYPESTR_FOR_NEW
for typeobj, _, typestr in self.TYPES:
if isinstance(value, typeobj):
break
else:
typestr = 'pickled'
value = pprint.pformat(value, indent=2)
return value, typestr
评论列表
文章目录