add raw mode to wsdump.py
This commit is contained in:
@@ -45,6 +45,8 @@ def parse_args():
|
|||||||
"If set to 2, enable to trace websocket module")
|
"If set to 2, enable to trace websocket module")
|
||||||
parser.add_argument("-n", "--nocert", action='store_true',
|
parser.add_argument("-n", "--nocert", action='store_true',
|
||||||
help="Ignore invalid SSL cert")
|
help="Ignore invalid SSL cert")
|
||||||
|
parser.add_argument("-r", "--raw", action="store_true",
|
||||||
|
help="raw output")
|
||||||
parser.add_argument("-s", "--subprotocols", nargs='*',
|
parser.add_argument("-s", "--subprotocols", nargs='*',
|
||||||
help="Set subprotocols")
|
help="Set subprotocols")
|
||||||
parser.add_argument("-o", "--origin",
|
parser.add_argument("-o", "--origin",
|
||||||
@@ -54,15 +56,7 @@ def parse_args():
|
|||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
class RawInput():
|
||||||
class InteractiveConsole(code.InteractiveConsole):
|
|
||||||
def write(self, data):
|
|
||||||
sys.stdout.write("\033[2K\033[E")
|
|
||||||
# sys.stdout.write("\n")
|
|
||||||
sys.stdout.write("\033[34m< " + data + "\033[39m")
|
|
||||||
sys.stdout.write("\n> ")
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
def raw_input(self, prompt):
|
def raw_input(self, prompt):
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
line = input(prompt)
|
line = input(prompt)
|
||||||
@@ -76,10 +70,28 @@ class InteractiveConsole(code.InteractiveConsole):
|
|||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
class InteractiveConsole(RawInput, code.InteractiveConsole):
|
||||||
|
def write(self, data):
|
||||||
|
sys.stdout.write("\033[2K\033[E")
|
||||||
|
# sys.stdout.write("\n")
|
||||||
|
sys.stdout.write("\033[34m< " + data + "\033[39m")
|
||||||
|
sys.stdout.write("\n> ")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
return self.raw_input("> ")
|
||||||
|
|
||||||
|
class NonInteractive(RawInput):
|
||||||
|
def write(self, data):
|
||||||
|
sys.stdout.write(data)
|
||||||
|
sys.stdout.write("\n")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
return self.raw_input("")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
console = InteractiveConsole()
|
|
||||||
if args.verbose > 1:
|
if args.verbose > 1:
|
||||||
websocket.enableTrace(True)
|
websocket.enableTrace(True)
|
||||||
options = {}
|
options = {}
|
||||||
@@ -91,6 +103,10 @@ def main():
|
|||||||
if (args.nocert):
|
if (args.nocert):
|
||||||
opts = { "cert_reqs": websocket.ssl.CERT_NONE, "check_hostname": False }
|
opts = { "cert_reqs": websocket.ssl.CERT_NONE, "check_hostname": False }
|
||||||
ws = websocket.create_connection(args.url, sslopt=opts, **options)
|
ws = websocket.create_connection(args.url, sslopt=opts, **options)
|
||||||
|
if args.raw:
|
||||||
|
console = NonInteractive()
|
||||||
|
else:
|
||||||
|
console = InteractiveConsole()
|
||||||
print("Press Ctrl+C to quit")
|
print("Press Ctrl+C to quit")
|
||||||
|
|
||||||
def recv():
|
def recv():
|
||||||
@@ -136,7 +152,7 @@ def main():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
message = console.raw_input("> ")
|
message = console.read()
|
||||||
ws.send(message)
|
ws.send(message)
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Reference in New Issue
Block a user