mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +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'''
|
of the sets as defined in command_sets.py'''
|
||||||
if command.command == 'file':
|
if command.command == 'file':
|
||||||
try:
|
try:
|
||||||
command_file = open(command.params['filename'])
|
with open(command.params['filename']) as command_file:
|
||||||
# copy them into a list for consistency with the built-in
|
commands = command_file.readlines()
|
||||||
# sets of commands
|
|
||||||
commands = []
|
|
||||||
for line in command_file:
|
|
||||||
commands.append(line)
|
|
||||||
command_file.close()
|
|
||||||
except IOError as ioe:
|
except IOError as ioe:
|
||||||
print("Error: " + str(ioe))
|
print("Error: " + str(ioe))
|
||||||
return
|
return
|
||||||
@@ -787,14 +782,14 @@ class BindCmdInterpreter(Cmd):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
if verbose:
|
if verbose:
|
||||||
print(line)
|
print(line)
|
||||||
if line.startswith('#'):
|
if line.startswith('#') or len(line) == 0:
|
||||||
continue
|
continue
|
||||||
elif line.startswith('!'):
|
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:])
|
print(line[6:])
|
||||||
elif line.startswith('!verbose on'):
|
elif re.match('^!verbose\s+on\s*$', line, re.I):
|
||||||
verbose = True
|
verbose = True
|
||||||
elif line.startswith('!verbose off'):
|
elif re.match('^!verbose\s+off$', line, re.I):
|
||||||
verbose = False
|
verbose = False
|
||||||
else:
|
else:
|
||||||
print("Warning: ignoring unknown directive: " + line)
|
print("Warning: ignoring unknown directive: " + line)
|
||||||
|
@@ -1,6 +1,19 @@
|
|||||||
# this is a comment: commentexample1
|
# this is a comment: commentexample1
|
||||||
!echo this is an echo: echoexample
|
!echo this is an echo: echoexample2
|
||||||
!verbose on
|
!verbose on
|
||||||
# this is a comment with verbose on: verbosecommentexample
|
# this is a comment with verbose on: verbosecommentexample3
|
||||||
!verbose off
|
!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
|
When I send bind10 the command execute file data/commands/directives
|
||||||
last bindctl output should not contain Error
|
last bindctl output should not contain Error
|
||||||
last bindctl output should not contain commentexample1
|
last bindctl output should not contain commentexample1
|
||||||
last bindctl output should contain echoexample
|
last bindctl output should contain echoexample2
|
||||||
last bindctl output should contain verbosecommentexample
|
last bindctl output should contain verbosecommentexample3
|
||||||
last bindctl output should not contain commentexample2
|
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
|
# bad_command contains a bad command, at which point execution should stop
|
||||||
When I send bind10 the command execute file data/commands/bad_command
|
When I send bind10 the command execute file data/commands/bad_command
|
||||||
|
Reference in New Issue
Block a user