def access_log(directive, param, args): """Map the CustomLog argument depending on the parameter. The CustomLog Apache directive has a single argument, but it maps to several apache::vhost parameters. Depending on what the parameter is, return the appropriate value, or None if the argument can't be mapped. """ arg = str(args[0]) syslog = arg.startswith('syslog') pipe = arg.startswith('|') if param == 'access_log': return True elif param == 'access_log_syslog' and syslog: return True elif param == 'access_log_pipe' and pipe: return arg elif param == 'access_log_file' and not syslog and not pipe: if os.path.isabs(arg): return os.path.basename(arg) else: return arg elif param == 'logroot' and not syslog and not pipe: if os.path.isabs(arg): return os.path.dirname(arg) else: return None elif param == 'access_log_format': return qstr(args[1]) elif param == 'access_log_env_var' and len(args) > 2: return str(args[2]) else: return None
def error_doc(directive, param, args, context): """Accumulate ErrorDocument directives into a hash.""" value = {'error_code': str(args[0]), 'document': qstr(args[1])} if context not in error_doc.values: error_doc.values[context] = [] error_doc.values[context].append(value) if len(error_doc.values[context]) > 1: return None else: return error_doc.values[context]
def _to_hash(directive, param, args, context, quote=False): """Accumulate the args into a dictionary. The first argument should be they key, and the second the value. If quote is True, quote the value if necessary. """ key = context + ';' + param if quote: hv = qstr(args[1]) else: hv = str(args[1]) value = {str(args[0]): hv} if key in _to_hash.values: _to_hash.values[key].update(value) return None else: _to_hash.values[key] = value return _to_hash.values[key]
def qarray(directive, param, args): """Return a list of the parameters, quoting if necessary.""" return [qstr(a) for a in args]
def qjoin(directive, param, args): """Join the parameters together, quoting if necessary.""" return ' '.join([qstr(a) for a in args])
def qstring(directive, param, args): """Return a single string parameter, quoted, if necessary.""" return qstr(args[0])