Merge pull request #3117 from cortesi/morefixes

More misc fixes
This commit is contained in:
Aldo Cortesi 2018-05-12 14:41:23 +12:00 committed by GitHub
commit 7fde02ac90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -59,9 +59,7 @@ class RequestReplayThread(basethread.BaseThread):
# In all modes, we directly connect to the server displayed
if self.options.mode.startswith("upstream:"):
server_address = server_spec.parse_with_mode(self.options.mode)[1].address
server = connections.ServerConnection(
server_address, (self.options.listen_host, 0)
)
server = connections.ServerConnection(server_address)
server.connect()
if r.scheme == "https":
connect_request = http.make_connect_request((r.data.host, r.port))
@ -85,10 +83,7 @@ class RequestReplayThread(basethread.BaseThread):
r.first_line_format = "absolute"
else:
server_address = (r.host, r.port)
server = connections.ServerConnection(
server_address,
(self.options.listen_host, 0)
)
server = connections.ServerConnection(server_address)
server.connect()
if r.scheme == "https":
server.establish_tls(

View File

@ -236,7 +236,10 @@ class CommandManager(mitmproxy.types._CommandBase):
"""
Execute a command string. May raise CommandError.
"""
parts = list(lexer(cmdstr))
try:
parts = list(lexer(cmdstr))
except ValueError as e:
raise exceptions.CommandError("Command error: %s" % e)
if not len(parts) >= 1:
raise exceptions.CommandError("Invalid command: %s" % cmdstr)
return self.call_strings(parts[0], parts[1:])

View File

@ -96,8 +96,8 @@ class Reply:
def commit(self):
"""
Ultimately, messages are committed. This is done either automatically by
if the message is not taken or manually by the entity which called
.take().
the handler if the message is not taken or manually by the entity which
called .take().
"""
if self.state != "taken":
raise exceptions.ControlException(

View File

@ -281,6 +281,8 @@ def test_simple():
c.execute("one.two too many args")
with pytest.raises(exceptions.CommandError, match="Unknown"):
c.call("nonexistent")
with pytest.raises(exceptions.CommandError, match="No escaped"):
c.execute("\\")
c.add("empty", a.empty)
c.execute("empty")