Пример #1
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                            {'ta_info':self.ta_info})
        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
        #prepare data for envelope
        if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
            self.ta_info['reference'] = unicode(botslib.unique('stxcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(botslib.unique('stxcounter_' + self.ta_info['frompartner']))
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({'BOTSID':'STX',
                        'STDS1':self.ta_info['STX.STDS1'],
                        'STDS2':self.ta_info['STX.STDS2'],
                        'FROM.01':self.ta_info['frompartner'],
                        'UNTO.01':self.ta_info['topartner'],
                        'TRDT.01':botslib.strftime('%y%m%d'),
                        'TRDT.02':botslib.strftime('%H%M%S'),
                        'SNRF':self.ta_info['reference']})
        if self.ta_info['STX.FROM.02']:
            self.out.put({'BOTSID':'STX','FROM.02':self.ta_info['STX.FROM.02']})
        if self.ta_info['STX.UNTO.02']:
            self.out.put({'BOTSID':'STX','UNTO.02':self.ta_info['STX.UNTO.02']})
        if self.ta_info['STX.APRF']:
            self.out.put({'BOTSID':'STX','APRF':self.ta_info['STX.APRF']})
        if self.ta_info['STX.PRCD']:
            self.out.put({'BOTSID':'STX','PRCD':self.ta_info['STX.PRCD']})
        self.out.put({'BOTSID':'STX'},{'BOTSID':'END','NMST':self.ta_info['nrmessages']})  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
        #convert the tree into segments; here only the STX is written (first segment)
        self.out.checkmessage(self.out.root,self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)

        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Пример #2
0
 def run(self):
     if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
         raise botslib.OutMessageError(
             _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
               ), {'ta_info': self.ta_info})
     self._openoutenvelope()
     self.ta_info.update(self.out.ta_info)
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'ta_infocontent',
                          ta_info=self.ta_info)
     #prepare data for envelope
     isa09date = botslib.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules.
     if self.ta_info['testindicator'] and self.ta_info[
             'testindicator'] != '0':  #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings',
                                  'interchangecontrolperpartner', False):
         self.ta_info['reference'] = unicode(
             botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = unicode(
             botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     isa06sender = self.ta_info.get('ISA06', self.ta_info['frompartner'])
     isa06sender = isa06sender.ljust(15)  #add spaces; is fixed length
     gs02sender = self.ta_info.get('GS02', self.ta_info['frompartner'])
     #also for ISA08 and GS03
     isa08receiver = self.ta_info.get('ISA08', self.ta_info['topartner'])
     isa08receiver = isa08receiver.ljust(15)  #add spaces; is fixed length
     gs03receiver = self.ta_info.get('GS03', self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put(
         {
             'BOTSID': 'ISA',
             'ISA01': self.ta_info['ISA01'],
             'ISA02': self.ta_info['ISA02'],
             'ISA03': self.ta_info['ISA03'],
             'ISA04': self.ta_info['ISA04'],
             'ISA05': self.ta_info['ISA05'],
             'ISA06': isa06sender,
             'ISA07': self.ta_info['ISA07'],
             'ISA08': isa08receiver,
             'ISA09': isa09date,
             'ISA10': botslib.strftime('%H%M'),
             'ISA11': self.ta_info[
                 'ISA11'],  #if ISA version > 00403, replaced by reprtion separator
             'ISA12': self.ta_info['version'],
             'ISA13': self.ta_info['reference'],
             'ISA14': self.ta_info['ISA14'],
             'ISA15': testindicator
         },
         strip=False
     )  #MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'IEA',
         'IEA01': '1',
         'IEA02': self.ta_info['reference']
     })
     gs08messagetype = self.ta_info['messagetype'][3:]
     if gs08messagetype[:6] < '004010':
         gs04date = botslib.strftime('%y%m%d')
     else:
         gs04date = botslib.strftime('%Y%m%d')
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'GS',
         'GS01': self.ta_info['functionalgroup'],
         'GS02': gs02sender,
         'GS03': gs03receiver,
         'GS04': gs04date,
         'GS05': botslib.strftime('%H%M'),
         'GS06': self.ta_info['reference'],
         'GS07': self.ta_info['GS07'],
         'GS08': gs08messagetype
     })
     self.out.put({'BOTSID': 'ISA'}, {'BOTSID': 'GS'}, {
         'BOTSID': 'GE',
         'GE01': self.ta_info['nrmessages'],
         'GE02': self.ta_info['reference']
     })  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'envelopecontent',
                          ta_info=self.ta_info,
                          out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.checkmessage(self.out.root, self.out.defmessage)
     self.out.checkforerrorlist()
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                               self.ta_info['charset'])
     isa_string = self.out.record2string(self.out.lex_records[0:1])
     #ISA has the used separators at certain positions. Normally bots would give errors for this (can not use sep as data) or compress these aways. So this is hardcoded.
     if self.ta_info['version'] < '00403':
         isa_string = isa_string[:103] + self.ta_info[
             'field_sep'] + self.ta_info['sfield_sep'] + isa_string[103:]
     else:
         isa_string = isa_string[:82] + self.ta_info[
             'reserve'] + isa_string[83:103] + self.ta_info[
                 'field_sep'] + self.ta_info['sfield_sep'] + isa_string[103:]
     tofile.write(isa_string)  #write ISA
     tofile.write(self.out.record2string(
         self.out.lex_records[1:2]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out.record2string(
         self.out.lex_records[2:]))  #write GE and IEA
     tofile.close()
Пример #3
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
                  ), {'ta_info': self.ta_info})
        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'ta_infocontent',
                             ta_info=self.ta_info)
        #prepare data for envelope
        if botsglobal.ini.getboolean('settings',
                                     'interchangecontrolperpartner', False):
            self.ta_info['reference'] = unicode(
                botslib.unique('stxcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(
                botslib.unique('stxcounter_' + self.ta_info['frompartner']))
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({
            'BOTSID': 'STX',
            'STDS1': self.ta_info['STX.STDS1'],
            'STDS2': self.ta_info['STX.STDS2'],
            'FROM.01': self.ta_info['frompartner'],
            'UNTO.01': self.ta_info['topartner'],
            'TRDT.01': botslib.strftime('%y%m%d'),
            'TRDT.02': botslib.strftime('%H%M%S'),
            'SNRF': self.ta_info['reference']
        })
        if self.ta_info['STX.FROM.02']:
            self.out.put({
                'BOTSID': 'STX',
                'FROM.02': self.ta_info['STX.FROM.02']
            })
        if self.ta_info['STX.UNTO.02']:
            self.out.put({
                'BOTSID': 'STX',
                'UNTO.02': self.ta_info['STX.UNTO.02']
            })
        if self.ta_info['STX.APRF']:
            self.out.put({'BOTSID': 'STX', 'APRF': self.ta_info['STX.APRF']})
        if self.ta_info['STX.PRCD']:
            self.out.put({'BOTSID': 'STX', 'PRCD': self.ta_info['STX.PRCD']})
        self.out.put({'BOTSID': 'STX'}, {
            'BOTSID': 'END',
            'NMST': self.ta_info['nrmessages']
        })  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'envelopecontent',
                             ta_info=self.ta_info,
                             out=self.out)
        #convert the tree into segments; here only the STX is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)

        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                                  self.ta_info['charset'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Пример #4
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
                  ), {'ta_info': self.ta_info})

        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'ta_infocontent',
                             ta_info=self.ta_info)

        #version dependent enveloping
        if self.ta_info['version'] < '4':
            date = botslib.strftime('%y%m%d')
            reserve = ' '
        else:
            date = botslib.strftime('%Y%m%d')
            reserve = self.ta_info['reserve']

        #UNB reference is counter is per sender or receiver
        if botsglobal.ini.getboolean('settings',
                                     'interchangecontrolperpartner', False):
            self.ta_info['reference'] = unicode(
                botslib.unique('unbcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(
                botslib.unique('unbcounter_' + self.ta_info['frompartner']))
        #testindicator is more complex:
        if self.ta_info['testindicator'] and self.ta_info[
                'testindicator'] != '0':  #first check value from ta; do not use default
            testindicator = '1'
        elif self.ta_info['UNB.0035'] != '0':  #than check values from grammar
            testindicator = '1'
        else:
            testindicator = ''
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({
            'BOTSID': 'UNB',
            'S001.0001': self.ta_info['charset'],
            'S001.0002': self.ta_info['version'],
            'S002.0004': self.ta_info['frompartner'],
            'S003.0010': self.ta_info['topartner'],
            'S004.0017': date,
            'S004.0019': botslib.strftime('%H%M'),
            '0020': self.ta_info['reference']
        })
        #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        for field in ('S001.0080', 'S001.0133', 'S002.0007', 'S002.0008',
                      'S002.0042', 'S003.0007', 'S003.0014', 'S003.0046',
                      'S005.0022', 'S005.0025', '0026', '0029', '0031',
                      '0032'):
            if self.ta_info['UNB.' + field]:
                self.out.put({
                    'BOTSID': 'UNB',
                    field: self.ta_info['UNB.' + field]
                })
        if testindicator:
            self.out.put({'BOTSID': 'UNB', '0035': testindicator})
        self.out.put({'BOTSID': 'UNB'}, {
            'BOTSID': 'UNZ',
            '0036': self.ta_info['nrmessages'],
            '0020': self.ta_info['reference']
        })  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'envelopecontent',
                             ta_info=self.ta_info,
                             out=self.out)
        #convert the tree into segments; here only the UNB is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)
        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                                  self.ta_info['charset'])
        if self.ta_info['forceUNA'] or self.ta_info['charset'] != 'UNOA':
            tofile.write('UNA' + self.ta_info['sfield_sep'] +
                         self.ta_info['field_sep'] + self.ta_info['decimaal'] +
                         self.ta_info['escape'] + reserve +
                         self.ta_info['record_sep'] +
                         self.ta_info['add_crlfafterrecord_sep'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Пример #5
0
 def run(self):
     if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
         raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                         {'ta_info':self.ta_info})
     self._openoutenvelope()
     self.ta_info.update(self.out.ta_info)
     botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
     #prepare data for envelope
     isa09date = botslib.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules.
     if self.ta_info['testindicator'] and self.ta_info['testindicator'] != '0':    #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
         self.ta_info['reference'] = unicode(botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = unicode(botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     isa06sender = self.ta_info.get('ISA06',self.ta_info['frompartner'])
     isa06sender = isa06sender.ljust(15)    #add spaces; is fixed length
     gs02sender = self.ta_info.get('GS02',self.ta_info['frompartner'])
     #also for ISA08 and GS03
     isa08receiver = self.ta_info.get('ISA08',self.ta_info['topartner'])
     isa08receiver = isa08receiver.ljust(15)    #add spaces; is fixed length
     gs03receiver = self.ta_info.get('GS03',self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put({'BOTSID':'ISA',
                     'ISA01':self.ta_info['ISA01'],
                     'ISA02':self.ta_info['ISA02'],
                     'ISA03':self.ta_info['ISA03'],
                     'ISA04':self.ta_info['ISA04'],
                     'ISA05':self.ta_info['ISA05'],
                     'ISA06':isa06sender,
                     'ISA07':self.ta_info['ISA07'],
                     'ISA08':isa08receiver,
                     'ISA09':isa09date,
                     'ISA10':botslib.strftime('%H%M'),
                     'ISA11':self.ta_info['ISA11'],      #if ISA version > 00403, replaced by reprtion separator
                     'ISA12':self.ta_info['version'],
                     'ISA13':self.ta_info['reference'],
                     'ISA14':self.ta_info['ISA14'],
                     'ISA15':testindicator},strip=False)         #MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'IEA','IEA01':'1','IEA02':self.ta_info['reference']})
     gs08messagetype = self.ta_info['messagetype'][3:]
     if gs08messagetype[:6] < '004010':
         gs04date = botslib.strftime('%y%m%d')
     else:
         gs04date = botslib.strftime('%Y%m%d')
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS',
                                     'GS01':self.ta_info['functionalgroup'],
                                     'GS02':gs02sender,
                                     'GS03':gs03receiver,
                                     'GS04':gs04date,
                                     'GS05':botslib.strftime('%H%M'),
                                     'GS06':self.ta_info['reference'],
                                     'GS07':self.ta_info['GS07'],
                                     'GS08':gs08messagetype})
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS'},{'BOTSID':'GE','GE01':self.ta_info['nrmessages'],'GE02':self.ta_info['reference']})  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.checkmessage(self.out.root,self.out.defmessage)
     self.out.checkforerrorlist()
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
     isa_string = self.out.record2string(self.out.lex_records[0:1])
     #ISA has the used separators at certain positions. Normally bots would give errors for this (can not use sep as data) or compress these aways. So this is hardcoded.
     if self.ta_info['version'] < '00403':
         isa_string = isa_string[:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + isa_string[103:] 
     else:
         isa_string = isa_string[:82] +self.ta_info['reserve'] + isa_string[83:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + isa_string[103:]
     tofile.write(isa_string)                                     #write ISA
     tofile.write(self.out.record2string(self.out.lex_records[1:2]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out.record2string(self.out.lex_records[2:])) #write GE and IEA
     tofile.close()
Пример #6
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                            {'ta_info':self.ta_info})

        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)

        #version dependent enveloping
        if self.ta_info['version'] < '4':
            date = botslib.strftime('%y%m%d')
            reserve = ' '
        else:
            date = botslib.strftime('%Y%m%d')
            reserve = self.ta_info['reserve']

        #UNB reference is counter is per sender or receiver
        if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
            self.ta_info['reference'] = unicode(botslib.unique('unbcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(botslib.unique('unbcounter_' + self.ta_info['frompartner']))
        #testindicator is more complex:
        if self.ta_info['testindicator'] and self.ta_info['testindicator'] != '0':    #first check value from ta; do not use default
            testindicator = '1'
        elif self.ta_info['UNB.0035'] != '0':   #than check values from grammar
            testindicator = '1'
        else:
            testindicator = ''
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({'BOTSID':'UNB',
                        'S001.0001':self.ta_info['charset'],
                        'S001.0002':self.ta_info['version'],
                        'S002.0004':self.ta_info['frompartner'],
                        'S003.0010':self.ta_info['topartner'],
                        'S004.0017':date,
                        'S004.0019':botslib.strftime('%H%M'),
                        '0020':self.ta_info['reference']})
        #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        for field in ('S001.0080','S001.0133','S002.0007','S002.0008','S002.0042',
                      'S003.0007','S003.0014','S003.0046','S005.0022','S005.0025',
                      '0026','0029','0031','0032'):
            if self.ta_info['UNB.'+field]:
                self.out.put({'BOTSID':'UNB',field:self.ta_info['UNB.'+field]})
        if testindicator:
            self.out.put({'BOTSID':'UNB','0035': testindicator})
        self.out.put({'BOTSID':'UNB'},{'BOTSID':'UNZ','0036':self.ta_info['nrmessages'],'0020':self.ta_info['reference']})  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
        #convert the tree into segments; here only the UNB is written (first segment)
        self.out.checkmessage(self.out.root,self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)
        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
        if self.ta_info['forceUNA'] or self.ta_info['charset'] != 'UNOA':
            tofile.write('UNA'+self.ta_info['sfield_sep']+self.ta_info['field_sep']+self.ta_info['decimaal']+self.ta_info['escape']+ reserve +self.ta_info['record_sep']+self.ta_info['add_crlfafterrecord_sep'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()