rest.py

changeset 96
24f0b13e87d3
parent 95
af912f53649c
child 97
55d7d9aea160
equal deleted inserted replaced
95:af912f53649c 96:24f0b13e87d3
47 g_throttle[g_throttle.index (address)][1] = tt 47 g_throttle[g_throttle.index (address)][1] = tt
48 except ValueError: 48 except ValueError:
49 # not in list 49 # not in list
50 g_throttle.append ([address, tt]) 50 g_throttle.append ([address, tt])
51 51
52 Irc.broadcast ('Throttling %s:%s for 30 seconds' % address) 52 Irc.broadcast ('Throttling %s for 30 seconds' % address)
53 53
54 def handle_rest_http (data, address): 54 def handle_rest_http (data, address):
55 global g_credentials 55 global g_credentials
56 displayaddress = address 56 displayaddress = address
57 authrex = re.compile (r'^authorization: Basic (.+)$') 57 authrex = re.compile (r'^authorization: Basic (.+)$')
73 match = payloadrex.match (line) 73 match = payloadrex.match (line)
74 if match: 74 if match:
75 payload = match.group (1) 75 payload = match.group (1)
76 76
77 if not authenticated: 77 if not authenticated:
78 Irc.broadcast ('%s:%s failed to authenticate' % address) 78 Irc.broadcast ('%s failed to authenticate' % address)
79 throttle (address) 79 throttle (address)
80 return 80 return
81 81
82 jsonstring = urllib.unquote_plus (payload).decode ('utf-8') 82 jsonstring = urllib.unquote_plus (payload).decode ('utf-8')
83 83
110 httpdata = '' 110 httpdata = ''
111 writebuffer = '' 111 writebuffer = ''
112 address = None 112 address = None
113 113
114 def __init__ (self, conn, address): 114 def __init__ (self, conn, address):
115 asyncore.dispatcher.__init__ (self, conn, address) 115 asyncore.dispatcher.__init__ (self, conn)
116 self.socket = ssl.wrap_socket (conn, server_side=True, keyfile='key.pem', 116 self.socket = ssl.wrap_socket (conn, server_side=True, keyfile='key.pem',
117 certfile='cert.pem', do_handshake_on_connect=False) 117 certfile='cert.pem', do_handshake_on_connect=False)
118 self.socket.setblocking (0) 118 self.socket.settimeout (3)
119 self.address = address 119 self.address = address
120 print 'Initialized connection handler for %s' % type (address)
121 120
122 while True: 121 while True:
123 try: 122 try:
124 self.socket.do_handshake() 123 self.socket.do_handshake()
125 break 124 break

mercurial