· 8 years ago · Jan 11, 2018, 05:24 PM
1try:
2 if (not options['gatewayUrl']) or (not options['clientId']) or (not options['secretKey']):
3 raise ConfigurationException('API connection data not set')
4except KeyError:
5 raise ConfigurationException('API connection data not set')
6
7chk = set(['gatewayUrl','clientId','secretKey'])
8chk.issubset(set(options)) and all(options.values())
9
10# значение Ð´Ð»Ñ ÐºÐ»ÑŽÑ‡Ð° "secretKey" не определено
11
12In [178]: options = {'gatewayUrl':'url', 'clientId':'id', 'secretKey':None}
13
14In [179]: chk.issubset(set(options)) and all(options.values())
15Out[179]: False
16
17# вÑе OK
18
19In [180]: options = {'gatewayUrl':'url', 'clientId':'id', 'secretKey':'secret'}
20
21In [181]: chk.issubset(set(options)) and all(options.values())
22Out[181]: True
23
24# отутÑвует ключ "secretKey"
25
26In [182]: options = {'gatewayUrl':'url', 'clientId':'id'}
27
28In [183]: chk.issubset(set(options)) and all(options.values())
29Out[183]: False
30
31keys = ['gatewayUrl', 'clientId', 'secretKey']
32
33options = {'gatewayUrl': '1', 'clientId':'2', 'secretKey':'3'}
34False in [bool(options.get(key)) for key in keys]
35>> False
36
37
38options = {'gatewayUrl': '1', 'clientId':'2', 'secretKey':''}
39False in [bool(options.get(key)) for key in keys]
40>> True
41
42options = {'gatewayUrl': '1', 'clientId':'2'}
43False in [bool(options.get(key)) for key in keys]
44>> True
45
46if False in [bool(options.get(key)) for key in keys]:
47 raise