Package ndg :: Package saml
[hide private]

Source Code for Package ndg.saml

 1  """Implementation of SAML 2.0 for NDG Security 
 2   
 3  NERC DataGrid Project 
 4   
 5  This implementation is adapted from the Java OpenSAML implementation.  The  
 6  copyright and licence information are included here: 
 7   
 8  Copyright [2005] [University Corporation for Advanced Internet Development, Inc.] 
 9   
10  Licensed under the Apache License, Version 2.0 (the "License"); 
11  you may not use this file except in compliance with the License. 
12  You may obtain a copy of the License at 
13   
14  http://www.apache.org/licenses/LICENSE-2.0 
15   
16  Unless required by applicable law or agreed to in writing, software 
17  distributed under the License is distributed on an "AS IS" BASIS, 
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19  See the License for the specific language governing permissions and 
20  limitations under the License. 
21  """ 
22  __author__ = "P J Kershaw" 
23  __date__ = "22/07/08" 
24  __copyright__ = "(C) 2009 Science and Technology Facilities Council" 
25  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
26  __license__ = "http://www.apache.org/licenses/LICENSE-2.0" 
27  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
28  __revision__ = "$Id: __init__.py 8009 2012-01-30 16:19:43Z rwilkinson $" 
29   
30 -class Config(object):
31 """Configuration options 32 @type use_lxml: bool 33 @cvar use_lxml: Controls whether lxml.etree should be imported instead of 34 etree. lxml is required for XPath expressions with conditions. 35 """ 36 use_lxml = None
37
38 -def importElementTreeAndCElementTree():
39 """Imports ElementTree and cElementTree, or the lxml ElementTree API, 40 depending on the Config.use_lxml value and whether the lxml package is 41 found. 42 @rtype: tuple (module, module) 43 @return: the ElementTree and cElementTree modules that have been imported - 44 None is returned instead of cElementTree if lxml is used. 45 """ 46 cElementTree = None 47 if Config.use_lxml is not None: 48 if Config.use_lxml: 49 from lxml import etree as ElementTree 50 else: 51 try: # python 2.5 52 # Force absolute import to prevent clash with 53 # ndg.saml.xml.etree. 54 p = __import__('xml.etree', globals(), locals(), 55 ['cElementTree', 'ElementTree'], 0) 56 cElementTree = p.cElementTree 57 ElementTree = p.ElementTree 58 except ImportError: 59 # if you've installed it yourself it comes this way 60 import cElementTree, ElementTree 61 else: 62 Config.use_lxml = False 63 try: 64 from lxml import etree as ElementTree 65 Config.use_lxml = True 66 except ImportError: 67 try: # python 2.5 68 p = __import__('xml.etree', globals(), locals(), 69 ['cElementTree', 'ElementTree'], 0) 70 cElementTree = p.cElementTree 71 ElementTree = p.ElementTree 72 except ImportError: 73 # if you've installed it yourself it comes this way 74 import cElementTree, ElementTree 75 return (ElementTree, cElementTree)
76
77 -def importElementTree():
78 """Imports ElementTree or the lxml ElementTree API depending on the 79 Config.use_lxml value and whether the lxml package is found. 80 @rtype: module 81 @return: the element tree module that has been imported 82 """ 83 return importElementTreeAndCElementTree()[0]
84