def run_cherrypy_server_with_python3(host="127.0.0.1", port=9004): """ Runs a CherryPy server on Python 3.x """ import wsaccel wsaccel.patch_ws4py() run_cherrypy_server(host, port)
def run_cherrypy_server_with_wsaccel(host="127.0.0.1", port=9006): """ Runs a CherryPy server on Python 2.x with a cython driver for some internal operations. """ import wsaccel wsaccel.patch_ws4py() run_cherrypy_server(host, port)
def __init__(self, bus): try: import wsaccel wsaccel.patch_ws4py() except ImportError: # wsaccel isn't a requirement. also, this occurs when docs are # built on readthedocs.org pass BaseWebSocketPlugin.__init__(self, bus)
def received_message(self, m): self.cnt += 1 if self.cnt < 1000: self.send(msg) else: self.close(reason='Bye bye') print(time.time() - self.started_at) global patched if not patched: patched = True wsaccel.patch_ws4py() start_client() else: server.stop()
def run_gevent_server(host="127.0.0.1", port=9001): """ Runs a gevent server on Python 2.x """ from gevent import monkey; monkey.patch_all() import wsaccel wsaccel.patch_ws4py() from ws4py.websocket import EchoWebSocket from ws4py.server.geventserver import WebSocketWSGIApplication, WSGIServer server = WSGIServer((host, port), WebSocketWSGIApplication(handler_cls=EchoWebSocket)) logger = logging.getLogger('autobahn_testsuite') logger.warning("Serving gevent server on %s:%s" % (host, port)) server.serve_forever()
def run_gevent_server(host="127.0.0.1", port=9001): """ Runs a gevent server on Python 2.x """ from gevent import monkey monkey.patch_all() import wsaccel wsaccel.patch_ws4py() from ws4py.websocket import EchoWebSocket from ws4py.server.geventserver import WebSocketWSGIApplication, WSGIServer server = WSGIServer((host, port), WebSocketWSGIApplication(handler_cls=EchoWebSocket)) logger = logging.getLogger('autobahn_testsuite') logger.warning("Serving gevent server on %s:%s" % (host, port)) server.serve_forever()
def run_python3_asyncio(host="127.0.0.1", port=9009): """ Runs a server using asyncio and Python 3.3+ """ import asyncio import wsaccel wsaccel.patch_ws4py() from ws4py.async_websocket import EchoWebSocket from ws4py.server.tulipserver import WebSocketProtocol loop = asyncio.get_event_loop() def start_server(): proto_factory = lambda: WebSocketProtocol(EchoWebSocket) return loop.create_server(proto_factory, host, port) s = loop.run_until_complete(start_server()) logger = logging.getLogger('asyncio_testsuite') logger.warning("Serving asyncio server on %s:%s" % s.sockets[0].getsockname()) loop.run_forever()
def startup(self): """Validate that all of the external dependencies are installed""" ret = True # default /tmp/wptagent as an alive file on Linux if self.options.alive is None: if platform.system() == "Linux": self.options.alive = '/tmp/wptagent' else: self.options.alive = os.path.join(os.path.dirname(__file__), 'wptagent.alive') self.alive() ret = self.requires('dns', 'dnspython') and ret ret = self.requires('monotonic') and ret ret = self.requires('PIL', 'pillow') and ret ret = self.requires('psutil') and ret ret = self.requires('requests') and ret if not self.options.android and not self.options.iOS: ret = self.requires('tornado') and ret # Windows-specific imports if platform.system() == "Windows": ret = self.requires('win32api', 'pywin32') and ret # Optional imports self.requires('brotli') self.requires('fontTools', 'fonttools') # Try patching ws4py with a faster lib try: self.requires('wsaccel') import wsaccel wsaccel.patch_ws4py() except Exception: pass try: subprocess.check_output(['python', '--version']) except Exception: print "Make sure python 2.7 is available in the path." ret = False try: subprocess.check_output('{0} -version'.format(self.image_magick['convert']), shell=True) except Exception: print "Missing convert utility. Please install ImageMagick " \ "and make sure it is in the path." ret = False try: subprocess.check_output('{0} -version'.format(self.image_magick['mogrify']), shell=True) except Exception: print "Missing mogrify utility. Please install ImageMagick " \ "and make sure it is in the path." ret = False if platform.system() == "Linux": try: subprocess.check_output(['traceroute', '--version']) except Exception: logging.debug("Traceroute is missing, installing...") subprocess.call(['sudo', 'apt-get', '-yq', 'install', 'traceroute']) # If we are on Linux and there is no display, enable xvfb by default if platform.system() == "Linux" and not self.options.android and \ not self.options.iOS and 'DISPLAY' not in os.environ: self.options.xvfb = True if self.options.xvfb: ret = self.requires('xvfbwrapper') and ret if ret: from xvfbwrapper import Xvfb self.xvfb = Xvfb(width=1920, height=1200, colordepth=24) self.xvfb.start() # Figure out which display to capture from if platform.system() == "Linux" and 'DISPLAY' in os.environ: logging.debug('Display: %s', os.environ['DISPLAY']) self.capture_display = os.environ['DISPLAY'] elif platform.system() == "Darwin": proc = subprocess.Popen('ffmpeg -f avfoundation -list_devices true -i ""', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) _, err = proc.communicate() for line in err.splitlines(): matches = re.search(r'\[(\d+)\] Capture screen', line) if matches: self.capture_display = matches.group(1) break elif platform.system() == "Windows": self.capture_display = 'desktop' if self.options.throttle: try: subprocess.check_output('sudo cgset -h', shell=True) except Exception: print "Missing cgroups, make sure cgroup-tools is installed." ret = False # Fix Lighthouse install permissions if platform.system() != "Windows": from internal.os_util import run_elevated run_elevated('chmod', '-R 777 ~/.config/configstore/') try: import getpass run_elevated('chown', '-R {0}:{0} ~/.config'.format(getpass.getuser())) except Exception: pass # Check for Node 10+ if self.get_node_version() < 10.0: if platform.system() == "Linux": # This only works on debian-based systems logging.debug('Updating Node.js to 10.x') subprocess.call('curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -', shell=True) subprocess.call(['sudo', 'apt-get', 'install', '-y', 'nodejs']) if self.get_node_version() < 10.0: logging.warning("Node.js 10 or newer is required for Lighthouse testing") # Check the iOS install if self.ios is not None: ret = self.ios.check_install() if not self.options.android and not self.options.iOS and not self.options.noidle: self.wait_for_idle(300) if self.adb is not None: if not self.adb.start(): print "Error configuring adb. Make sure it is installed and in the path." ret = False self.shaper.remove() if not self.shaper.install(): if platform.system() == "Windows": print "Error configuring traffic shaping, make sure secure boot is disabled." else: print "Error configuring traffic shaping, make sure it is installed." ret = False # Update the Windows root certs if platform.system() == "Windows": self.update_windows_certificates() return ret
You can specify the base url which will be used to build the URL to the board. For instance, a board's url will be: https://myhost/board/c866 """ import json import os.path import tempfile import time import uuid try: import wsaccel wsaccel.patch_ws4py() except ImportError: pass from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool from ws4py.websocket import WebSocket import cherrypy from cherrypy.process import plugins from mako.lookup import TemplateLookup from mako.template import Template BASE_URL = None cwd_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) bus = cherrypy.engine
import os import re import requests import warnings import six try: import wsaccel except ImportError: wsaccel = None from six.moves import urllib from ws4py.client.threadedclient import WebSocketClient as WS4PyWebSocketClient try: if wsaccel is not None: wsaccel.patch_ws4py() except Exception as exc: warnings.warn('Could not import wsaccel: %s' % exc, RuntimeWarning) class WebSocketClient(WS4PyWebSocketClient): ''' Websocket Client Parameters ---------- url : string The URL to connect to on_open : function, optional Function to call when the websocket is connected on_close : function, optional
# -*- coding: utf-8 -*- from gevent import monkey; monkey.patch_all() import argparse import random import os import gevent import gevent.pywsgi from ws4py.server.geventserver import WebSocketWSGIApplication, \ WebSocketWSGIHandler, WSGIServer from ws4py.websocket import EchoWebSocket import wsaccel; wsaccel.patch_ws4py() class BroadcastWebSocket(EchoWebSocket): def opened(self): app = self.environ['ws4py.app'] app.clients.append(self) def received_message(self, m): # self.clients is set from within the server # and holds the list of all connected servers # we can dispatch to app = self.environ['ws4py.app'] for client in app.clients: client.send(m) def closed(self, code, reason="A client left the room without a proper explanation."): app = self.environ.pop('ws4py.app')