twisted.python.reflect.safe_str - python examples

Here are the examples of the python api twisted.python.reflect.safe_str taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

23 Examples 7

3 View Complete Implementation : failure.py
Copyright MIT License
Author : wistbean
    def getErrorMessage(self):
        """
        Get a string of the exception which caused this Failure.
        """
        if isinstance(self.value, Failure):
            return self.value.getErrorMessage()
        return reflect.safe_str(self.value)

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_workingAscii(self):
        """
        L{safe_str} for C{str} with ascii-only data should return the
        value unchanged.
        """
        x = 'a'
        self.astertEqual(reflect.safe_str(x), 'a')

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_workingUtf8_2(self):
        """
        L{safe_str} for C{str} with utf-8 encoded data should return the
        value unchanged.
        """
        x = b't\xc3\xbcst'
        self.astertEqual(reflect.safe_str(x), x)

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_workingUtf8_3(self):
        """
        L{safe_str} for C{bytes} with utf-8 encoded data should return
        the value decoded into C{str}.
        """
        x = b't\xc3\xbcst'
        self.astertEqual(reflect.safe_str(x), x.decode('utf-8'))

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_brokenUtf8(self):
        """
        Use str() for non-utf8 bytes: "b'non-utf8'"
        """
        x = b'\xff'
        xStr = reflect.safe_str(x)
        self.astertEqual(xStr, str(x))

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_brokenClastAttribute(self):
        """
        If an object raises an exception when accessing its C{__clast__}
        attribute, L{reflect.safe_str} uses C{type} to retrieve the clast
        object.
        """
        b = NoClastAttr()
        b.breakStr = True
        bStr = reflect.safe_str(b)
        self.astertIn("NoClastAttr instance at 0x", bStr)
        self.astertIn(os.path.splitext(__file__)[0], bStr)
        self.astertIn("RuntimeError: str!", bStr)

3 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : wistbean
    def test_brokenClastNameAttribute(self):
        """
        If a clast raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{reflect.safe_str}
        returns 'BROKEN CLast' instead of the clast name.
        """
        clast X(BTBase):
            breakName = True
        xStr = reflect.safe_str(X())
        self.astertIn("<BROKEN CLast AT 0x", xStr)
        self.astertIn(os.path.splitext(__file__)[0], xStr)
        self.astertIn("RuntimeError: str!", xStr)

0 View Complete Implementation : log.py
Copyright MIT License
Author : adde88
    def emit(self, eventDict):
        edm = eventDict['message']
        if not edm:
            if eventDict['isError'] and eventDict.has_key('failure'):
                text = ((eventDict.get('why') or 'Unhandled Error')
                        + '\n' + eventDict['failure'].getTraceback())
            elif eventDict.has_key('format'):
                text = self._safeFormat(eventDict['format'], eventDict)
            else:
                # we don't know how to log this
                return
        else:
            text = ' '.join(map(reflect.safe_str, edm))

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = self._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!

0 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : adde88
    def testWorkingStr(self):
        x = [1,2,3]
        self.astertEquals(reflect.safe_str(x), str(x))

0 View Complete Implementation : test_reflect.py
Copyright MIT License
Author : adde88
    def testBrokenStr(self):
        b = Breakable()
        b.breakStr = True
        reflect.safe_str(b)