Редакция 4 | Весь файл | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 4 | Редакция 6 | ||
---|---|---|---|
Строка 1... | Строка 1... | ||
1 | # -*- coding: utf-8 -*-
|
1 | Я -*- coding: utf-8 -*-
|
2 | """ PyCODC NMDC/ADC Client """
|
2 | """ PyCODC NMDC/ADC Client """
|
3 | from twisted.internet import protocol |
3 | from twisted.internet import protocol |
4 | from twisted.protocols import basic |
4 | from twisted.protocols import basic |
5 | from twisted.python import log |
5 | from twisted.python import log |
6 | 6 | ||
Строка 18... | Строка 18... | ||
18 | encoding = None |
18 | encoding = None |
19 | hostname = None |
19 | hostname = None |
20 | 20 | ||
21 | def lineReceived(self, line): |
21 | def lineReceived(self, line): |
22 | print "Line Received: %s" % line |
22 | print "Line Received: %s" % line |
23 | command, params = self.parseLine(line) |
23 | self.parseLine(line) |
24 | self.handleCommand(command, params) |
- | |
25 | 24 | ||
26 | def connectionLost(self, reason): |
25 | def connectionLost(self, reason): |
27 | print "Conlost: %s" %self |
26 | print "Conlost: %s" %self |
28 | 27 | ||
29 | def connectionMade(self): |
28 | def connectionMade(self): |
Строка 44... | Строка 43... | ||
44 | try:
|
43 | try:
|
45 | m = re.match("^\$(?P<command>[a-zA-Z]+)[ ](?P<params>.+$)", line) |
44 | m = re.match("^\$(?P<command>[a-zA-Z]+)[ ](?P<params>.+$)", line) |
46 | 45 | ||
47 | command = m.group("command") |
46 | command = m.group("command") |
48 | params = m.group("params") |
47 | params = m.group("params") |
49 | print "NMDC Command: %s; Params: %s" %(command, params) |
48 | self.handleCommand(command, params) |
50 | except:
|
49 | except:
|
51 | print "Exception: %s"% line |
50 | print "Exception: %s"% line |
52 | return command, params |
- | |
53 | else:
|
- | |
54 | return "", "" |
- | |
55 | 51 | ||
56 | def handleCommand(self, command, params): |
52 | def handleCommand(self, command, params): |
57 | print "handleCommand: %s %s" % (command, params) |
53 | print "handleCommand: %s %s" % (command, params) |
58 | method = getattr(self, "nmdc_%s" % command, None) |
54 | method = getattr(self, "nmdc_%s" % command, None) |
59 | try:
|
55 | try:
|
Строка 72... | Строка 68... | ||
72 | answer = "$%s|"% command |
68 | answer = "$%s|"% command |
73 | 69 | ||
74 | self.sendLine(answer) |
70 | self.sendLine(answer) |
75 | print "makeAnswer: %s" % answer |
71 | print "makeAnswer: %s" % answer |
76 | 72 | ||
- | 73 | def nmdc_rawline(self, line): |
|
- | 74 | print "rawline: %s"% line |
|
- | 75 | ||
77 | def nmdc_unknown(self, command, params): |
76 | def nmdc_unknown(self, command): |
78 | print "nmdc_%s doesn't exist. Called with params: %s" % (command,params) |
77 | print "nmdc_%s doesn't exist." % command |
79 | 78 |