Projects
Wiki     Timeline     Roadmap     Browse Source     View Tickets     New Ticket     Search

Ticket #136: config.py.patch

File config.py.patch, 2.1 KB (added by callan@…, 3 years ago)

Patch to allow directory service implementations to declare their default configuration options.

  • config.py

     
    2020import copy 
    2121 
    2222from twisted.python import log 
     23from twisted.python.reflect import namedClass 
    2324 
    2425from twistedcaldav.py.plistlib import readPlist 
    2526 
     
    198199                newParams = items["DirectoryService"].get("params", {}) 
    199200                _mergeData(oldParams, newParams) 
    200201            else: 
     202                # Lookup default parameters and insert them in the module 
     203                # variable if they exist. This process also ensures that the 
     204                # specified directory service class can be imported and that 
     205                # we have default parameters for the subsequent logic that  
     206                # follows. 
     207                try: 
     208                    serviceClass = namedClass(dsType) 
     209                    if hasattr(serviceClass, "defaultParams"): 
     210                        serviceDefaultParams[dsType] = serviceClass.defaultParams 
     211                    elif dsType not in serviceDefaultParams: 
     212                        raise ConfigurationError( 
     213                            "Default service parameters must be specified in " \ 
     214                            "%s using the 'defaultParams' class variable or " \ 
     215                            "via the 'defaultServiceParams' module variable " \ 
     216                            "in twistedcaldav.config." % \ 
     217                            dsType) 
     218                except (ImportError, AttributeError): 
     219                    raise ConfigurationError("Unable to load directory service %s" % dsType) 
     220 
    201221                if dsType in serviceDefaultParams: 
    202222                    self._data["DirectoryService"]["params"] = copy.deepcopy(serviceDefaultParams[dsType]) 
    203223                else: 
    204224                    self._data["DirectoryService"]["params"] = {} 
    205225 
     226 
    206227        for param in items.get("DirectoryService", {}).get("params", {}): 
    207228            if param not in serviceDefaultParams[dsType]: 
    208229                raise ConfigurationError("Parameter %s is not supported by service %s" % (param, dsType))