프로젝트

일반

사용자정보

개정판 36d003ae

ID36d003ae2f926aaea2ce0f900604a20fb5286113
상위 d6819cb8
하위 8ce06859, 6e800d2b

함의성이(가) 약 4년 전에 추가함

issue #000: add ex

Change-Id: I2f381e44db4c97bb2fc36acde8bf2bc7aa6d16e3

차이점 보기:

DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py
486 486
                    else:
487 487
                        self.attrs[attr] = ''
488 488

  
489
    def try_eval(self, item, expression):
490
        try:
491
            return eval(expression)
492
        except Exception as ex:
493
            from App import App
494
            from AppDocData import MessageType
495

  
496
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
497
                                                           sys.exc_info()[-1].tb_lineno) + ' Item UID : ' + str(self.uid)
498
            App.mainWnd().addMessage.emit(MessageType.Error, message)
499
        
500
        return ''
501

  
502

  
489 503
    def getAttributes(self, findOwner=False):
490 504
        """calculate all attributes of item"""
491 505
        import re
......
576 590
                    if not attr.AssocItem and len(items) > at and not attr.Codes.values:
577 591
                        attr.AssocItem = items[at]
578 592
                        item = attr.AssocItem
579
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
593
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else ''
580 594
                    elif attr.AssocItem:
581 595
                        item = attr.AssocItem = self.get_assoc_item(attr.AssocItem)
582
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
596
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else ''
583 597
                    else:
584 598
                        _attrs[attr] = ''
585 599
                elif attr.AttributeType == 'Size Text Item' or attr.AttributeType == 'Tag No':
......
588 602
                    if not attr.AssocItem and len(items) > at:
589 603
                        attr.AssocItem = items[at]
590 604
                        item = attr.AssocItem
591
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
605
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else ''
592 606
                    else:
593 607
                        item = attr.AssocItem = self.get_assoc_item(attr.AssocItem)
594
                        _attrs[attr] = eval(attr.Expression) if attr.Expression and (
608
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression and (
595 609
                                (item and 'item' in attr.Expression) or 'self' in attr.Expression) else ''
596 610
                elif attr.AttributeType == 'Symbol Item' or attr.AttributeType == 'Line Item' or \
597 611
                        attr.AttributeType == 'Comp Item' or attr.AttributeType == 'EQ Item':
......
599 613
                    if not attr.AssocItem and len(_symbols) > at:
600 614
                        attr.AssocItem = _symbols[at]
601 615
                        item = attr.AssocItem
602
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
616
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else ''
603 617
                    elif attr.AssocItem:
604 618
                        item = attr.AssocItem = self.get_assoc_item(attr.AssocItem)
605
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
619
                        _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else ''
606 620
                    else:
607 621
                        _attrs[attr] = ''
608 622
                elif attr.AttributeType == 'String':
609 623
                    #_attrs[attr] = attr.Expression if attr.Expression and not _attrs[attr] else _attrs[attr]
610
                    _attrs[attr] = eval(attr.Expression) if attr.Expression else _attrs[attr]
624
                    _attrs[attr] = self.try_eval(item, attr.Expression) if attr.Expression else _attrs[attr]
611 625

  
612 626
            """calculate attribute value for combined type"""
613 627
            p = re.compile('{[A-Za-z0-9_ ]+}')
......
641 655
                    pos = match.end()
642 656

  
643 657
                value += attr.Expression[pos:len(attr.Expression)]
644
                _attrs[attr] = eval(value) if attr.Expression else ''
658
                _attrs[attr] = self.try_eval(None, value) if attr.Expression else ''
645 659
            """up to here"""
646 660

  
647 661
            for _attr, _value in _attrs.items():

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)