当前位置: 首页>>代码示例>>Python>>正文


Python headers.MimeHeaders类代码示例

本文整理汇总了Python中flanker.mime.message.headers.MimeHeaders的典型用法代码示例。如果您正苦于以下问题:Python MimeHeaders类的具体用法?Python MimeHeaders怎么用?Python MimeHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MimeHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: headers_transform_encodedword_test

def headers_transform_encodedword_test():
    # Create a header with non-ascii characters that will be stored in encoded-word format.
    headers = [('Subject', encoding.to_mime('Subject', u'Hello ✓'))]
    h = MimeHeaders(headers)

    # transform should decode it for us when we pass decode=True
    h.transform(lambda key,val: (key, val.replace(u'✓', u'☃')), decode=True)
    eq_(u'Hello ☃', h.get('Subject'))
开发者ID:mailgun,项目名称:flanker,代码行数:8,代码来源:headers_test.py

示例2: headers_case_insensitivity_test

def headers_case_insensitivity_test():
    h = MimeHeaders()
    h['Content-Type'] = 1
    eq_(1, h['Content-Type'])
    eq_(1, h['conTenT-TyPE'])
    ok_('cOnTenT-TyPE' in h)
    ok_('Content-Type' in h)
    eq_(1, h.get('Content-Type'))
    eq_(None, h.get('Content-Type2'))
    eq_([('Content-Type', 1)], h.items())
开发者ID:Appono,项目名称:flanker,代码行数:10,代码来源:headers_test.py

示例3: headers_roundtrip_test

def headers_roundtrip_test():
    headers = MimeHeaders.from_stream(StringIO(BILINGUAL))
    out = StringIO()
    headers.to_stream(out)

    headers2 = MimeHeaders.from_stream(StringIO(out.getvalue()))
    eq_(21, len(headers2))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers["Subject"])
    received_headers = headers.getall("Received")
    eq_(5, len(received_headers))
    ok_("c2cs24435ybk" in received_headers[0])
    eq_(headers["Content-Transfer-Encoding"], headers2["Content-Transfer-Encoding"])
    eq_(headers["DKIM-Signature"], headers2["DKIM-Signature"])
开发者ID:nickcatal,项目名称:flanker,代码行数:13,代码来源:headers_test.py

示例4: headers_order_preserved_test

def headers_order_preserved_test():
    headers = [("mime-version", "1"), ("rEceived", "2"), ("mime-version", "3"), ("ReceiveD", "4")]
    h = MimeHeaders(headers)

    # various types of iterations
    should_be = [("Mime-Version", "1"), ("Received", "2"), ("Mime-Version", "3"), ("Received", "4")]
    eq_(should_be, h.items())
    ok_(isinstance(h.items(), list))
    eq_(should_be, [p for p in h.iteritems()])

    # iterate over keys
    keys = ["Mime-Version", "Received", "Mime-Version", "Received"]
    eq_(keys, [p for p in h])
    eq_(keys, h.keys())
开发者ID:nickcatal,项目名称:flanker,代码行数:14,代码来源:headers_test.py

示例5: headers_roundtrip_test

def headers_roundtrip_test():
    headers = MimeHeaders.from_stream(six.StringIO(BILINGUAL.decode('utf-8')))
    out = six.StringIO()
    headers.to_stream(out)

    headers2 = MimeHeaders.from_stream(six.StringIO(out.getvalue()))
    eq_(21, len(headers2))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers['Subject'])
    received_headers = headers.getall('Received')
    eq_(5, len(received_headers))
    ok_('c2cs24435ybk' in received_headers[0])
    eq_(headers['Content-Transfer-Encoding'],
        headers2['Content-Transfer-Encoding'])
    eq_(headers['DKIM-Signature'],
        headers2['DKIM-Signature'])
开发者ID:plq,项目名称:flanker,代码行数:15,代码来源:headers_test.py

示例6: bilingual_message_test

def bilingual_message_test():
    headers = MimeHeaders.from_stream(StringIO(BILINGUAL))
    eq_(21, len(headers))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers['Subject'])
    received_headers = headers.getall('Received')
    eq_(5, len(received_headers))
    ok_('c2cs24435ybk' in received_headers[0])
开发者ID:Appono,项目名称:flanker,代码行数:7,代码来源:headers_test.py

示例7: headers_multiple_values_test

def headers_multiple_values_test():
    headers = [("mime-version", "1"), ("rEceived", "2"), ("mime-version", "3"), ("ReceiveD", "4")]
    h = MimeHeaders(headers)
    eq_(["1", "3"], h.getall("Mime-Version"))

    # set re-sets all values for the message
    h["Mime-Version"] = "5"
    eq_(["5"], h.getall("Mime-Version"))

    # use add to add more values
    h.add("Received", "6")
    eq_(["2", "4", "6"], h.getall("Received"))

    # use prepend to insert header in the begining of the list
    h.prepend("Received", "0")
    eq_(["0", "2", "4", "6"], h.getall("Received"))

    # delete removes it all!
    del h["RECEIVED"]
    eq_([], h.getall("Received"))
开发者ID:nickcatal,项目名称:flanker,代码行数:20,代码来源:headers_test.py

示例8: headers_transform_test

def headers_transform_test():
    headers = [("mime-version", "1"), ("rEceived", "2"), ("mime-version", "3"), ("ReceiveD", "4")]

    h = MimeHeaders(headers)

    # transform tracks whether anything actually changed
    h.transform(lambda key, val: (key, val))
    assert_false(h.have_changed())

    # ok, now something have changed, make sure we've preserved order and did not collapse anything
    h.transform(lambda key, val: ("X-{}".format(key), "t({})".format(val)))
    ok_(h.have_changed())

    eq_(
        [("X-Mime-Version", "t(1)"), ("X-Received", "t(2)"), ("X-Mime-Version", "t(3)"), ("X-Received", "t(4)")],
        h.items(),
    )
开发者ID:nickcatal,项目名称:flanker,代码行数:17,代码来源:headers_test.py

示例9: headers_transform_test

def headers_transform_test():
    headers = [('mime-version', '1'), ('rEceived', '2'), ('mime-version', '3'), ('ReceiveD', '4')]

    h = MimeHeaders(headers)

    # transform tracks whether anything actually changed
    h.transform(lambda key,val: (key, val))
    assert_false(h.have_changed())

    # ok, now something have changed, make sure we've preserved order and did not collapse anything
    h.transform(lambda key,val: ("X-{0}".format(key), "t({0})".format(val)))
    ok_(h.have_changed())

    eq_([('X-Mime-Version', 't(1)'), ('X-Received', 't(2)'), ('X-Mime-Version', 't(3)'), ('X-Received', 't(4)')], h.items())
开发者ID:Appono,项目名称:flanker,代码行数:14,代码来源:headers_test.py

示例10: add

 def add(self, key, value):
     MimeHeaders.add(self, key, value)
     self._m[key] = headers.to_mime(normalize(key), remove_newlines(value))
开发者ID:Appono,项目名称:flanker,代码行数:3,代码来源:part.py

示例11: test_folding_combinations

def test_folding_combinations():
    message = """From [email protected] Mon Feb  8 02:53:47 PST 1993\nTo: sasha\r\n  continued\n      line\nFrom: single line  \r\nSubject: hello, how are you\r\n today?"""
    headers = MimeHeaders.from_stream(StringIO(message))
    eq_('sasha  continued      line', headers['To'])
    eq_('single line  ', headers['From'])
    eq_("hello, how are you today?", headers['Subject'])
开发者ID:Appono,项目名称:flanker,代码行数:6,代码来源:headers_test.py

示例12: headers_parsing_ridiculously_long_line_test

def headers_parsing_ridiculously_long_line_test():
    val = "abcdefg"*100000
    header = "Hello: {0}\r\n".format(val)
    MimeHeaders.from_stream(StringIO(header))
开发者ID:mailgun,项目名称:flanker,代码行数:4,代码来源:headers_test.py

示例13: broken_sequences_test

def broken_sequences_test():
    headers = StringIO("  hello this is a bad header\nGood: this one is ok")
    headers = MimeHeaders.from_stream(headers)
    eq_(1, len(headers))
    eq_("this one is ok", headers["Good"])
开发者ID:Appono,项目名称:flanker,代码行数:5,代码来源:headers_test.py

示例14: headers_parsing_empty_test

def headers_parsing_empty_test():
    h = MimeHeaders.from_stream(StringIO(""))
    eq_(0, len(h))
开发者ID:Appono,项目名称:flanker,代码行数:3,代码来源:headers_test.py

示例15: __delitem__

 def __delitem__(self, key):
     MimeHeaders.__delitem__(self, key)
     del self._m[key]
开发者ID:Appono,项目名称:flanker,代码行数:3,代码来源:part.py


注:本文中的flanker.mime.message.headers.MimeHeaders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。