File: base.py

package info (click to toggle)
gevent-websocket 0.10.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 216 kB
  • sloc: python: 995; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (3)
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
class BaseProtocol(object):
    PROTOCOL_NAME = ''

    def __init__(self, app):
        self._app = app

    def on_open(self):
        self.app.on_open()

    def on_message(self, message):
        self.app.on_message(message)

    def on_close(self, reason=None):
        self.app.on_close(reason)

    @property
    def app(self):
        if self._app:
            return self._app
        else:
            raise Exception("No application coupled")

    @property
    def server(self):
        if not hasattr(self.app, 'ws'):
            return None

        return self.app.ws.handler.server

    @property
    def handler(self):
        if not hasattr(self.app, 'ws'):
            return None

        return self.app.ws.handler