Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ISO8583/ISO8583.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,11 @@ def setBit(self, bit, value):
self.BITMAP[0] = self.BITMAP[0] | self._TMP[2] # need to set bit 1 of first "bit" in bitmap

if (bit % 8) == 0:
pos = (bit / 8) - 1
# pos = (bit / 8) - 1
pos = (bit // 8) - 1
else:
pos = (bit / 8)
# pos = (bit / 8)
pos = (bit // 8)

# need to check if the value can be there .. AN , N ... etc ... and the size

Expand Down Expand Up @@ -1160,6 +1162,8 @@ def getNetworkISO(self, bigEndian=True):
netIso = ""
asciiIso = self.getRawIso()

leng = len(asciiIso)

if bigEndian:
netIso = struct.pack('!h', len(asciiIso))
if self.DEBUG == True:
Expand All @@ -1169,9 +1173,9 @@ def getNetworkISO(self, bigEndian=True):
if self.DEBUG == True:
print('Pack Little-endian')

netIso += asciiIso
res = netIso + asciiIso.encode()

return netIso
return res

################################################################################################

Expand Down Expand Up @@ -1210,7 +1214,7 @@ def setNetworkISO(self, iso, bigEndian=True):
if len(iso) < 24:
raise InvalidIso8583('This is not a valid iso!!Invalid Size')

size = iso[0:2]
size = iso[0:2].encode()
if bigEndian:
size = struct.unpack('!h', size)
if self.DEBUG == True:
Expand Down
4 changes: 3 additions & 1 deletion ISO8583/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
"""

__all__ = ['ISO8583', 'ISOErrors']
30 changes: 1 addition & 29 deletions README
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
(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/>.

========================================================================

*) To install information, read INSTALL DOC


*) To read the documentation use pyDoc.

*) To generate HTML documentation use:
1) Go to doc dir
2) Use the command: pydoc -w PATH_TO_ISO8583_UNCOMPRESSED_DIR
3) That's it!


========================================================================
Newbie porting (https://github.com/Seedstars/python-iso8583) to Python 3
154 changes: 73 additions & 81 deletions examples/echoClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,103 +17,95 @@

"""


from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *
import socket
import sys
import time


# Configure the client
serverIP = "192.168.0.103"
serverPort = 8583
serverIP = "127.0.0.1"
serverPort = 7777
numberEcho = 5
timeBetweenEcho = 5 # in seconds
timeBetweenEcho = 5 # in seconds

bigEndian = True
#bigEndian = False
# bigEndian = False

s = None
for res in socket.getaddrinfo(serverIP, serverPort, socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
s = socket.socket(af, socktype, proto)
except socket.error as msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
s.connect(sa)
except socket.error as msg:
s.close()
s = None
continue
break
if s is None:
print ('Could not connect :(')
print('Could not connect :(')
sys.exit(1)



for req in range(0,numberEcho):
iso = ISO8583()
iso.setMTI('0800')
iso.setBit(3,'300000')
iso.setBit(24,'045')
iso.setBit(41,'11111111')
iso.setBit(42,'222222222222222')
iso.setBit(63,'This is a Test Message')
if bigEndian:
try:
message = iso.getNetworkISO()
s.send(message)
print ('Sending ... %s' % message)
ans = s.recv(2048)
print ("\nInput ASCII |%s|" % ans)
isoAns = ISO8583()
isoAns.setNetworkISO(ans)
v1 = isoAns.getBitsAndValues()
for v in v1:
print ('Bit %s of type %s with value = %s' % (v['bit'],v['type'],v['value']))

if isoAns.getMTI() == '0810':
print ("\tThat's great !!! The server understand my message !!!")
else:
print ("The server dosen't understand my message!")

except InvalidIso8583, ii:
print ii
break


time.sleep(timeBetweenEcho)

else:
try:
message = iso.getNetworkISO(False)
s.send(message)
print ('Sending ... %s' % message)
ans = s.recv(2048)
print ("\nInput ASCII |%s|" % ans)
isoAns = ISO8583()
isoAns.setNetworkISO(ans,False)
v1 = isoAns.getBitsAndValues()
for v in v1:
print ('Bit %s of type %s with value = %s' % (v['bit'],v['type'],v['value']))

if isoAns.getMTI() == '0810':
print ("\tThat's great !!! The server understand my message !!!")
else:
print ("The server dosen't understand my message!")

except InvalidIso8583, ii:
print ii
break

time.sleep(timeBetweenEcho)



print ('Closing...')
s.close()


for req in range(0, numberEcho):
iso = ISO8583()
iso.setMTI('0800')
iso.setBit(3, '300000')
iso.setBit(24, '045')
iso.setBit(41, '11111111')
iso.setBit(42, '222222222222222')
iso.setBit(63, 'This is a Test Message')
if bigEndian:
try:
message = iso.getNetworkISO()
s.send(message)
print('Sending ... %s' % message)
ans = s.recv(2048).decode()
print("\nInput ASCII |%s|" % ans)
isoAns = ISO8583()
isoAns.setNetworkISO(ans)
v1 = isoAns.getBitsAndValues()
for v in v1:
print('Bit %s of type %s with value = %s' % (v['bit'], v['type'], v['value']))

if isoAns.getMTI() == '0810':
print("\tThat's great !!! The server understand my message !!!")
else:
print("The server dosen't understand my message!")

except InvalidIso8583 as ii:
print(ii)
break

time.sleep(timeBetweenEcho)

else:
try:
message = iso.getNetworkISO(False)
s.send(message)
print('Sending ... %s' % message)
ans = s.recv(2048)
print("\nInput ASCII |%s|" % ans)
isoAns = ISO8583()
isoAns.setNetworkISO(ans, False)
v1 = isoAns.getBitsAndValues()
for v in v1:
print('Bit %s of type %s with value = %s' % (v['bit'], v['type'], v['value']))

if isoAns.getMTI() == '0810':
print("\tThat's great !!! The server understand my message !!!")
else:
print("The server dosen't understand my message!")

except InvalidIso8583 as ii:
print(ii)
break

time.sleep(timeBetweenEcho)

print('Closing...')
s.close()
10 changes: 5 additions & 5 deletions examples/echoServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from socket import *

# Configure the server
serverIP = "192.168.0.103"
serverPort = 8583
serverIP = "127.0.0.1"
serverPort = 7777
maxConn = 5
bigEndian = True
#bigEndian = False
Expand All @@ -44,7 +44,7 @@
connection, address = s.accept()
while 1:
# receive message
isoStr = connection.recv(2048)
isoStr = connection.recv(2048).decode()
if isoStr:
print ("\nInput ASCII |%s|" % isoStr)
pack = ISO8583()
Expand All @@ -66,8 +66,8 @@
break


except InvalidIso8583, ii:
print ii
except InvalidIso8583 as ii:
print(ii)
break
except:
print ('Something happened!!!!')
Expand Down
8 changes: 4 additions & 4 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@

try:
print ('Bit 27 is there? %s' % p.getBit(27))
except BitNotSet, bns:
print bns
except BitNotSet as bns:
print(bns)


#More exceptions...
Expand All @@ -105,9 +105,9 @@
iso.setBit(17,17)
iso.setBit(49,9861) # this bit is wrong ...
iso.setBit(99,99)
except ValueToLarge, e:
except ValueToLarge as e:
print ('Value too large :( %s' % e)
except InvalidMTI, i:
except InvalidMTI as i:
print ('This MTI is wrong :( %s' % i)


Expand Down