예제 #1
0
    def testType10(self):
        f = open(IMAGE,'rb')
        buf = f.read()
        f.close()
        msg = nistitl.Message()
        msg.TOT = 'TESTBIN'

        r2 = nistitl.AsciiRecord(2)
        r2.IDC = 1
        msg += r2
        
        r4 = nistitl.BinaryRecord(4)
        r4.IDC = 1
        msg += r4
        r4.value = buf

        r10 = nistitl.AsciiRecord(10)
        r10.IDC = 1
        msg += r10
        f999 = nistitl.BinaryField(10,999,buf)
        r10 += f999

        N = msg.NIST
        
        # parse the NIST
        msg = nistitl.Message()
        msg.parse(N)
        
        self.assertEqual(len(msg[2].value),12911)
        self.assertTrue(buf==msg[2].value)
    def test_full(self):
        msg = nistitl.Message()
        msg.TOT = 'MY_TOT'
        msg[0].TCN = 'TCN'

        # --- Add a type 2 record
        r2 = nistitl.AsciiRecord(2)
        msg += r2
        r2.IDC = 1
        # Add field 2.003, long notation used to specify an alias
        r2 += nistitl.Field(2, 3, alias='TEST')
        # Add field 2.004, with 2 subfields) using the short notation
        r2._4 = ('SF1', 'SF2')

        # --- Add a type 4 record
        r4 = nistitl.BinaryRecord(4)
        msg += r4
        r4.IDC = 2
        # Set all fields in one step, image and headers
        r4.pack("!HH", 500, 500, b'image')

        # --- Add a type 10 record
        r10 = nistitl.AsciiRecord(10)
        msg += r10
        r10.IDC = 3
        # Used pre-defined alias
        r10.SRC = 'my src'
        r10.DATA = b'image'

        # Generate the NIST buffer
        buffer = msg.NIST

        self.assertTrue(len(buffer) > 10)

        # ---------------------------------------------------------------------

        msg = nistitl.Message()
        msg.parse(buffer)

        # --- Access type 2 record
        r2 = msg[(2, 1)]
        # Read field 2.003
        v = r2._3

        # --- Loop on all records of type 4
        for r4 in msg.iter(4):
            # Get all fields
            width, height, data = r4.unpack("!HH")

        # --- Loop on all records of type 10
        for r10 in msg.iter(10):
            # Used pre-defined alias
            src = r10.SRC
            image = r10.DATA
예제 #3
0
    def testGenerate(self):
        msg = nistitl.Message()
        msg.TOT = 'MY_TOT'

        r2 = nistitl.AsciiRecord(2)
        r2 += nistitl.Field(2,3,alias='TEST')
        msg += r2

        buffer = msg.NIST

        self.assertTrue(len(msg.NIST)>10)
        
        msg = nistitl.Message()
        msg.parse(buffer)
        print("The TOT is ",msg.TOT)
        for record in msg.iter(2):
            print("Field 2.003 is ",record._3)
예제 #4
0
    def testMaxSize(self):
        # Bug: syntax error when record length (parsable part) is over 8192
        msg = nistitl.Message()
        msg.TOT = 'TESTMAXSIZE'

        r2 = nistitl.AsciiRecord(2)
        r2.IDC = 1
        msg += r2
        f = nistitl.Field(2,3)
        f.value = [[1234,5678,345,'A']*600] #511]
        r2 += f

        r10 = nistitl.AsciiRecord(10)
        r10.IDC = 2
        msg += r10

        N = msg.NIST
        msg = nistitl.Message()
        msg.parse(N)
예제 #5
0
    def testOK(self):
        msg = nistitl.Message()
        msg.TOT = 'TESTTAGGEDBIN'

        r2 = nistitl.AsciiRecord(2)
        r2.IDC = 1
        msg += r2
        
        r10 = nistitl.AsciiRecord(10)
        r10.IDC = 1
        msg += r10
        
        f = open(IMAGE,'rb')
        buf = f.read()
        f.close()
        f999 = nistitl.BinaryField(10,999,buf)
        r10 += f999

        r10 = nistitl.AsciiRecord(10)
        r10.IDC = 2
        msg += r10
        
        f999 = nistitl.BinaryField(10,999,buf)
        r10 += f999
        
        #f = open('testtaggedbin.nist','wb')
        N = msg.NIST
        #f.write(N)
        #f.close()
        
        # parse the NIST
        msg = nistitl.Message()
        msg.parse(N)
        
        self.assertTrue(buf==msg[(10,1)][999].value)
        self.assertTrue(buf==msg[(10,2)][999].value)
예제 #6
0
    def testOK(self):
        msg = nistitl.Message()
        msg.TOT = 'TESTBIN'

        # Two type 1
        r2 = nistitl.AsciiRecord(1)
        self.assertRaises(NistException,msg.__add__,r2)

        r2 = nistitl.AsciiRecord(2)
        r2 += nistitl.Field(2,3,alias='TT')
        self.assertRaises(NistException,r2.__add__, nistitl.Field(2,3) )
        self.assertRaises(NistException,r2.__add__, nistitl.Field(2,4,alias='TT') )
        self.assertRaises(NistException,r2.__add__, nistitl.Field(3,3) )
        
        f = nistitl.Field(2,99,type='F')
        f.value = "OK"
        self.assertRaises(NistException,f.add_subfields, nistitl.SubField() )
        f = nistitl.Field(2,99,type='FS')
        f.value = "OK"
        f.add_subfields(nistitl.SubField())
        self.assertRaises(NistException,f[0].add_values,"I" )
예제 #7
0
 def testKO(self):
     msg = nistitl.Message()
     self.assertRaises(NistException,msg.parse,NIST_BAD_CNT)
예제 #8
0
 def testOK(self):
     msg = nistitl.Message()
     msg.parse(NIST_OK)
     self.assertTrue(msg.NIST==NIST_OK)