コード例 #1
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_encoding(self):
     # pound sign: '£' == '\u00a3' latin-1: b'\xa3', utf-8: b'\xc2\xa3'
     with pytest.raises(UnicodeDecodeError):
         base.BinString(b'\xa3', errors='strict')
     s = base.BinString(b'\xa3', encoding='latin-1', errors='strict')
     assert s == '£'
     assert bytes(s) == b'\xa3'
コード例 #2
0
    def threadid(self):
        """The thread ID.

        The thread ID is decoded with the surrogateescape error
        handler so that it is possible to reconstruct the original
        thread ID if it is not valid UTF-8.

        :returns: The thread ID.
        :rtype: :class:`BinString`, this is a normal str but calling
           bytes() on it will return the original bytes used to create
           it.

        :raises ObjectDestroyedError: if used after destroyed.
        """
        ret = capi.lib.notmuch_message_get_thread_id(self._msg_p)
        return base.BinString(capi.ffi.string(ret))
コード例 #3
0
    def messageid(self):
        """The message ID as a string.

        The message ID is decoded with the ignore error handler.  This
        is fine as long as the message ID is well formed.  If it is
        not valid ASCII then this will be lossy.  So if you need to be
        able to write the exact same message ID back you should use
        :attr:`messageidb`.

        Note that notmuch will decode the message ID value and thus
        strip off the surrounding ``<`` and ``>`` characters.  This is
        different from Python's :mod:`email` package behaviour which
        leaves these characters in place.

        :returns: The message ID.
        :rtype: :class:`BinString`, this is a normal str but calling
           bytes() on it will return the original bytes used to create
           it.

        :raises ObjectDestroyedError: if used after destroyed.
        """
        ret = capi.lib.notmuch_message_get_message_id(self._msg_p)
        return base.BinString(capi.ffi.string(ret))
コード例 #4
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_invalid_utf8(self):
     s = base.BinString(b'\x80foo')
     assert s == 'foo'
     assert bytes(s) == b'\x80foo'
コード例 #5
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_bytes(self):
     s = base.BinString(b'foo')
     assert bytes(s) == b'foo'
コード例 #6
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_init_str(self):
     s = base.BinString('foo')
     assert s == 'foo'
コード例 #7
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_init_bytes(self):
     s = base.BinString(b'foo')
     assert s == 'foo'
コード例 #8
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_type(self):
     s = base.BinString(b'foo')
     assert isinstance(s, str)
コード例 #9
0
ファイル: test_base.py プロジェクト: tstenhaug/notmuch
 def test_errors(self):
     s = base.BinString(b'\x80foo', errors='replace')
     assert s == '�foo'
     assert bytes(s) == b'\x80foo'