source: src/mlx/common.py@ 1151:2ef1ab0b28cb

python3
Last change on this file since 1151:2ef1ab0b28cb was 1047:23b36442cf1c, checked in by István Váradi <ivaradi@…>, 3 years ago

The original MAVA website URL is used (re #357)

File size: 1.5 KB
Line 
1import os
2
3#-----------------------------------------------------------------------------
4
5## @package mlx.common
6#
7# Common definitions to be used by both the GUI and possible other parts
8#
9#---------------------------------------------------------------------------------------
10
11MAVA_BASE_URL = os.environ.get("MAVA_BASE_URL", "https://virtualairlines.hu")
12
13#-------------------------------------------------------------------------------
14
15from gi.repository import GObject
16
17#-------------------------------------------------------------------------------
18
19def fixUnpickledValue(value):
20 """Fix the given unpickled value.
21
22 It handles some basic data, like scalars, lists and tuples. If it
23 encounters byte arrays, they are decoded as 'utf-8' strings."""
24 if isinstance(value, bytes):
25 return str(value, "utf-8")
26 elif isinstance(value, list):
27 return [fixUnpickledValue(v) for v in value]
28 elif isinstance(value, tuple):
29 return tuple([fixUnpickledValue(v) for v in value])
30 else:
31 return value
32
33#-------------------------------------------------------------------------------
34
35def fixUnpickled(state):
36 """Fix the given unpickled state.
37
38 It checks keys and values, and if it encounters any byte arrays, they are
39 decoded with the encoding 'utf-8'. It returns a new dictionary.
40 """
41 newDict = {}
42 for (key, value) in iter(state.items()):
43 newDict[fixUnpickledValue(key)] = fixUnpickledValue(value)
44
45 return newDict
Note: See TracBrowser for help on using the repository browser.