Websocket.py 898 Bytes
"""
Websocket protocol

Author: Georg Hopp <ghopp@spamtitan.com>
"""
from random import seed, randint
from base64 import b64encode, b64decode
from hashlib import sha1

from ..Protocol import Protocol

from Parser import Parser
from Composer import Composer
from Message import Message

class Websocket(Protocol):
    WS_UUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'

    @staticmethod
    def isHandshake(request):
        con = request.getHeader('Connection').lower()
        up  = request.getHeader('Upgrade').lower()

        return 'upgrade' in con and 'websocket' in up

    def __init__(self):
        self._parser   = Parser()
        self._composer = Composer()

    def getParser(self):
        return self._parser

    def getComposer(self):
        return self._composer

    def createMessage(self, remote=None):
        return Message(remote)

# vim: set ft=python et ts=8 sw=4 sts=4: