File: example1.py

package info (click to toggle)
python-iso8583 1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 240 kB
  • ctags: 230
  • sloc: python: 900; makefile: 34
file content (115 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""

(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 *
import traceback

#Clean the shell
import os
os.system(['clear','cls'][os.name == 'nt'])

# get new object
p = ISO8583()
#some string describing the transation type
transation = "200"
print 'Setting transation type to %s' % transation
p.setTransationType(transation)
# Is the same that:
#p.setMTI(transation)

#Some tests and 
print 'Setting bits'

p.setBit(3,"100000")
p.setBit(4,1200)
p.setBit(7,"1207231505")
p.setBit(11,12)
p.setBit(12,"231505")
p.setBit(13,1207)
p.setBit(32,"01020000000")
p.setBit(40,"002")
p.setBit(41,"98765432")
p.setBit(42,"303500098765432")
p.setBit(49,986)
p.setBit(62,"PP16814995840013560000")
p.setBit(63,"00000105")
try:
	p.setBit(126,"00000000000000105")
except ValueToLarge:
	print '\t\tSomething happening!!!! The Exception! So, bit 126 is not set!!!!'
	#if want more information ...
	#traceback.print_exc()

#show hex bitmap
print 'Bitmap in HEX'
p.showBitmap()

#Show bits
print 'Bits with values'
p.showIsoBits()

# Show raw ASCII ISO
print 'The package is -> '
p.showRawIso()

# Getting bits...
print '\n\n\n------------------------------------------\n'

print 'Getting bits'
try:
	print 'Bit 7 is there? %s' % p.getBit(7)
	print 'Bit 32 is there? %s' % p.getBit(32)
except:
	print 'Something is bad...'
	
# Testing exceptions...	
try:
	print 'Bit 45 is there? %s' % p.getBit(45)
except:
	print "No, this bit is not there :)"	

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

#More exceptions...	
print '\n\n\n------------------------------------------\n'
print 'Exeptions....'

iso = ISO8583()
try:
	iso.setMTI('0800')
	iso.setBit(2,2)
	iso.setBit(4,4)
	iso.setBit(12,12)
	iso.setBit(21,21)
	iso.setBit(17,17)
	iso.setBit(49,9861) # this bit is wrong ...
	iso.setBit(99,99)
except ValueToLarge, e:
		print 'Value too large :( %s' % e
except InvalidMTI, i:
		print 'This MTI is wrong :( %s' % i