minor code cleanup
This commit is contained in:
parent
c7d574ada6
commit
2370ffbe2d
31
src/nip.py
31
src/nip.py
@ -22,6 +22,7 @@ import ConfigParser
|
||||
|
||||
DEBUG = 0
|
||||
|
||||
|
||||
def log(msg):
|
||||
sys.stderr.write('backend (%s): %s\n' % (os.getpid(), msg))
|
||||
|
||||
@ -31,20 +32,25 @@ def write(*l):
|
||||
c = 0
|
||||
for a in l:
|
||||
c += 1
|
||||
if DEBUG: log('writing: %s' % a)
|
||||
if DEBUG:
|
||||
log('writing: %s' % a)
|
||||
sys.stdout.write(a)
|
||||
if c < args:
|
||||
if DEBUG: log('writetab')
|
||||
if DEBUG:
|
||||
log('writetab')
|
||||
sys.stdout.write('\t')
|
||||
if DEBUG: log('writenewline')
|
||||
if DEBUG:
|
||||
log('writenewline')
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def get_next():
|
||||
if DEBUG: log('reading now')
|
||||
if DEBUG:
|
||||
log('reading now')
|
||||
l = sys.stdin.readline()
|
||||
if DEBUG: log('read line: %s' % l)
|
||||
if DEBUG:
|
||||
log('read line: %s' % l)
|
||||
return l.strip().split('\t')
|
||||
|
||||
|
||||
@ -95,7 +101,8 @@ class DynamicBackend:
|
||||
|
||||
while True:
|
||||
cmd = get_next()
|
||||
if DEBUG: log(cmd)
|
||||
if DEBUG:
|
||||
log(cmd)
|
||||
|
||||
if len(cmd) < 6:
|
||||
log('did not understand: %s' % cmd)
|
||||
@ -132,20 +139,24 @@ class DynamicBackend:
|
||||
subparts = ip_dashes.split('-')
|
||||
|
||||
if len(subparts) < 4:
|
||||
if DEBUG: log('subparts less than 4')
|
||||
if DEBUG:
|
||||
log('subparts less than 4')
|
||||
self.handle_self(qname)
|
||||
return
|
||||
|
||||
ipaddress = subparts[-4:]
|
||||
if DEBUG: log('ip: %s' % ipaddress)
|
||||
if DEBUG:
|
||||
log('ip: %s' % ipaddress)
|
||||
for part in ipaddress:
|
||||
if re.match('^\d{1,3}$', part) is None:
|
||||
if DEBUG: log('%s is not a number' % part)
|
||||
if DEBUG:
|
||||
log('%s is not a number' % part)
|
||||
self.handle_self(qname)
|
||||
return
|
||||
parti = int(part)
|
||||
if parti < 0 or parti > 255:
|
||||
if DEBUG: log('%d is too big/small' % parti)
|
||||
if DEBUG:
|
||||
log('%d is too big/small' % parti)
|
||||
self.handle_self(qname)
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user