本文整理汇总了Python中email.quoprimime.header_encode方法的典型用法代码示例。如果您正苦于以下问题:Python quoprimime.header_encode方法的具体用法?Python quoprimime.header_encode怎么用?Python quoprimime.header_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.quoprimime
的用法示例。
在下文中一共展示了quoprimime.header_encode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_header_encode
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_header_encode(self):
eq = self.assertEqual
he = quoprimime.header_encode
eq(he('hello'), '=?iso-8859-1?q?hello?=')
eq(he('hello\nworld'), '=?iso-8859-1?q?hello=0D=0Aworld?=')
# Test the charset option
eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?q?hello?=')
# Test the keep_eols flag
eq(he('hello\nworld', keep_eols=True), '=?iso-8859-1?q?hello=0Aworld?=')
# Test a non-ASCII character
eq(he('hello\xc7there'), '=?iso-8859-1?q?hello=C7there?=')
# Test the maxlinelen argument
eq(he('xxxx ' * 20, maxlinelen=40), """\
=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
=?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
=?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=
=?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=
=?iso-8859-1?q?x_xxxx_xxxx_?=""")
# Test the eol argument
eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=\r
=?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=\r
=?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=\r
=?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=\r
=?iso-8859-1?q?x_xxxx_xxxx_?=""")
示例2: test_header_quopri_len
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_header_quopri_len(self):
eq = self.assertEqual
eq(quoprimime.header_length(b'hello'), 5)
# RFC 2047 chrome is not included in header_length().
eq(len(quoprimime.header_encode(b'hello', charset='xxx')),
quoprimime.header_length(b'hello') +
# =?xxx?q?...?= means 10 extra characters
10)
eq(quoprimime.header_length(b'h@e@l@l@o@'), 20)
# RFC 2047 chrome is not included in header_length().
eq(len(quoprimime.header_encode(b'h@e@l@l@o@', charset='xxx')),
quoprimime.header_length(b'h@e@l@l@o@') +
# =?xxx?q?...?= means 10 extra characters
10)
for c in self.hlit:
eq(quoprimime.header_length(bytes([c])), 1,
'expected length 1 for %r' % chr(c))
for c in self.hnon:
# Space is special; it's encoded to _
if c == ord(' '):
continue
eq(quoprimime.header_length(bytes([c])), 3,
'expected length 3 for %r' % chr(c))
eq(quoprimime.header_length(b' '), 1)
示例3: test_header_quopri_len
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_header_quopri_len(self):
eq = self.assertEqual
hql = quoprimime.header_quopri_len
enc = quoprimime.header_encode
for s in ('hello', 'h@e@l@l@o@'):
# Empty charset and no line-endings. 7 == RFC chrome
eq(hql(s), len(enc(s, charset='', eol=''))-7)
for c in self.hlit:
eq(hql(c), 1)
for c in self.hnon:
eq(hql(c), 3)
示例4: test_accepts_any_charset_like_object
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_accepts_any_charset_like_object(self):
# issue 1690608. email.utils.formataddr() should be rfc2047 aware.
name = "H\u00e4ns W\u00fcrst"
addr = 'person@dom.ain'
utf8_base64 = "=?utf-8?b?SMOkbnMgV8O8cnN0?= <person@dom.ain>"
foobar = "FOOBAR"
class CharsetMock:
def header_encode(self, string):
return foobar
mock = CharsetMock()
mock_expected = "%s <%s>" % (foobar, addr)
self.assertEqual(utils.formataddr((name, addr), mock), mock_expected)
self.assertEqual(utils.formataddr((name, addr), Charset('utf-8')),
utf8_base64)
示例5: test_invalid_charset_like_object_raises_error
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_invalid_charset_like_object_raises_error(self):
# issue 1690608. email.utils.formataddr() should be rfc2047 aware.
name = "H\u00e4ns W\u00fcrst"
addr = 'person@dom.ain'
# An object without a header_encode method:
bad_charset = object()
self.assertRaises(AttributeError, utils.formataddr, (name, addr),
bad_charset)
示例6: test_header_encode
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_header_encode(self):
eq = self.assertEqual
he = base64mime.header_encode
eq(he('hello'), '=?iso-8859-1?b?aGVsbG8=?=')
eq(he('hello\r\nworld'), '=?iso-8859-1?b?aGVsbG8NCndvcmxk?=')
eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
# Test the charset option
eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?b?aGVsbG8=?=')
eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
示例7: _test_header_encode
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def _test_header_encode(self, header, expected_encoded_header, charset=None):
if charset is None:
encoded_header = quoprimime.header_encode(header)
else:
encoded_header = quoprimime.header_encode(header, charset)
self.assertEqual(encoded_header, expected_encoded_header)
示例8: test_header_encode
# 需要导入模块: from email import quoprimime [as 别名]
# 或者: from email.quoprimime import header_encode [as 别名]
def test_header_encode(self):
eq = self.assertEqual
he = base64mime.header_encode
eq(he('hello'), '=?iso-8859-1?b?aGVsbG8=?=')
eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8NCndvcmxk?=')
# Test the charset option
eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?b?aGVsbG8=?=')
# Test the keep_eols flag
eq(he('hello\nworld', keep_eols=True),
'=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
# Test the maxlinelen argument
eq(he('xxxx ' * 20, maxlinelen=40), """\
=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=
=?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=
=?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=
=?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=
=?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=
=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")
# Test the eol argument
eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=\r
=?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=\r
=?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=\r
=?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=\r
=?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=\r
=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")