mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
Tests fixed
This commit is contained in:
parent
4074a62c6c
commit
49f04e5546
4 changed files with 13 additions and 13 deletions
|
|
@ -141,7 +141,7 @@ class CommandManager(mitmproxy.types._CommandBase):
|
|||
|
||||
def add(self, path: str, func: typing.Callable):
|
||||
self.commands[path] = Command(self, path, func)
|
||||
# Collecting one-word commands for lexer
|
||||
# Collecting one-word command names for lexer
|
||||
if len(path.split(".")) == 1:
|
||||
self.oneword_commands.append(path)
|
||||
|
||||
|
|
@ -220,6 +220,8 @@ class CommandManager(mitmproxy.types._CommandBase):
|
|||
Execute a command string. May raise CommandError.
|
||||
"""
|
||||
lex = lexer.create_lexer(cmdstr, self.oneword_commands)
|
||||
print(list(lex))
|
||||
lex.lexpos = 0
|
||||
parser_return = self.command_parser.parse(lexer=lex)
|
||||
return parser_return
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ from mitmproxy import exceptions
|
|||
class CommandLanguageLexer:
|
||||
tokens = (
|
||||
"WHITESPACE",
|
||||
"ARRAY",
|
||||
"COMMAND",
|
||||
"PLAIN_STR",
|
||||
"QUOTED_STR"
|
||||
|
|
@ -19,11 +18,6 @@ class CommandLanguageLexer:
|
|||
plain_str = fr"[^{special_symbols}\s]+"
|
||||
|
||||
t_ignore_WHITESPACE = r"\s+" # We won't ignore it in the new language
|
||||
t_ARRAY = r"\w+(\,\w+)+"
|
||||
t_QUOTED_STR = r"""
|
||||
\'+[^\']*\'+ | # Single-quoted string
|
||||
\"+[^\"]*\"+ # Double-quoted string
|
||||
"""
|
||||
|
||||
def __init__(self, oneword_commands: typing.Sequence[str]):
|
||||
self.oneword_commands = dict.fromkeys(oneword_commands, "COMMAND")
|
||||
|
|
@ -32,6 +26,14 @@ class CommandLanguageLexer:
|
|||
r"""\w+(\.\w+)+"""
|
||||
return t
|
||||
|
||||
def t_QUOTED_STR(self, t):
|
||||
r"""
|
||||
\'+[^\']*\'+ | # Single-quoted string
|
||||
\"+[^\"]*\"+ # Double-quoted string
|
||||
"""
|
||||
t.value = t.value.strip("'\"")
|
||||
return t
|
||||
|
||||
@lex.TOKEN(plain_str)
|
||||
def t_PLAIN_STR(self, t):
|
||||
t.type = self.oneword_commands.get(t.value, "PLAIN_STR")
|
||||
|
|
|
|||
|
|
@ -35,15 +35,10 @@ class CommandLanguageParser:
|
|||
|
||||
def p_argument(self, p):
|
||||
"""argument : PLAIN_STR
|
||||
| quoted
|
||||
| ARRAY
|
||||
| QUOTED_STR
|
||||
| COMMAND"""
|
||||
p[0] = p[1]
|
||||
|
||||
def p_quoted(self, p):
|
||||
"""quoted : QUOTED_STR"""
|
||||
p[0] = p[1][1:-1] # removing quotes
|
||||
|
||||
def p_empty(self, p):
|
||||
"""empty :"""
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ class CommandBuffer:
|
|||
else:
|
||||
ret.append(("text", ""))
|
||||
ret.append(("text", " "))
|
||||
self.right()
|
||||
if remhelp:
|
||||
ret.append(("text", " "))
|
||||
for v in remhelp:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue