From f6af085e1a393a7ef8b7d194330b46e16ab217e2 Mon Sep 17 00:00:00 2001 From: liris Date: Wed, 13 May 2015 08:22:50 +0900 Subject: [PATCH] fixed #183 --- ChangeLog | 1 + bin/wsdump.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0e124bf..6d921ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ ChangeLog - Avoid deprecated BaseException.message (#180) - Add travis builds (#182) + - fixed wsdump to work with piped input (#183) - 0.30.0 diff --git a/bin/wsdump.py b/bin/wsdump.py index d98d240..00cd5eb 100755 --- a/bin/wsdump.py +++ b/bin/wsdump.py @@ -5,6 +5,7 @@ import code import six import sys import threading +import time import websocket try: import readline @@ -12,8 +13,17 @@ except: pass +def get_encoding(): + encoding = getattr(sys.stdin, "encoding", "") + if not encoding: + return "utf-8" + else: + return encoding.lower() + + OPCODE_DATA = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY) -ENCODING = getattr(sys.stdin, "encoding", "").lower() +ENCODING = get_encoding() + class VAction(argparse.Action): def __call__(self, parser, args, values, option_string=None): @@ -105,6 +115,7 @@ def main(): def recv_ws(): while True: opcode, data = recv() + print(data) msg = None if not args.verbose and opcode in OPCODE_DATA: msg = "< %s" % data @@ -128,6 +139,7 @@ def main(): try: message = console.raw_input("> ") ws.send(message) + time.sleep(0.05) except KeyboardInterrupt: return except EOFError: