-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.py
More file actions
36 lines (28 loc) · 779 Bytes
/
protocol.py
File metadata and controls
36 lines (28 loc) · 779 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
'''
Created on 21 Nov 2018
@author: devwarrior
'''
class Protocol(object):
'''
Defines requests and responses between app-client and app-server
'''
known_cmds = [ 'ping' ]
@classmethod
def make_ping_request(cls):
return dict(
type="text/json",
encoding="utf-8",
content=dict(cmd='ping'),
)
#. . .
@classmethod
def get_response_content(cls, request):
content = {'error': None}
cmd = request['cmd']
if not cmd in cls.known_cmds:
content['error'] = 'unknown command: {}'.format(cmd)
return content
if cmd == 'ping':
content['result'] = 'pong'
#
return content