def callback(scanner, name, ob): # Evaluate conditions handler = ConfigurationHandler(scanner.context, testing=scanner.testing) condition = arguments.pop('condition', None) if condition and not handler.evaluateCondition(condition): return # Configure standalone directive name = '{0:s}.{1:s}'.format(ob.__module__, name) arguments[callable_] = name scanner.context.begin(directive, arguments, self_.__info__) scanner.context.end()
def callback(scanner, name, ob): # Evaluate conditions handler = ConfigurationHandler(scanner.context, testing=scanner.testing) condition = arguments.pop('condition', None) if condition and not handler.evaluateCondition(condition): return # Configure standalone directive scanner.context.begin(directive_, arguments, self_.__info__) # Do not end when used with 'with' statement if not self_.__is_complex__: scanner.context.end()
def callback(scanner, name, ob): # Evaluate conditions handler = ConfigurationHandler(scanner.context, testing=scanner.testing) condition = arguments.pop('condition', None) if condition and not handler.evaluateCondition(condition): return # Configure standalone directive if getattr(scanner.context, 'info', '') == '': scanner.context.info = self_.__info__ scanner.context.begin(directive_, arguments, self_.__info__) # Do not end when used with 'with' statement if not self_.__is_complex__: scanner.context.end()
def processcfgfile(file, context, testing=False): """Process a configuration file (cfg)""" import ConfigParser config = ConfigParser.RawConfigParser() config.readfp(file) sections = config._sections # Define namespaces namespaces = NAMESPACES.copy() if 'namespaces' in sections: namespaces.update(config.items('namespaces')) sections.pop('namespaces', None) from zope.configuration.xmlconfig import ConfigurationHandler handler = ConfigurationHandler(context, testing=testing) # Read directives in resolved order for section in sections: # Read arguments data = sections.get(section, {}) data.pop('__name__', None) # Resolve condition condition = data.pop('condition', None) if condition: if not handler.evaluateCondition(condition): continue # Resolve namespace and directive name = section.split(':')[:-1] if len(name) == 1: name = [namespaces[''], name[0]] else: name[0] = namespaces[name[0]] # Configure! context.begin(tuple(name), data) context.end()