Commit fc475649 authored by nduca@chromium.org's avatar nduca@chromium.org

Initial checkin for devtools-based automation

Review URL: https://chromiumcodereview.appspot.com/10825463

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152439 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f796d60
# The set noparent is temporary until src/OWNERS isn't *.
set noparent
nduca@chromium.org
alokp@chromium.org
dtu@chromium.org
devtools_auto provides automation of chrome instances on top of the chrome developer tools protocol.
The protocol we use:
https://developers.google.com/chrome-developer-tools/docs/remote-debugging
*.pyc
*~
*\#
.\#*
build
dist
websocket_client.egg-info
This diff is collapsed.
Name: Python websocket-client
Short Name: websocket-client
URL: https://github.com/liris/websocket-client
Version: 0
Revision: 861f9cf354833fe3992315b60292865c5245c821
Date: Tue Jul 10 19:57:00 2012 -0700
License: LGPL-2.1
License File: NOT_SHIPPED
Security Critical: no
Description:
websocket-client module is WebSocket client for python. This provide the low
level APIs for WebSocket. All APIs are the synchronous functions.
Used by the python code in devtools-auto to communicate with a running Chrome instance.
Local Modifications:
None.
=================
websocket-client
=================
websocket-client module is WebSocket client for python. This provide the low level APIs for WebSocket. All APIs are the synchronous functions.
websocket-client supports only hybi-13.
License
============
- LGPL
Installation
=============
This module is tested on only Python 2.7.
Type "python setup.py install" or "pip install websocket-client" to install.
This module does not depend on any other module.
Example
============
Low Level API example::
from websocket import create_connection
ws = create_connection("ws://echo.websocket.org/")
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
print "Reeiving..."
result = ws.recv()
print "Received '%s'" % result
ws.close()
JavaScript websocket-like API example::
import websocket
import thread
import time
def on_message(ws, message):
print message
def on_error(ws, error):
print error
def on_close(ws):
print "### closed ###"
def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
ws.send("Hello %d" % i)
time.sleep(1)
ws.close()
print "thread terminating..."
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://echo.websocket.org/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
wsdump.py
============
wsdump.py is simple WebSocket test(debug) tool.
sample for echo.websocket.org::
$ wsdump.py ws://echo.websocket.org/
Press Ctrl+C to quit
> Hello, WebSocket
< Hello, WebSocket
> How are you?
< How are you?
Usage
---------
usage::
wsdump.py [-h] [-v [VERBOSE]] ws_url
WebSocket Simple Dump Tool
positional arguments:
ws_url websocket url. ex. ws://echo.websocket.org/
optional arguments:
-h, --help show this help message and exit
-v VERBOSE, --verbose VERBOSE set verbose mode. If set to 1, show opcode. If set to 2, enable to trace websocket module
example::
$ wsdump.py ws://echo.websocket.org/
$ wsdump.py ws://echo.websocket.org/ -v
$ wsdump.py ws://echo.websocket.org/ -vv
ChangeLog
============
- v0.7.0
- fixed problem to read long data.(ISSUE#12)
- fix buffer size boundary violation
- v0.6.0
- Patches: UUID4, self.keep_running, mask_key (ISSUE#11)
- add wsdump.py tool
- v0.5.2
- fix Echo App Demo Throw Error: 'NoneType' object has no attribute 'opcode (ISSUE#10)
- v0.5.1
- delete invalid print statement.
- v0.5.0
- support hybi-13 protocol.
- v0.4.1
- fix incorrect custom header order(ISSUE#1)
#!/usr/bin/env python
import argparse
import code
import sys
import threading
import websocket
try:
import readline
except:
pass
OPCODE_DATA = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
ENCODING = getattr(sys.stdin, "encoding", "").lower()
class VAction(argparse.Action):
def __call__(self, parser, args, values, option_string=None):
if values==None:
values = "1"
try:
values = int(values)
except ValueError:
values = values.count("v")+1
setattr(args, self.dest, values)
def parse_args():
parser = argparse.ArgumentParser(description="WebSocket Simple Dump Tool")
parser.add_argument("url", metavar="ws_url",
help="websocket url. ex. ws://echo.websocket.org/")
parser.add_argument("-v", "--verbose", default=0, nargs='?', action=VAction,
dest="verbose",
help="set verbose mode. If set to 1, show opcode. "
"If set to 2, enable to trace websocket module")
return parser.parse_args()
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):
line = raw_input(prompt)
if ENCODING and ENCODING != "utf-8" and not isinstance(line, unicode):
line = line.decode(ENCODING).encode("utf-8")
elif isinstance(line, unicode):
line = encode("utf-8")
return line
def main():
args = parse_args()
console = InteractiveConsole()
ws = websocket.create_connection(args.url)
if args.verbose > 1:
websocket.enableTrace(True)
print "Press Ctrl+C to quit"
def recv():
frame = ws.recv_frame()
if not frame:
raise websocket.WebSocketException("Not a valid frame %s" % frame)
elif frame.opcode in OPCODE_DATA:
return (frame.opcode, frame.data)
elif frame.opcode == websocket.ABNF.OPCODE_CLOSE:
ws.send_close()
return (frame.opcode, None)
elif frame.opcode == websocket.ABNF.OPCODE_PING:
ws.pong("Hi!")
return None, None
def recv_ws():
while True:
opcode, data = recv()
msg = None
if not args.verbose and opcode in OPCODE_DATA:
msg = "< %s" % data
elif args.verbose:
msg = "< %s: %s" % (websocket.ABNF.OPCODE_MAP.get(opcode), data)
if msg:
console.write(msg)
thread = threading.Thread(target=recv_ws)
thread.daemon = True
thread.start()
while True:
try:
message = console.raw_input("> ")
ws.send(message)
except KeyboardInterrupt:
return
except EOFError:
return
if __name__ == "__main__":
try:
main()
except Exception, e:
print e
HTTP/1.1 101 WebSocket Protocol Handshake
Connection: Upgrade
Upgrade: WebSocket
Sec-WebSocket-Accept: Kxep+hNu9n51529fGidYu7a3wO0=
some_header: something
HTTP/1.1 101 WebSocket Protocol Handshake
Connection: Upgrade
Upgrade WebSocket
Sec-WebSocket-Accept: Kxep+hNu9n51529fGidYu7a3wO0=
some_header: something
import websocket
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.create_connection("ws://echo.websocket.org/")
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
print "Receiving..."
result = ws.recv()
print "Received '%s'" % result
ws.close()
import websocket
import thread
import time
import sys
def on_message(ws, message):
print message
def on_error(ws, error):
print error
def on_close(ws):
print "### closed ###"
def on_open(ws):
def run(*args):
for i in range(3):
# send the message, then wait
# so thread doesnt exit and socket
# isnt closed
ws.send("Hello %d" % i)
time.sleep(1)
time.sleep(1)
ws.close()
print "Thread terminating..."
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
if len(sys.argv) < 2:
host = "ws://echo.websocket.org/"
else:
host = sys.argv[1]
ws = websocket.WebSocketApp(host,
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
from setuptools import setup
VERSION = "0.7.0"
setup(
name="websocket-client",
version=VERSION,
description="WebSocket client for python. hybi13 is supported.",
long_description=open("README.rst").read(),
author="liris",
author_email="liris.pp@gmail.com",
license="LGPL",
url="https://github.com/liris/websocket-client",
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Programming Language :: Python",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Operating System :: Microsoft :: Windows",
"Topic :: Internet",
"Topic :: Software Development :: Libraries :: Python Modules",
"Intended Audience :: Developers",
],
py_modules=["websocket"],
scripts=["bin/wsdump.py"]
)
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment