diff options
| author | Emmanuel Raviart <eraviart@entrouvert.com> | 2004-08-20 14:47:40 +0000 |
|---|---|---|
| committer | Emmanuel Raviart <eraviart@entrouvert.com> | 2004-08-20 14:47:40 +0000 |
| commit | 460a7adda9df6eaf37ae978068d495f1deae7093 (patch) | |
| tree | 7783b75b4a87cbe1b31154c9ec0d3585633261ac /python | |
| parent | 956fc02557ddaf5337681e87a8cb3c0f6276e21a (diff) | |
| download | lasso-460a7adda9df6eaf37ae978068d495f1deae7093.tar.gz lasso-460a7adda9df6eaf37ae978068d495f1deae7093.tar.xz lasso-460a7adda9df6eaf37ae978068d495f1deae7093.zip | |
In Python high-level binding, constants are now defined using 2 forms: as a
global variable and as a dict item. For example:
libNameIDPolicyTypeFederated and libNameIDPolicyTypes['federated'].
Diffstat (limited to 'python')
| -rw-r--r-- | python/lasso.py | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/python/lasso.py b/python/lasso.py index 1d26686a..96756b8b 100644 --- a/python/lasso.py +++ b/python/lasso.py @@ -36,21 +36,35 @@ import lassomod ################################################################################ -# Copy constants from lassomod as is, except that the 'lasso' prefix is removed -# and the first letter is lowered. -_globals = globals() -for constantName, constantValue in lassomod.__dict__.iteritems(): - if constantName.startswith('lassoHttpMethod') \ - or constantName.startswith('lassoLibConsent') \ - or constantName.startswith('lassoLibNameIDPolicyType') \ - or constantName.startswith('lassoLibProtocolProfile') \ - or constantName.startswith('lassoLoginProtocolProfile') \ - or constantName.startswith('lassoMessageType') \ - or constantName.startswith('lassoProviderType') \ - or constantName.startswith('lassoRequestType') \ - or constantName.startswith('lassoSamlAuthenticationMethod') \ - or constantName.startswith('lassoSignatureMethod'): - _globals[constantName[5].lower() + constantName[6:]] = constantValue +def _initConstants(): + """Copy constants from module lassomod. + + They are copied in two forms : + + - as a global variable, with the 'lasso' prefix removed and the first letter in lower case, + + - as an item in a global dictionnary of all constants having the same prefix. + """ + + constantPrefixes = ( + 'lassoHttpMethod', 'lassoLibConsent', 'lassoLibNameIDPolicyType', + 'lassoLibProtocolProfile', 'lassoLoginProtocolProfile', 'lassoMessageType', + 'lassoProviderType', 'lassoRequestType', 'lassoSamlAuthenticationMethod', + 'lassoSignatureMethod') + globals_ = globals() + for constantName, constantValue in lassomod.__dict__.iteritems(): + for contantPrefix in constantPrefixes: + if constantName.startswith(contantPrefix): + globals_[constantName[5].lower() + constantName[6:]] = constantValue + constantPlural = contantPrefix[5].lower() + contantPrefix[6:] + 's' + constantCore = constantName[len(contantPrefix)].lower() \ + + constantName[len(contantPrefix) + 1:] + if constantPlural in globals_: + globals_[constantPlural][constantCore] = constantValue + else: + globals_[constantPlural] = {constantCore: constantValue} + +_initConstants() ################################################################################ @@ -683,8 +697,11 @@ if __name__ == '__main__': import os init() + + # Lasso constants have two forms. + assert libNameIDPolicyTypeFederated == libNameIDPolicyTypes['federated'] + dataDirectoryPath = '../tests/data' - server = Server( os.path.join(dataDirectoryPath, 'sp1-la/metadata.xml'), os.path.join(dataDirectoryPath, 'sp1-la/public-key.pem'), |
