-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiso8853.pyw
77 lines (66 loc) · 2.19 KB
/
iso8853.pyw
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
(C) Copyright 2009 Igor V. Custodio
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *
from socket import *
from datetime import datetime
import threading
import logging
from ViewDesk import *
from utils import *
import traceback
DEBUG = False
def _handler(connection, address):
iso = ISO8583(debug=True)
#iso = ISO8583()
logger = logging.getLogger()
try:
d = ({'color':'magenta4'})
logger.debug("Connection with %s has been established", address)
while True:
data = connection.recv(1024)
if data == "":
logger.debug("Connection has been lost")
break
logger.debug("Request: %s\n%s", datetime.now().strftime("%d/%m/%y %H:%M:%S"), dump(data), extra=d)
iso.setIsoContent(ByteToHex(data[2:]))
v3 = iso.getBitsAndValues()
for v in v3:
log_bit(v, iso, logger)
connection.sendall(data)
logger.debug("Response: %s\n%s", datetime.now().strftime("%d/%m/%y %H:%M:%S"), dump(data), extra=d)
except Exception, e:
if ( DEBUG == True ):
logger.exception("Problem handling request")
else:
logger.error("%s: %s" % (e.__class__.__name__,str(e),) )
finally:
logger.debug("Closing socket")
connection.close()
if __name__ == '__main__':
FORMAT = '%(asctime)-15s %(levelname)-9s %(message)s'
logging.basicConfig(level=logging.DEBUG, format=FORMAT)
logger = logging.getLogger('MultiHOST')
try:
txtWnd = ViewDesk('MultiHOST')
txtWnd.attach()
from InitHolder import Server
server = Server('0.0.0.0', 802, _handler)
server.start()
txtWnd.mainloop()
server.quit()
except:
logger.exception("Unexpected exception")
finally:
logger.info("Shutting down")