Changeset 955:d98b211d32fa for src
- Timestamp:
- 05/12/19 07:18:47 (6 years ago)
- Branch:
- python3
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 3 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 -
src/mlx/pirep.py
r919 r955 2 2 from .util import utf2unicode 3 3 from .flight import Flight 4 from .common import fixUnpickled 4 5 5 6 from . import const … … 114 115 try: 115 116 with open(path, "rb") as f: 116 pirep = pickle.load(f )117 pirep = pickle.load(f, fix_imports = True, encoding = "bytes") 117 118 if "numCrew" not in dir(pirep): 118 119 pirep.numCrew = pirep.bookedFlight.numCrew … … 412 413 413 414 return ([], attrs) 415 416 def __setstate__(self, state): 417 """Set the state from the given unpickled dictionary.""" 418 self.__dict__.update(fixUnpickled(state)) -
src/mlx/rpc.py
r928 r955 2 2 from . import rpccommon 3 3 4 from .common import MAVA_BASE_URL 4 from .common import MAVA_BASE_URL, fixUnpickled 5 5 6 6 import jsonrpclib … … 322 322 print("foglalas_id=%s" % ("0" if self.id is None else self.id,), file=f) 323 323 324 def __setstate__(self, state): 325 """Set the state from the given unpickled dictionary.""" 326 self.__dict__.update(fixUnpickled(state)) 327 324 328 #--------------------------------------------------------------------------------------- 325 329
Note:
See TracChangeset
for help on using the changeset viewer.