當前位置: 首頁>>代碼示例>>Python>>正文


Python Utils.format_exception_context方法代碼示例

本文整理匯總了Python中Cerebrum.Utils.format_exception_context方法的典型用法代碼示例。如果您正苦於以下問題:Python Utils.format_exception_context方法的具體用法?Python Utils.format_exception_context怎麽用?Python Utils.format_exception_context使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cerebrum.Utils的用法示例。


在下文中一共展示了Utils.format_exception_context方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_format_exception_context1

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import format_exception_context [as 別名]
def test_format_exception_context1():
    """ Utils.format_exception_context with valid arguments. """
    try:
        raise ValueError("ioshivfq")
    except ValueError:
        message = Utils.format_exception_context(*sys.exc_info())
        assert re.search("Exception <type 'exceptions.ValueError'> occured " +
                         "\(in context.*: ioshivfq", message)
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:10,代碼來源:test_core_Utils.py

示例2: next

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import format_exception_context [as 別名]
    def next(self):
        """Return next object constructed from a suitable XML element

        Reads the 'next' element and returns an object constructed out of it,
        if at all possible. The object construction is dispatched to
        subclasses (via next_object). If the object construction fails,
        next_object should return None.

        This method would consume subsequent XML elements/subtrees until a
        suitable object can be constructed or we run out of XML elements. In
        the latter case StopIteration is thrown (as per iterator protocol).

        IVR 2007-12-25 TBD: releasing the memory occupied by subtrees is quite
        helpful, but very ugly in this code. This should be implemented more
        elegantly.
        """

        import sys
        while 1:
            try:
                # Fetch the next XML subtree...
                element = self._xmliter.next()
                # ... and dispatch to subclass to create an object
                obj = self.next_object(element)

                # free the memory in the ElementTree framework.
                element.clear()

                # IVR 2007-12-28 TBD: Do we want some generic 'no object
                # created' error message here? The problem with such a message
                # is that it is difficult to ignore a separate generic error
                # line in the logs. Typically, when obj is None,
                # next_element() would have made (or at least, it should have)
                # some sort of error message which explains far better what
                # went wrong, thus making a generic message here somewhat
                # moot.
                if obj is not None:
                    return obj
            except StopIteration:
                raise
            except:
                # If *any* sort of exception occurs, log this, and continue
                # with the parsing. We cannot afford one defective entry to
                # break down the entire data import run.
                if self.logger:
                    self.logger.warn(
                        "%s occurred while processing XML element %s. "
                        "Skipping it.",
                        Utils.format_exception_context(*sys.exc_info()),
                        element.tag)
                element.clear()
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:53,代碼來源:xml2object.py

示例3: test_format_exception_context_no_exc

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import format_exception_context [as 別名]
def test_format_exception_context_no_exc():
    """ Utils.format_exception_context with empty arguments. """
    retval = Utils.format_exception_context(None, None, None)
    assert retval == ''
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:6,代碼來源:test_core_Utils.py


注:本文中的Cerebrum.Utils.format_exception_context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。