source: src/mlx/common.py@ 999:e096a5638b87

python3
Last change on this file since 999:e096a5638b87 was 995:ad90726834d4, checked in by István Váradi <ivaradi@…>, 5 years ago

Using 'GObject' instead of 'gobject' (re #347)

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", "http://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.