Ignore:
Timestamp:
15/02/10 11:33:01 (11 years ago)
Author:
pjkersha
Message:

Working refactored Attribute Authority Client unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/utils/factory.py

    r6570 r6572  
    2121    @param moduleName: Name of module containing the class 
    2222    @type moduleName: str  
    23     @param className: Name of the class to import.  If none is given, the  
     23    @param objectName: Name of the class to import.  If none is given, the  
    2424    class name will be assumed to be the last component of modulePath 
    25     @type className: str 
     25    @type objectName: str 
    2626    @rtype: class object 
    2727    @return: imported class''' 
    28      
    29     if className is None: 
    30         _moduleName, className = moduleName.rsplit('.', 1) 
     28    if objectName is None: 
     29        if ':' in moduleName: 
     30            # Support PAste style import syntax with rhs of colon denoting  
     31            # module content to import 
     32            _moduleName, objectName = moduleName.rsplit(':', 1) 
     33            if '.' in objectName: 
     34                objectName = objectName.split('.') 
     35        else:  
     36            _moduleName, objectName = moduleName.rsplit('.', 1) 
     37            objectName = [objectName] 
    3138    else: 
    3239        _moduleName = moduleName 
     40        if isinstance(objectName, basestring): 
     41            objectName = [objectName] 
    3342     
    34     log.debug("Importing %r ..." % className)  
     43    log.debug("Importing %r ..." % objectName)  
    3544       
    3645    module = __import__(_moduleName, globals(), locals(), []) 
     
    4150    except AttributeError, e: 
    4251        raise AttributeError("Error importing %r: %s" % 
    43                              (className, traceback.format_exc())) 
     52                             (objectName, traceback.format_exc())) 
    4453 
    45     importedObject = getattr(module, className) 
     54    importedObject = module 
     55    for i in objectName: 
     56        importedObject = getattr(importedObject, i) 
    4657 
    4758    # Check class inherits from a base class 
    4859    if objectType and not issubclass(importedObject, objectType): 
    4960        raise TypeError("Specified class %r must be derived from %r; got %r" % 
    50                         (className, objectType, importedObject)) 
     61                        (objectName, objectType, importedObject)) 
    5162     
    52     log.info('Imported %r from module, %r', className, _moduleName) 
     63    log.info('Imported %r from module, %r', objectName, _moduleName) 
    5364    return importedObject 
    5465 
    5566 
    56 def callModuleObject(moduleName, className=None, moduleFilePath=None,  
     67def callModuleObject(moduleName, objectName=None, moduleFilePath=None,  
    5768                     objectType=None, objectArgs=(), objectProperties={}): 
    5869    ''' 
     
    6071    @param moduleName: Name of module containing the class 
    6172    @type moduleName: str  
    62     @param className: Name of the class to instantiate.  May be None in  
     73    @param objectName: Name of the class to instantiate.  May be None in  
    6374    which case, the class name is parsed from the moduleName last element 
    64     @type className: str 
     75    @type objectName: str 
    6576    @param moduleFilePath: Path to the module - if unset, assume module on  
    6677    system path already 
Note: See TracChangeset for help on using the changeset viewer.