source: src/mlx/common.py@ 1191:0db341c8c3b3

python3 tip
Last change on this file since 1191:0db341c8c3b3 was 1191:0db341c8c3b3, checked in by István Váradi <ivaradi@…>, 4 days ago

context is used instead of cafile in urlopen()

File size: 1.6 KB
Line 
1import os
2import ssl
3import 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
13MAVA_BASE_URL = os.environ.get("MAVA_BASE_URL", "https://virtualairlines.hu")
14
15#-------------------------------------------------------------------------------
16
17from gi.repository import GObject
18
19#-------------------------------------------------------------------------------
20
21def 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
37def 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
51sslContext = ssl.create_default_context(cafile = certifi.where())
Note: See TracBrowser for help on using the repository browser.