Websocket.py
898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
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: