mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[1843] use re for directive matching
to work with both whitespace and case-insensitivity
This commit is contained in:
@@ -739,13 +739,8 @@ class BindCmdInterpreter(Cmd):
|
||||
of the sets as defined in command_sets.py'''
|
||||
if command.command == 'file':
|
||||
try:
|
||||
command_file = open(command.params['filename'])
|
||||
# copy them into a list for consistency with the built-in
|
||||
# sets of commands
|
||||
commands = []
|
||||
for line in command_file:
|
||||
commands.append(line)
|
||||
command_file.close()
|
||||
with open(command.params['filename']) as command_file:
|
||||
commands = command_file.readlines()
|
||||
except IOError as ioe:
|
||||
print("Error: " + str(ioe))
|
||||
return
|
||||
@@ -787,14 +782,14 @@ class BindCmdInterpreter(Cmd):
|
||||
line = line.strip()
|
||||
if verbose:
|
||||
print(line)
|
||||
if line.startswith('#'):
|
||||
if line.startswith('#') or len(line) == 0:
|
||||
continue
|
||||
elif line.startswith('!'):
|
||||
if line.startswith('!echo ') and len(line) > 6:
|
||||
if re.match('^!echo ', line, re.I) and len(line) > 6:
|
||||
print(line[6:])
|
||||
elif line.startswith('!verbose on'):
|
||||
elif re.match('^!verbose\s+on\s*$', line, re.I):
|
||||
verbose = True
|
||||
elif line.startswith('!verbose off'):
|
||||
elif re.match('^!verbose\s+off$', line, re.I):
|
||||
verbose = False
|
||||
else:
|
||||
print("Warning: ignoring unknown directive: " + line)
|
||||
|
@@ -1,6 +1,19 @@
|
||||
# this is a comment: commentexample1
|
||||
!echo this is an echo: echoexample
|
||||
!echo this is an echo: echoexample2
|
||||
!verbose on
|
||||
# this is a comment with verbose on: verbosecommentexample
|
||||
# this is a comment with verbose on: verbosecommentexample3
|
||||
!verbose off
|
||||
# this is a comment with verbose off again: commentexample2
|
||||
# this is a comment with verbose off again: commentexample4
|
||||
# empty lines and lines with only whitespace should be ignored
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# directives are case insensitive, and should handle whitespace
|
||||
!ECHO echoexample5
|
||||
!eChO echoexample6
|
||||
!Verbose ON
|
||||
# verbosecommentexample7
|
||||
!verBOSE off
|
||||
# commentexample8
|
||||
|
@@ -88,9 +88,13 @@ Feature: control with bindctl
|
||||
When I send bind10 the command execute file data/commands/directives
|
||||
last bindctl output should not contain Error
|
||||
last bindctl output should not contain commentexample1
|
||||
last bindctl output should contain echoexample
|
||||
last bindctl output should contain verbosecommentexample
|
||||
last bindctl output should not contain commentexample2
|
||||
last bindctl output should contain echoexample2
|
||||
last bindctl output should contain verbosecommentexample3
|
||||
last bindctl output should not contain commentexample4
|
||||
last bindctl output should contain echoexample5
|
||||
last bindctl output should contain echoexample6
|
||||
last bindctl output should contain verbosecommentexample7
|
||||
last bindctl output should not contain commentexample8
|
||||
|
||||
# bad_command contains a bad command, at which point execution should stop
|
||||
When I send bind10 the command execute file data/commands/bad_command
|
||||
|
Reference in New Issue
Block a user