Changeset 955:d98b211d32fa for src/mlx/common.py
- Timestamp:
- 05/12/19 07:18:47 (5 years ago)
- Branch:
- python3
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/common.py
r942 r955 31 31 32 32 from gi.repository import GObject as gobject 33 34 #------------------------------------------------------------------------------- 35 36 def fixUnpickledValue(value): 37 """Fix the given unpickled value. 38 39 It handles some basic data, like scalars, lists and tuples. If it 40 encounters byte arrays, they are decoded as 'utf-8' strings.""" 41 if isinstance(value, bytes): 42 return str(value, "utf-8") 43 elif isinstance(value, list): 44 return [fixUnpickledValue(v) for v in value] 45 elif isinstance(value, tuple): 46 return tuple([fixUnpickledValue(v) for v in value]) 47 else: 48 return value 49 50 #------------------------------------------------------------------------------- 51 52 def fixUnpickled(state): 53 """Fix the given unpickled state. 54 55 It checks keys and values, and if it encounters any byte arrays, they are 56 decoded with the encoding 'utf-8'. It returns a new dictionary. 57 """ 58 newDict = {} 59 for (key, value) in iter(state.items()): 60 newDict[fixUnpickledValue(key)] = fixUnpickledValue(value) 61 62 return newDict
Note:
See TracChangeset
for help on using the changeset viewer.