class ucserver asyncore dispatcher def __init__ self address asyncore

 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
class ucserver(asyncore.dispatcher):
def __init__(self, address):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.bind(address)
self.address = self.socket.getsockname()
self.listen(5)
def handle_accept(self):
conn, addr = self.accept()
uchandler(sock=conn)
def handle_close(self):
self.close()
class Command(BaseCommand):
help = ('starts a simple server answering if user is allowed to '
'write in repo')
args = ''
def handle(self, *args, **kwargs):
server = ucserver(('localhost', 8888))
print server.address
try:
asyncore.loop(timeout=2)
except KeyboardInterrupt:
print 'Ctrl-C pressed, exiting...'
server.close()