[575] | 1 | import os
|
---|
| 2 |
|
---|
| 3 | #-----------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | ## @package mlx.common
|
---|
| 6 | #
|
---|
| 7 | # Common definitions to be used by both the GUI and possible other parts
|
---|
| 8 | #
|
---|
[740] | 9 | #---------------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | MAVA_BASE_URL = os.environ.get("MAVA_BASE_URL", "http://virtualairlines.hu")
|
---|
| 12 |
|
---|
[575] | 13 | #-------------------------------------------------------------------------------
|
---|
| 14 |
|
---|
[995] | 15 | from gi.repository import GObject
|
---|
[955] | 16 |
|
---|
| 17 | #-------------------------------------------------------------------------------
|
---|
| 18 |
|
---|
| 19 | def 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 |
|
---|
| 35 | def 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
|
---|