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