This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from HTMLParser import HTMLParser | |
whitespace = re.compile('(\w+)') | |
class HTMLAbbrev(HTMLParser): | |
def __init__(self, maxlength, *args, **kwargs): | |
HTMLParser.__init__(self, *args, **kwargs) | |
self.stack = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gevent.pywsgi | |
from websocket import WebSocketUpgrader | |
class UpgradableWSGIHandler(gevent.pywsgi.WSGIHandler): | |
def handle_one_response(self): | |
connection_header = self.environ.get('HTTP_CONNECTION', '').lower() | |
if connection_header == 'upgrade' and self.server.upgrade_handler: | |
upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower() | |
handler = self.server.upgrade_handler(upgrade_header, self.environ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from gevent import server | |
from gevent.baseserver import _tcp_listener | |
from gevent.monkey import patch_all; patch_all() | |
from multiprocessing import Process, current_process, cpu_count | |
def note(format, *args): | |
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Class for managing multiple servers or anything with start() and stop() methods | |
class ServerRack(object): | |
def __init__(self, servers): | |
self.servers = servers | |
def start(self): | |
started = [] | |
try: |