def parseline(self, line, lineno): __pychecker__ = 'no-argsused' n = line.split() # Everything we have is of the form 'directive argument', # so we can be really simple: if len(n) != 2: raise BadInput, "badly formatted line" # Every directive except 'listen' can only be given once, # so we can do this checking very easily. if n[0] != "listen" and self.cf.has_key(n[0]): raise BadInput, "can only give one %s directive" % \ (n[0],) # These three do no contents-checking: they just store it. if n[0] in ('rulefile', 'actionfile', 'user', 'aftermaxthreads'): self.cf[n[0]] = n[1] # I really need a better name for this. elif n[0] == 'dropipafter': self.cf[n[0]] = util.getsecs_or_raise(n[1], BadInput) elif n[0] == 'expireevery': self.cf[n[0]] = util.getsecs_or_raise(n[1], BadInput) elif n[0] == 'maxthreads': self.cf[n[0]] = util.int_or_raise(n[1], BadInput) elif n[0] == 'listen': # Listen stores host/port pairs in a list, since # we can legally accept multiple listen directives. # We insist that the port is always specified, but # the IP address can be wildcarded. r = util.gethostport(n[1]) if not r: raise BadInput, "bad argument to listen" if r[1] == '': raise BadInput, "listen requires a port" self.cf['listen'].append(r) elif n[0] == 'onfileerror': if n[1] not in ('drop', 'use-old'): raise BadInput, "unknown option for onfileerror" self.cf[n[0]] = n[1] elif n[0] == "substitutions": if n[1] not in ("off", "on"): raise BadInput, "substitutions must be off or on" self.cf[n[0]] = n[1] else: raise BadInput, "unknown config file directive "+n[0] return None
def getvalue(keyw, rest): def _badarg(): raise BadAction, "wrong number of arguments for directive "+keyw # for some reason, pychecker fails to understand that we always # return a value. Probably the raises confuse it. __pychecker__ = "no-implicitreturn" if not actargs.has_key(keyw): raise BadAction, "unknown directive "+keyw acnt = actargs[keyw] rest = rest.strip() # nullStr will accept null or a string; our argument in the null # case is a null string, so we're done. if acnt == nullStr: return rest elif acnt == noArg and rest: _badarg() elif acnt == noArg: return 1 # everything past here requires arguments, so if they don't have # any we can bail now. elif not rest: _badarg() elif acnt == oneInt: # this will automatically fail if 'rest' has multiple # words in it. return util.int_or_raise(rest, BadAction) elif acnt == aStr: return rest elif acnt == aEnv: # setenv requires an environment variable name and its value. # subst is similar enough to use the same code. n = rest.split(None, 1) if len(n) != 2: _badarg() return n elif acnt == anArg: n = rest.split() if len(n) != 1: _badarg() return rest # If we have gotten here, something is wrong; either an unhandled # argument type or an argument type handler that failed to get out # of the function. raise KeyError, "internal error: unhandled case for getvalue for "+keyw
def __init__(self, name, val): __pychecker__ = "no-argsused" self.port = util.int_or_raise(val, BadArg) if not (0 <= self.port <= 65536): raise BadArg, "port number outside of OK range"