Beispiel #1
0
def storeone(country, text):
    "store one record with the country and the text related to the country"

    wwl = len(text)
    udh.country = country
    udh.declen = wwl
    udh.declaration = text

    c1.rabd.send = 32 + 4 + wwl  # set send size for record buffer
    try:
        c1.store()  # issue N1
        print '%s stored, ISN %d, size %d' % (country, c1.cb.isn, wwl)
        c1.et()  # end of transaction
    except DatabaseError, (line, apa):
        print line
        dump.dump(apa.rb, header='Record Buffer')
        dump.dump(apa.acbx, header='Control Block')
        print "Skipping country", country
        x = raw_input("Press enter to continue")
        pass
Beispiel #2
0
try:
    # print Adabas call buffers before and after
    c1.cb.dbid = DBID  # for ACBX; c1.dbid=DBID for ACB
    c1.cb.fnr = FNR  # set control block fields

    c1.open(mode=UPD)  # issue OP

    c1.cb.cid = 'abcd'
    c1.cb.isn = 0
    c1.fb.value = FB  # put data into format buffer
    c1.rb.value = 'AACDEFGE'  # ..            record buffer
    c1.rabd.send = 8  # set send size for record buffer

    c1.store()  # issue N1

    c1.rb.value = ' ' * 8  # reset rb
    # c1.rabd.send=0        # send size zero!
    c1.rabd.send = 8  # send size !

    c1.get()  # issue L1

    print repr(c1.rb.value), 'returned size', c1.rabd.recv

    c1.bt()  # issue backout
    c1.close()  # issue close

except DatabaseError, (line, apa):
    print line
    dump.dump(apa.acbx, header='Control Block')
    raise
Beispiel #3
0
      '\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf',
      '\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf',
      '\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf',
      '\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf',
      '\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef',
      '\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')

tbuf = Abuf(256)
ebuf = Abuf(256)
abuf = Abuf(256)

for t in tt:
    tbuf.write(t)

ebuf[0:256] = tbuf[0:256]

conv.asc2ebc(ebuf, 0, len(ebuf))

abuf[0:256] = ebuf[0:256]
conv.ebc2asc(abuf, 0, len(abuf))

print 'tbuf has characters from 0 to 255'
dump.dump(tbuf, header='tbuf')
print 'ebuf is contents after asc2ebc() call'
dump.dump(ebuf, header='ebuf')
print 'abuf is contents after ebc2asc() call'
dump.dump(abuf, header='abuf')

print "str2ebc('ABC'):         ", repr(conv.str2ebc('ABC'))
print "str2asc('\\xC1\\xC2\\xC3'):", repr(conv.str2asc('\xC1\xC2\xC3'))
Beispiel #4
0
        if 'UTF8' in v:
            utext = z.read(UPREFIX + k + '-UTF8')
            storeone(k, utext)
        elif 'UFT8' in v:
            utext = z.read(UPREFIX + k + '-UFT8')
            storeone(k, utext)
        elif 'Latin1' in v:
            utext = z.read(UPREFIX + k + '-Latin1')
            storeone(k, utext.decode('latin1', 'replace').encode('utf8'))
        elif 'Latin2' in v:
            utext = z.read(UPREFIX + k + '-Latin2')
            storeone(k, utext.decode('latin2', 'replace').encode('utf8'))
        elif 'Arabic' in v:
            utext = z.read(UPREFIX + k + '-Arabic')
            storeone(k + '-cp1256',
                     utext.decode('cp1256', 'replace').encode('utf8'))
        else:
            print 'unhandled:', k, v

    z.close()  # zipfile close
    c1.close()  # database close

except DatabaseError, (line, apa):
    print line
    dump.dump(apa.acbx, header='Control Block')
    dump.dump(apa.rb, header='Recor Buffer')
    c1.close()
    raise
except:
    c1.close()
Beispiel #5
0
def select(req, name='', dbid=str(DBID), fnr=str(FNR), isn='0', acbx='0'):

    lines = ''
    extraline = ''
    ACBX = 0
    if acbx != '0':
        ACBX = 1

    try:
        if ACBX:
            c1 = Adabasx(fbl=64, sbl=3, vbl=32,
                         rbl=RBL)  # allocate set of buffers ACBX,
            c1.acb = c1.acbx
        else:
            c1 = Adabas(fbl=64, sbl=3, vbl=32,
                        rbl=RBL)  # allocate set of buffers ACBX,
            # abd+format and record buffer
        c1.cb.dbid = int(dbid)

        c1.open(wcharset='UTF-8')  # issue OP

        c1.cb.fnr = int(fnr)
        c1.cb.cid = '1019'

        c1.fb.value = FB
        if ACBX:
            c1.fabd.send = len(FB)

        udh = Datamap(
            'udhr_record',
            String('language', 32),
            Int4('declen'),
            String('decla', RBL - 36),  # stored in UTF-8
            buffer=c1.rb)

        if name != '':
            c1.searchfield('AA.', 32, name.capitalize())
            if ACBX:
                c1.sabd.send = 3
                c1.vabd.send = 32

            c1.read(descriptor='AA')
        else:
            c1.getiseq(isn=int(isn))

        language = udh.language
        wwl = udh.declen

        # if c1.rabd.recv > 0:
        if 1:
            if 0:
                req.write(repr(wwl))
                req.write(language)
                f = cStringIO.StringIO()
                dump.dump(c1.acb, header='Control Block', fd=f)
                dump.dump(c1.rb, header='Record Buffer', fd=f)
                f.seek(0)
                req.write('<pre>' + f.read() + '</pre>')

            c1.rb.seek(32 + 4)
            lines = cStringIO.StringIO()
            lines.write(c1.rb.read(wwl))
            lines.seek(0)
            text = '<p></p>'.join(lines.readlines())
            #for line in lines.readlines():
            #    text+='<p></p>'+line

            #?? text=udh.decla #  [0:wwl]
            # ValueError: Can only assign sequence of same size

        else:
            text = '<p></p>no data found'

        xrtl = ''
        if test_rtl(text):
            # right-to-left language: align to right <text>
            xrtl = 'class="rtl"'

        lines = '<p></p><em>%s</em> textsize=%d<p></p><div %s>%s</div>' % (
            language, wwl, xrtl, text)

        c1.close()

    except DatabaseError, (line, apa):
        extraline += 'Database Error dbid=%d, fnr=%d, reading language %s:' % (
            apa.cb.dbid, apa.cb.fnr, name) + line

        f = cStringIO.StringIO()
        dump.dump(apa.acb, header='Control Block', fd=f)
        dump.dump(apa.fb, header='Format Buffer', fd=f)
        dump.dump(apa.sb, header='Search Buffer', fd=f)
        dump.dump(apa.vb, header='Value Buffer', fd=f)
        f.seek(0)
        extraline += '<pre>' + f.read() + '</pre>'
        apa.close()
Beispiel #6
0
def browse(req,
           name='',
           dbid=str(DBID),
           fnr=str(FNR),
           maxlines=str(20),
           dbug=''):

    lines = [
        stable1,
    ]
    extraline = ''
    f = cStringIO.StringIO()

    try:
        c1 = Adabas(fbl=64, sbl=3, vbl=32,
                    rbl=112)  # allocate set of buffers ACBX,
        # abd+format and record buffer
        c1.cb.dbid = int(dbid)

        c1.open(wcharset='UTF-8')  # issue OP

        c1.cb.fnr = int(fnr)
        c1.cb.cid = '1020'

        c1.fb.value = FBB

        udh = Datamap(
            'udhr_record',
            String('language', 32),
            String('decla', 80),  # stored in UTF-8
            buffer=c1.rb)

        c1.searchfield('AA.', 32, name.capitalize())

        for linum in range(int(maxlines)):

            c1.read(descriptor='AA')

            language = udh.language

            if dbug == '1':
                print language >> f
                dump.dump(c1.acb, header='Control Block', fd=f)
                dump.dump(c1.fb, header='Format Buffer', fd=f)
                dump.dump(c1.rb, header='Record Buffer', fd=f)
                dump.dump(c1.sb, header='Search Buffer', fd=f)
                dump.dump(c1.vb, header='Value Buffer', fd=f)

            texts = cStringIO.StringIO()
            texts.write(udh.decla)
            texts.seek(0)
            text = texts.readline().strip()  # read one line, strip new line

            if linum % 2:
                altx = 'class="altline"'
            else:
                altx = 'class="wline"'  # alternate for between 2 lines

            lines.append(sline % (altx, thisfile, c1.cb.isn, language, text))

        c1.close()

    except DatabaseError, (line, apa):
        f.write('Database Error dbid=%d, fnr=%d, reading language %s:' %
                (apa.cb.dbid, apa.cb.fnr, name) + line)

        dump.dump(apa.acb, header='Control Block', fd=f)
        dump.dump(apa.fb, header='Format Buffer', fd=f)
        dump.dump(apa.sb, header='Search Buffer', fd=f)
        dump.dump(apa.vb, header='Value Buffer', fd=f)
        # apa.close()
        pass
Beispiel #7
0
def select(req, name='', dbid=str(DBID), fnr=str(FNR), isn='0', acbx='0'):

    lines = ''
    extraline = ''
    ACBX = 0
    if acbx != '0':
        ACBX = 1

    try:
        if ACBX:
            c1 = Adabasx(fbl=64, sbl=3, vbl=32,
                         rbl=RBL)  # allocate set of buffers ACBX,
            c1.acb = c1.acbx
        else:
            c1 = Adabas(fbl=64, sbl=3, vbl=32,
                        rbl=RBL)  # allocate set of buffers ACBX,
            # abd+format and record buffer
        c1.cb.dbid = int(dbid)

        c1.open()  # issue OP

        c1.cb.fnr = int(fnr)
        c1.cb.cid = '1019'

        c1.fb.value = FB
        if ACBX:
            c1.fabd.send = len(FB)

        udh = Datamap(
            'udhr_record',
            String('language', 32),
            Unicode('decla', RBL - 32),  # stored in Unicode
            buffer=c1.rb)

        if name != '':
            c1.searchfield('AA.', 32, name.capitalize())
            if ACBX:
                c1.sabd.send = 3
                c1.vabd.send = 32

            c1.read(descriptor='AA')
        else:
            c1.getiseq(isn=int(isn))

        language = udh.language

        c1.rb.seek(32 + 4)
        lines = cStringIO.StringIO()
        lines.write(udh.decla.encode('utf8'))
        lines.seek(0)
        text = '<p></p>'.join(lines.readlines())

        xrtl = ''
        if test_rtl(text):
            # right-to-left language: align to right <text>
            xrtl = 'class="rtl"'

        lines = '<p></p><em>%s</em><p></p><div %s>%s</div>' % (language, xrtl,
                                                               text)

        c1.close()

    except DatabaseError, (line, apa):
        extraline += 'Database Error dbid=%d, fnr=%d, reading language %s:' % (
            apa.cb.dbid, apa.cb.fnr, name) + line

        f = cStringIO.StringIO()
        dump.dump(apa.acb, header='Control Block', fd=f)
        dump.dump(apa.fb, header='Format Buffer', fd=f)
        dump.dump(apa.sb, header='Search Buffer', fd=f)
        dump.dump(apa.vb, header='Value Buffer', fd=f)
        f.seek(0)
        extraline += '<pre>' + f.read() + '</pre>'
        apa.close()