-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequests.py
More file actions
36 lines (30 loc) · 930 Bytes
/
Requests.py
File metadata and controls
36 lines (30 loc) · 930 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
# -*- coding:utf-8 -*-
from Message import Message
import network
class Requests :
def __init__(self, key, message_type) :
self.key = key
self.message_type = message_type
def run(self, socket) :
self.content = {}
for x in self.fields :
l = raw_input(x + ": ")
self.content[x] = l
msg = self.prepare_message(socket)
network.send(socket, msg)
self.response(socket)
def prepare_message(self, socket) :
header ={}
body = {}
body["content"] = {}
header["type"] = self.message_type
header["ack"] = ""
body["content"] = self.content
msg = Message(header, body)
return msg
def response(self, socket) :
msg, rest = network.receive(socket)
message = Message()
message.create_message(msg)
body = message.get_body()
return body