Package pyx12 :: Module error_handler
[hide private]

Source Code for Module pyx12.error_handler

   1  ###################################################################### 
   2  # Copyright (c) 2001-2005 Kalamazoo Community Mental Health Services, 
   3  #   John Holland <jholland@kazoocmh.org> <john@zoner.org> 
   4  # All rights reserved. 
   5  # 
   6  # This software is licensed as described in the file LICENSE.txt, which 
   7  # you should have received as part of this distribution. 
   8  # 
   9  ###################################################################### 
  10   
  11  #    $Id: error_handler.py 961 2007-03-23 21:35:20Z johnholland $ 
  12   
  13  """ 
  14  Interface to X12 Errors 
  15  """ 
  16   
  17  import logging 
  18  from types import * 
  19  #import pdb 
  20   
  21  # Intrapackage imports 
  22  from errors import * 
  23   
  24  #class error_node: 
  25  #    def __init__(self) 
  26   
  27  logger = logging.getLogger('pyx12.error_handler') 
  28  #logger.setLevel(logging.DEBUG) 
  29  #logger.setLevel(logging.ERROR) 
  30   
31 -class err_iter(object):
32 - def __init__(self, errh):
33 """ 34 @param errh: Error_handler instance 35 @type errh: L{error_handler.err_handler} 36 """ 37 self.errh = errh 38 self.cur_node = errh 39 #self.done = False 40 self.visit_stack = []
41
42 - def first(self):
43 self.cur_node = self.errh
44
45 - def next(self):
46 #pdb.set_trace() 47 #orig_node = self.cur_node 48 49 #If at previosly visited branch, do not do children 50 if self.cur_node in self.visit_stack: 51 node = None 52 else: 53 node = self.cur_node.get_first_child() 54 if node is not None: 55 self.visit_stack.append(self.cur_node) 56 self.cur_node = node 57 else: 58 node = self.cur_node.get_next_sibling() 59 if node is not None: 60 self.cur_node = node 61 else: 62 if not self.cur_node.is_closed(): 63 raise IterOutOfBounds 64 #pdb.set_trace() 65 node = self.cur_node.get_parent() 66 if node is None: 67 raise IterOutOfBounds 68 #if node.get_cur_line() < self.src.cur_line: 69 if not node.is_closed(): 70 raise IterOutOfBounds 71 if self.cur_node in self.visit_stack: 72 del self.visit_stack[-1] 73 self.cur_node = node 74 #logger.debug(node) 75 if node.id == 'ROOT': 76 raise IterOutOfBounds
77 # raise IterDone 78
79 - def next_old(self):
80 #pdb.set_trace() 81 start_line = self.cur_node.get_cur_line() 82 orig_node = self.cur_node 83 if self.done: 84 raise EngineError, 'Iterator was completed' 85 try: 86 self.cur_node = self.cur_node.get_first_child() 87 except IterOutOfBounds: 88 while not self.done: 89 try: 90 self.cur_node = self.cur_node.get_next_sibling() 91 break 92 except IterOutOfBounds: 93 self.cur_node = self.cur_node.get_parent() 94 break 95 except IterDone: 96 self.done = True 97 if self.cur_node.get_cur_line() < start_line: 98 self.cur_node = orig_node 99 self.done = False 100 raise IterOutOfBounds
101
102 - def get_cur_node(self):
103 return self.cur_node
104 105 # def is_done(self): 106 # return self.done 107 108 109
110 -class err_handler(object):
111 """ 112 The interface to the error handling structures. 113 """
114 - def __init__(self):
115 """ 116 """ 117 118 self.id = 'ROOT' 119 #self.isa_loop_count = 0 120 self.children = [] 121 self.cur_node = self 122 self.cur_isa_node = None 123 self.cur_gs_node = None 124 self.cur_st_node = None 125 self.cur_seg_node = None 126 self.seg_node_added = False 127 self.cur_ele_node = None 128 self.cur_line = 0
129
130 - def accept(self, visitor):
131 """ 132 Params: visitor - ref to visitor class 133 """ 134 visitor.visit_root_pre(self) 135 for child in self.children: 136 child.accept(visitor) 137 visitor.visit_root_post(self)
138
139 - def handle_errors(self, err_list):
140 """ 141 @param err_list: list of errors to apply 142 """ 143 for (err_type, err_cde, err_str, err_val, src_line) in err_list: 144 if err_type == 'isa': 145 self.isa_error(err_cde, err_str) 146 elif err_type == 'gs': 147 self.gs_error(err_cde, err_str) 148 elif err_type == 'st': 149 self.st_error(err_cde, err_str) 150 elif err_type == 'seg': 151 self.seg_error(err_cde, err_str, err_val, src_line)
152
153 - def get_cur_line(self):
154 """ 155 @return: Current file line number 156 @rtype: int 157 """ 158 return self.cur_line
159
160 - def get_id(self):
161 """ 162 """ 163 return self.id
164
165 - def add_isa_loop(self, seg_data, src):
166 """ 167 @param seg_data: Segment object 168 @type seg_data: L{segment<segment.Segment>} 169 """ 170 #logger.debug('add_isa loop') 171 self.children.append(err_isa(self, seg_data, src)) 172 self.cur_isa_node = self.children[-1] 173 self.cur_seg_node = self.cur_isa_node 174 self.seg_node_added = True
175
176 - def add_gs_loop(self, seg_data, src):
177 """ 178 @param seg_data: Segment object 179 @type seg_data: L{segment<segment.Segment>} 180 """ 181 #logger.debug('add_gs loop') 182 parent = self.cur_isa_node 183 parent.children.append(err_gs(parent, seg_data, src)) 184 self.cur_gs_node = parent.children[-1] 185 self.cur_seg_node = self.cur_gs_node 186 self.seg_node_added = True
187
188 - def add_st_loop(self, seg_data, src):
189 """ 190 @param seg_data: Segment object 191 @type seg_data: L{segment<segment.Segment>} 192 """ 193 #logger.debug('add_st loop') 194 parent = self.cur_gs_node 195 parent.children.append(err_st(parent, seg_data, src)) 196 self.cur_st_node = parent.children[-1] 197 self.cur_seg_node = self.cur_st_node 198 self.seg_node_added = True
199
200 - def add_seg(self, map_node, seg_data, seg_count, cur_line, ls_id):
201 """ 202 @param map_node: current segment node 203 @type map_node: L{node<map_if.segment_if>} 204 @param seg_data: Segment object 205 @type seg_data: L{segment<segment.Segment>} 206 @param seg_count: Count of current segment in the ST Loop 207 @type seg_count: int 208 @param cur_line: Current line number in the file 209 @type cur_line: int 210 @param ls_id: The current LS loop identifier 211 @type ls_id: string 212 """ 213 parent = self.cur_st_node 214 self.cur_seg_node = err_seg(parent, map_node, seg_data, seg_count, cur_line, ls_id) 215 self.seg_node_added = False
216 #logger.debug('add_seg: %s' % map_node.name) 217 #if len(parent.children) > 0: 218 # if parent.children[-1].err_count() == 0: 219 # del parent.children[-1] 220 # logger.debug('del seg_data: %s' % map_node.name) 221 #parent.children.append(err_seg(parent, map_node, seg_data, src)) 222
223 - def _add_cur_seg(self):
224 """ 225 """ 226 #pdb.set_trace() 227 if not self.seg_node_added: 228 self.cur_st_node.children.append(self.cur_seg_node) 229 self.seg_node_added = True
230
231 - def add_ele(self, map_node):
232 """ 233 """ 234 if self.cur_seg_node.id == 'ISA': 235 self.cur_ele_node = err_ele(self.cur_isa_node, map_node) 236 elif self.cur_seg_node.id == 'GS': 237 self.cur_ele_node = err_ele(self.cur_gs_node, map_node) 238 elif self.cur_seg_node.id == 'ST': 239 self.cur_ele_node = err_ele(self.cur_st_node, map_node) 240 else: 241 self.cur_ele_node = err_ele(self.cur_seg_node, map_node) 242 self.ele_node_added = False
243
244 - def _add_cur_ele(self):
245 """ 246 """ 247 self._add_cur_seg() 248 if not self.ele_node_added and self.cur_seg_node is not None: 249 self.cur_seg_node.elements.append(self.cur_ele_node) 250 self.ele_node_added = True
251 #logger.debug('---- add_ele: %s' % self.cur_seg_node.elements[-1].name) 252
253 - def isa_error(self, err_cde, err_str):
254 """ 255 @param err_cde: ISA level error code 256 @type err_cde: string 257 @param err_str: Description of the error 258 @type err_str: string 259 """ 260 sout = '' 261 sout += 'Line:%i ' % (self.cur_isa_node.get_cur_line()) 262 sout += 'ISA:%s - %s' % (err_cde, err_str) 263 logger.error(sout) 264 self.cur_isa_node.add_error(err_cde, err_str)
265
266 - def gs_error(self, err_cde, err_str):
267 """ 268 @param err_cde: GS level error code 269 @type err_cde: string 270 @param err_str: Description of the error 271 @type err_str: string 272 """ 273 sout = '' 274 sout += 'Line:%i ' % (self.cur_gs_node.get_cur_line()) 275 sout += 'GS:%s - %s' % (err_cde, err_str) 276 logger.error(sout) 277 self.cur_gs_node.add_error(err_cde, err_str)
278
279 - def st_error(self, err_cde, err_str):
280 """ 281 @param err_cde: Segment level error code 282 @type err_cde: string 283 @param err_str: Description of the error 284 @type err_str: string 285 """ 286 sout = '' 287 sout += 'Line:%i ' % (self.cur_st_node.get_cur_line()) 288 sout += 'ST:%s - %s' % (err_cde, err_str) 289 logger.error(sout) 290 self.cur_st_node.add_error(err_cde, err_str)
291
292 - def seg_error(self, err_cde, err_str, err_value=None, src_line=None):
293 """ 294 @param err_cde: Segment level error code 295 @type err_cde: string 296 @param err_str: Description of the error 297 @type err_str: string 298 """ 299 self._add_cur_seg() 300 self.cur_seg_node.add_error(err_cde, err_str, err_value) 301 sout = '' 302 if src_line: 303 sout += 'Line:%i ' % (src_line) 304 else: 305 sout += 'Line:%i ' % (self.cur_seg_node.get_cur_line()) 306 sout += 'SEG:%s - %s' % (err_cde, err_str) 307 if err_value: 308 sout += ' (%s)' % err_value 309 logger.error(sout)
310
311 - def ele_error(self, err_cde, err_str, bad_value):
312 """ 313 @param err_cde: Element level error code 314 @type err_cde: string 315 @param err_str: Description of the error 316 @type err_str: string 317 """ 318 self._add_cur_ele() 319 self.cur_ele_node.add_error(err_cde, err_str, bad_value) #, pos, data_ele) 320 sout = '' 321 sout += 'Line:%i ' % (self.cur_seg_node.get_cur_line()) 322 sout += 'ELE:%s - %s' % (err_cde, err_str) 323 if bad_value: 324 sout += ' (%s)' % (bad_value) 325 logger.error(sout)
326 #print self.cur_ele_node.errors 327
328 - def close_isa_loop(self, node, seg, src):
329 """ 330 """ 331 self.cur_isa_node.close(node, seg, src) 332 self.cur_seg_node = self.cur_isa_node 333 self.seg_node_added = True
334
335 - def close_gs_loop(self, node, seg, src):
336 """ 337 """ 338 self.cur_gs_node.close(node, seg, src) 339 self.cur_seg_node = self.cur_gs_node 340 self.seg_node_added = True
341
342 - def close_st_loop(self, node, seg, src):
343 """ 344 """ 345 self.cur_st_node.close(node, seg, src) 346 self.cur_seg_node = self.cur_st_node 347 self.seg_node_added = True
348
349 - def find_node(self, type):
350 """ 351 Find the last node of a type 352 """ 353 new_node = self.cur_node 354 node_order = {'ROOT': 1, 'ISA': 2, 'GS': 3, 'ST': 4, 'SEG': 5, 'ELE': 6} 355 while node_order[type] > new_node[new_node.get_id()]: 356 new_node = new_node.get_parent()
357 #walk error tree to find place to append 358 #if type == 'ISA': 359 #return node 360 361 # def update_node(self, obj): 362 # self.children[-1].update_node(obj) 363
364 - def _get_last_child(self):
365 """ 366 """ 367 if len(self.children) != 0: 368 return self.children[-1] 369 else: 370 return None
371
372 - def get_parent(self):
373 return None
374
375 - def get_error_count(self):
376 """ 377 """ 378 count = 0 379 for child in self.children: 380 count += child.get_error_count() 381 return count
382
383 - def get_first_child(self):
384 """ 385 """ 386 if len(self.children) > 0: 387 return self.children[0] 388 else: 389 return None
390
391 - def get_next_sibling(self):
392 """ 393 """ 394 return None
395 #raise IterDone 396
397 - def next(self):
398 """ 399 Return the next error node 400 """ 401 for child in self.children: 402 yield child
403
404 - def is_closed(self):
405 """ 406 @rtype: boolean 407 """ 408 return True
409
410 - def __repr__(self):
411 """ 412 """ 413 return '%i: %s' % (-1, self.id)
414 415
416 -class err_node(object):
417 - def __init__(self, parent):
418 """ 419 """ 420 self.parent = parent 421 self.id = None 422 self.children = [] 423 self.cur_line = -1 424 self.errors = []
425
426 - def accept(self, visitor):
427 """ 428 """ 429 pass
430 431 # def update_node(self, obj): 432 # pass 433
434 - def get_cur_line(self):
435 """ 436 @return: Current file line number 437 @rtype: int 438 """ 439 return self.cur_line
440
441 - def get_id(self):
442 """ 443 """ 444 return self.id
445
446 - def get_parent(self):
447 """ 448 """ 449 return self.parent
450
451 - def _get_last_child(self):
452 """ 453 """ 454 if len(self.children) != 0: 455 return self.children[-1] 456 else: 457 return None
458
459 - def get_next_sibling(self):
460 """ 461 """ 462 #if self.id == 'ROOT': raise EngineError 463 bFound = False 464 for sibling in self.parent.children: 465 if bFound: 466 return sibling 467 if sibling is self: 468 bFound = True 469 return None
470 #raise IterOutOfBounds 471
472 - def get_first_child(self):
473 """ 474 """ 475 if len(self.children) > 0: 476 return self.children[0] 477 else: 478 return None
479
480 - def get_error_count(self):
481 """ 482 """ 483 count = 0 484 for child in self.children: 485 count += child.get_error_count() 486 return count
487
488 - def get_error_list(self, seg_id, pre=False):
489 """ 490 """ 491 return self.errors
492
493 - def is_closed(self):
494 """ 495 @rtype: boolean 496 """ 497 return True
498
499 -class err_isa(err_node):
500 """ 501 Holds source ISA loop errors 502 """ 503
504 - def __init__(self, parent, seg_data, src):
505 """ 506 @param seg_data: Segment object 507 @type seg_data: L{segment<segment.Segment>} 508 @param src: X12file source 509 @type src: L{X12file<x12file.X12file>} 510 """ 511 self.seg_data = seg_data 512 self.isa_id = src.get_isa_id() 513 self.cur_line_isa = src.get_cur_line() 514 self.cur_line_iea = None 515 516 self.isa_trn_set_id = seg_data.get_value('ISA13') 517 self.ta1_req = seg_data.get_value('ISA14') 518 self.orig_date = seg_data.get_value('ISA09') 519 self.orig_time = seg_data.get_value('ISA10') 520 self.id = 'ISA' 521 522 self.parent = parent 523 self.children = [] 524 self.errors = [] 525 self.elements = []
526
527 - def is_closed(self):
528 """ 529 @rtype: boolean 530 """ 531 if self.cur_line_iea: 532 return True 533 else: 534 return False
535
536 - def accept(self, visitor):
537 """ 538 Params: visitor - ref to visitor class 539 """ 540 visitor.visit_isa_pre(self) 541 for child in self.children: 542 child.accept(visitor) 543 visitor.visit_isa_post(self)
544
545 - def add_error(self, err_cde, err_str):
546 """ 547 @param err_cde: Error code 548 @type err_cde: string 549 @param err_str: Description of the error 550 @type err_str: string 551 """ 552 self.errors.append((err_cde, err_str))
553
554 - def close(self, node, seg, src):
555 self.cur_line_iea = src.get_cur_line()
556
557 - def get_cur_line(self):
558 """ 559 @return: Current file line number 560 @rtype: int 561 """ 562 if self.cur_line_iea: 563 return self.cur_line_iea 564 else: 565 return self.cur_line_isa
566
567 - def get_error_count(self):
568 """ 569 """ 570 count = 0 571 for ele in self.elements: 572 count += ele.get_error_count() 573 for child in self.children: 574 count += child.get_error_count() 575 return count + len(self.errors)
576
577 - def get_error_list(self, seg_id, pre=False):
578 """ 579 """ 580 if seg_id == 'ISA': 581 return filter(lambda err: 'ISA' in err[0], self.errors) 582 elif seg_id == 'IEA': 583 return filter(lambda err: 'IEA' in err[0], self.errors) 584 else: 585 return []
586 #err_list = [] 587 #for err in self.errors: 588 # if seg_id in err[0]: 589 # err_list.append(err) 590 #return err_list 591
592 - def next(self):
593 """ 594 Return the next error node 595 """ 596 for child in self.children: 597 yield child 598 self.parent.next()
599
600 - def __repr__(self):
601 return '%i: %s' % (self.get_cur_line(), self.id)
602 603
604 -class err_gs(err_node):
605 """ 606 Holds source GS loop information 607 """ 608
609 - def __init__(self, parent, seg_data, src):
610 """ 611 @param seg_data: Segment object 612 @type seg_data: L{segment<segment.Segment>} 613 @param src: X12file source 614 @type src: L{X12file<x12file.X12file>} 615 616 """ 617 self.seg_data = seg_data 618 self.isa_id = src.get_isa_id() 619 self.cur_line_gs = src.get_cur_line() 620 self.cur_line_ge = None 621 self.gs_control_num = src.get_gs_id() 622 self.fic = self.seg_data.get_value('GS01') 623 self.id = 'GS' 624 625 self.st_loops = [] 626 627 # From GE loop 628 self.ack_code = None # AK901 629 self.st_count_orig = 0 # AK902 630 self.st_count_recv = 0 # AK903 631 #self.st_count_accept = None # AK904 632 633 self.parent = parent 634 self.children = [] 635 self.errors = [] 636 self.elements = []
637
638 - def accept(self, visitor):
639 """ 640 Params: visitor - ref to visitor class 641 """ 642 visitor.visit_gs_pre(self) 643 for child in self.children: 644 child.accept(visitor) 645 visitor.visit_gs_post(self)
646
647 - def add_error(self, err_cde, err_str):
648 """ 649 @param err_cde: Error code 650 @type err_cde: string 651 @param err_str: Description of the error 652 @type err_str: string 653 """ 654 self.errors.append((err_cde, err_str))
655
656 - def close(self, node, seg_data, src):
657 """ 658 """ 659 # From GE loop 660 self.cur_line_ge = src.get_cur_line() 661 662 self.ack_code = self._get_ack_code() 663 664 if seg_data is None: 665 self.st_count_orig = 0 666 else: 667 self.st_count_orig = int(seg_data.get_value('GE01')) # AK902 668 self.st_count_recv = src.st_count # AK903
669 #self.st_count_accept = self.st_count_recv - len(self.children) # AK904 670
671 - def _get_ack_code(self):
672 for child in self.children: 673 if child.get_error_count() > 0: 674 return 'R' 675 #err_codes = map(lambda x:x[0], self.errors) 676 #if '1' in err_codes: return 'R' 677 #elif '2' in err_codes: return 'R' 678 #elif '3' in err_codes: return 'R' 679 #elif '4' in err_codes: return 'R' 680 #elif '5' in err_codes: return 'E' 681 #elif '6' in err_codes: return 'E' 682 if len(self.errors) > 0: 683 return 'R' 684 return 'A'
685
686 - def count_failed_st(self):
687 ct = 0 688 for child in self.children: 689 if child.ack_code not in ['A', 'E']: 690 ct += 1 691 return ct
692
693 - def get_cur_line(self):
694 """ 695 @return: Current file line number 696 @rtype: int 697 """ 698 if self.cur_line_ge: 699 return self.cur_line_ge 700 else: 701 return self.cur_line_gs
702
703 - def get_error_count(self):
704 """ 705 """ 706 count = 0 707 for ele in self.elements: 708 count += ele.get_error_count() 709 for child in self.children: 710 count += child.get_error_count() 711 return count + len(self.errors)
712
713 - def get_error_list(self, seg_id, pre=False):
714 """ 715 """ 716 if seg_id == 'GS': 717 return filter(lambda err: err[0] in ('6'), self.errors) 718 elif seg_id == 'GE': 719 return filter(lambda err: err[0] not in ('6'), self.errors) 720 else: 721 return []
722
723 - def is_closed(self):
724 """ 725 @rtype: boolean 726 """ 727 if self.cur_line_ge: 728 return True 729 else: 730 return False
731
732 - def next(self):
733 """ 734 Return the next error node 735 """ 736 for child in self.children: 737 yield child 738 self.parent.next()
739
740 - def __repr__(self):
741 return '%i: %s' % (self.get_cur_line(), self.id)
742 743
744 -class err_st(err_node):
745 """ 746 ST loops 747 748 Needs: 749 1. Transaction set id code (837, 834) 750 2. Transaction set control number 751 3. trn set error codes 752 4. At SE, Determine final ack code 753 """ 754
755 - def __init__(self, parent, seg_data, src):
756 """ 757 @param seg_data: Segment object 758 @type seg_data: L{segment<segment.Segment>} 759 @param src: X12file source 760 @type src: L{X12file<x12file.X12file>} 761 """ 762 self.seg_data = seg_data 763 self.trn_set_control_num = src.get_st_id() 764 self.cur_line_st = src.get_cur_line() 765 self.cur_line_se = None 766 self.trn_set_id = seg_data.get_value('ST01') 767 self.id = 'ST' 768 769 self.ack_code = 'R' 770 self.parent = parent 771 self.children = [] 772 self.errors = [] 773 self.elements = []
774 #self.rejected = None 775
776 - def accept(self, visitor):
777 """ 778 Params: visitor - ref to visitor class 779 """ 780 visitor.visit_st_pre(self) 781 for child in self.children: 782 child.accept(visitor) 783 visitor.visit_st_post(self)
784
785 - def add_error(self, err_cde, err_str):
786 """ 787 @param err_cde: Error code 788 @type err_cde: string 789 @param err_str: Description of the error 790 @type err_str: string 791 """ 792 self.errors.append((err_cde, err_str))
793
794 - def close(self, node, seg_data, src):
795 """ 796 Close ST loop 797 798 @param node: SE node 799 @type node: L{node<map_if.x12_node>} 800 @param seg_data: Segment object 801 @type seg_data: L{segment<segment.Segment>} 802 @param src: X12file source 803 @type src: L{X12file<x12file.X12file>} 804 """ 805 self.cur_line_se = src.get_cur_line() 806 #pdb.set_trace() 807 if self.err_count() > 0: 808 self.ack_code = 'R' 809 else: 810 self.ack_code = 'A'
811
812 - def err_count(self):
813 """ 814 @return: Count of ST/SE loop errors 815 @rtype: int 816 """ 817 seg_err_ct = 0 818 if self.child_err_count() > 0: 819 seg_err_ct = 1 820 return len(self.errors) + seg_err_ct
821
822 - def get_error_count(self):
823 return self.err_count()
824
825 - def get_error_list(self, seg_id, pre=False):
826 """ 827 """ 828 if seg_id == 'ST': 829 return filter(lambda err: err[0] in ('1', '6', '7', '23'), self.errors) 830 elif seg_id == 'SE': 831 return filter(lambda err: err[0] not in ('1', '6', '7', '23'), self.errors) 832 else: 833 return []
834
835 - def child_err_count(self):
836 ct = 0 837 for child in self.children: 838 if child.err_count() > 0: 839 ct += 1 840 return ct
841
842 - def get_cur_line(self):
843 """ 844 @return: Current file line number 845 @rtype: int 846 """ 847 if self.cur_line_se: 848 return self.cur_line_se 849 else: 850 return self.cur_line_st
851
852 - def is_closed(self):
853 """ 854 @rtype: boolean 855 """ 856 if self.cur_line_se: 857 return True 858 else: 859 return False
860
861 - def next(self):
862 """ 863 Return the next error node 864 """ 865 for child in self.children: 866 yield child 867 return
868 #self.parent.next() 869
870 - def __repr__(self):
871 return '%i: %s' % (self.get_cur_line(), self.id)
872 873
874 -class err_seg(err_node):
875 """ 876 Segment Errors 877 """
878 - def __init__(self, parent, map_node, seg_data, seg_count, cur_line, ls_id):
879 """ 880 Needs: 881 1. seg_id_code 882 2. seg_pos - pos in ST loop 883 3, loop_id - LS loop id 884 4. seg_count - in parent 885 """ 886 self.parent = parent 887 if map_node is None: 888 self.name = 'Unknown' 889 self.pos = -1 890 else: 891 self.name = map_node.name 892 self.pos = map_node.pos 893 self.seg_id = seg_data.get_seg_id() 894 self.seg_count = seg_count 895 self.cur_line = cur_line 896 self.ls_id = ls_id 897 898 self.id = 'SEG' 899 900 self.elements= [] 901 self.errors = []
902
903 - def accept(self, visitor):
904 """ 905 Params: visitor - ref to visitor class 906 """ 907 visitor.visit_seg(self) 908 for elem in self.elements: 909 elem.accept(visitor)
910
911 - def add_error(self, err_cde, err_str, err_value=None):
912 """ 913 @param err_cde: Error code 914 @type err_cde: string 915 @param err_str: Description of the error 916 @type err_str: string 917 """ 918 self.errors.append((err_cde, err_str, err_value))
919
920 - def err_count(self):
921 """ 922 Returns: count of errors 923 """ 924 ele_err_ct = 0 925 if self.child_err_count() > 0: 926 ele_err_ct = 1 927 return len(self.errors) + ele_err_ct
928
929 - def get_error_count(self):
930 return self.err_count()
931
932 - def child_err_count(self):
933 ct = 0 934 for ele in self.elements: 935 if ele.err_count() > 0: 936 ct += 1 937 return ct
938
939 - def next(self):
940 """ 941 Desc: Return the next error node 942 """ 943 #for child in self.children: 944 # yield child 945 #pdb.set_trace() 946 return self
947 #self.parent.next() 948
949 - def __repr__(self):
950 return '%i: %s %s' % (self.get_cur_line(), self.id, self.seg_id)
951
952 - def get_first_child(self):
953 return None
954 #raise IterOutOfBounds 955
956 -class err_ele(err_node):
957 """ 958 Element Errors - Holds and generates output for element and 959 composite/sub-element errors 960 961 Each element with an error creates a new err_ele instance. 962 """
963 - def __init__(self, parent, map_node):
964 """ 965 """ 966 #, self.id, self.name, self.seq, self.data_ele) 967 self.ele_ref_num = map_node.data_ele 968 self.name = map_node.name 969 if map_node.parent.is_composite(): 970 self.ele_pos = map_node.parent.seq 971 self.subele_pos = map_node.seq 972 else: 973 self.ele_pos = map_node.seq 974 self.subele_pos = None 975 976 #self.bad_val = bad_val 977 self.id = 'ELE' 978 979 self.parent = parent 980 #self.children = [] 981 self.errors = []
982
983 - def accept(self, visitor):
984 """ 985 Params: visitor - ref to visitor class 986 """ 987 visitor.visit_ele(self)
988
989 - def add_error(self, err_cde, err_str, bad_value):
990 """ 991 @param err_cde: Error code 992 @type err_cde: string 993 @param err_str: Description of the error 994 @type err_str: string 995 """ 996 #logger.debug('err_ele.add_error: %s %s %s' % (err_cde, err_str, bad_value)) 997 self.errors.append((err_cde, err_str, bad_value))
998
999 - def err_count(self):
1000 return len(self.errors)
1001
1002 - def get_error_count(self):
1003 return len(self.errors)
1004
1005 -class ErrorErrhNull(Exception):
1006 """Class for errh_null errors."""
1007
1008 -class errh_null(object):
1009 """ 1010 A null error object - used for testing. 1011 Stores the current error in simple variables. 1012 """
1013 - def __init__(self):
1014 self.id = 'ROOT' 1015 #self.children = [] 1016 self.cur_node = self 1017 #self.cur_isa_node = None 1018 #self.cur_gs_node = None 1019 #self.cur_st_node = None 1020 #self.cur_seg_node = None 1021 #self.seg_node_added = False 1022 #self.cur_ele_node = None 1023 self.cur_line = 0 1024 self.err_cde = None 1025 self.err_str = None
1026
1027 - def get_cur_line(self):
1028 """ 1029 @return: Current file line number 1030 @rtype: int 1031 """ 1032 return self.cur_line
1033
1034 - def get_id(self):
1035 """ 1036 @return: Error node type 1037 @rtype: string 1038 """ 1039 return self.id
1040
1041 - def add_isa_loop(self, seg, src):
1042 """ 1043 """ 1044 raise ErrorErrhNull, 'add_isa loop'
1045
1046 - def add_gs_loop(self, seg, src):
1047 """ 1048 """ 1049 pass
1050
1051 - def add_st_loop(self, seg, src):
1052 """ 1053 """ 1054 pass
1055
1056 - def add_seg(self, map_node, seg, seg_count, cur_line, ls_id):
1057 """ 1058 """ 1059 pass
1060
1061 - def add_ele(self, map_node):
1062 """ 1063 """ 1064 pass
1065
1066 - def isa_error(self, err_cde, err_str):
1067 """ 1068 @param err_cde: ISA level error code 1069 @type err_cde: string 1070 @param err_str: Description of the error 1071 @type err_str: string 1072 """ 1073 self.err_cde = err_cde 1074 self.err_str = err_str
1075
1076 - def gs_error(self, err_cde, err_str):
1077 """ 1078 @param err_cde: GS level error code 1079 @type err_cde: string 1080 @param err_str: Description of the error 1081 @type err_str: string 1082 """ 1083 self.err_cde = err_cde 1084 self.err_str = err_str
1085
1086 - def st_error(self, err_cde, err_str):
1087 """ 1088 @param err_cde: Segment level error code 1089 @type err_cde: string 1090 @param err_str: Description of the error 1091 @type err_str: string 1092 """ 1093 self.err_cde = err_cde 1094 self.err_str = err_str
1095
1096 - def seg_error(self, err_cde, err_str, err_value=None, src_line=None):
1097 """ 1098 @param err_cde: Segment level error code 1099 @type err_cde: string 1100 @param err_str: Description of the error 1101 @type err_str: string 1102 """ 1103 self.err_cde = err_cde 1104 self.err_str = err_str
1105
1106 - def ele_error(self, err_cde, err_str, bad_value):
1107 """ 1108 @param err_cde: Element level error code 1109 @type err_cde: string 1110 @param err_str: Description of the error 1111 @type err_str: string 1112 """ 1113 self.err_cde = err_cde 1114 self.err_str = err_str
1115
1116 - def close_isa_loop(self, node, seg, src):
1117 """ 1118 """ 1119 pass
1120
1121 - def close_gs_loop(self, node, seg, src):
1122 """ 1123 """ 1124 pass
1125
1126 - def close_st_loop(self, node, seg, src):
1127 """ 1128 """ 1129 pass
1130
1131 - def find_node(self, type):
1132 """ 1133 Find the last node of a type 1134 """ 1135 pass
1136
1137 - def get_parent(self):
1138 return None
1139 1140 # def get_first_child(self): 1141 # """ 1142 # """ 1143 # if len(self.children) > 0: 1144 # return self.children[0] 1145 # else: 1146 # return None 1147
1148 - def get_next_sibling(self):
1149 """ 1150 """ 1151 return None
1152
1153 - def get_error_count(self):
1154 """ 1155 """ 1156 if self.err_cde is not None: 1157 return 1 1158 else: 1159 return 0
1160
1161 - def is_closed(self):
1162 """ 1163 @rtype: boolean 1164 """ 1165 return True
1166
1167 - def __repr__(self):
1168 """ 1169 """ 1170 return '%i: %s' % (-1, self.id)
1171