本文整理汇总了Python中Kamaelia.Data.MimeDict.MimeDict类的典型用法代码示例。如果您正苦于以下问题:Python MimeDict类的具体用法?Python MimeDict怎么用?Python MimeDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MimeDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test___str__fromString_RepeatedMultipleHeadersWithDifferingContinuationSizes
def test___str__fromString_RepeatedMultipleHeadersWithDifferingContinuationSizes(self):
"Identity check for fromString, __str__ roundtrip for header with repeated multiple headers with continuations"
value1a = "Twinkle \r\n Twinkle"
value2a = "Little\r\n Star"
value3a = "How I \r\n wonder what you are"
value1b = "Twinkle \r\n Twinkle\r\n Twinkle"
value2b = "Little\r\n Star\r\n Star"
value3b = "How I \r\n wonder what you are\r\n Star"
value1c = "Twinkle \r\n Twinkle\r\n Star"
value2c = "Little\r\n Star\r\n Star"
value3c = "How I \r\n wonder what you are\r\n Star\r\n are!"
header = "Header: " + value1a + "\r\n"
header += "Hooder: " + value2a + "\r\n"
header += "Hooder: " + value3a + "\r\n"
header += "Heeder: " + value3b + "\r\n"
header += "Header: " + value3c + "\r\n"
header += "Heeder: " + value2b + "\r\n"
header += "Heeder: " + value1b + "\r\n"
header += "Hooder: " + value1c + "\r\n"
header += "Header: " + value2c + "\r\n"
body = ""
message = header + "\r\n" + body
x = MimeDict.fromString(message)
y = MimeDict.fromString(str(x))
self.assertEqual(x, y)
self.assertEqual(str(x), str(y))
self.assertEqual(str(y), message)
示例2: test___str__fromString_RepeatedSingleHeaderWithContinuations
def test___str__fromString_RepeatedSingleHeaderWithContinuations(self):
"Identity check for fromString, __str__ roundtrip for header with repeated headers with continuations"
value1 = "Twinkle \r\n Twinkle"
value2 = "Little\r\n Star"
header = "Header: " + value1 + "\r\n"
header += "Header: " + value2 + "\r\n"
body = ""
message = header + "\r\n" + body
x = MimeDict.fromString(message)
y = MimeDict.fromString(str(x))
self.assertEqual(x, y)
self.assertEqual(str(x), str(y))
self.assertEqual(str(x), message)
示例3: test___str__fromString_MultipleHeadersWithContinuations
def test___str__fromString_MultipleHeadersWithContinuations(self):
"Identity check for fromString, __str__ roundtrip for header with multiple headers with continuations"
value1 = "Twinkle \r\n Twinkle"
value2 = "Little\r\n Star"
value3 = "How I \r\n wonder what you are"
header = "Header: " + value1 + "\r\n"
header += "Heeder: " + value2 + "\r\n"
header += "Hooder: " + value3 + "\r\n"
body = ""
message = header + "\r\n" + body
x = MimeDict.fromString(message)
y = MimeDict.fromString(str(x))
self.assertEqual(x, y)
self.assertEqual(str(x), str(y))
self.assertEqual(str(y), message)
示例4: test__str__SampleNonEmptyDict
def test__str__SampleNonEmptyDict(self):
"__str__ - Dict with multiple headers each with 1 associated simple string value should result in leading Key: Value lines"
x = MimeDict(Hello="World", Sheep="Dolly", Marvin="Android", Cat="Garfield")
lines = str(x).splitlines(True)
self.assertEqual(lines[4], "\r\n")
header = lines[:4]
header.sort()
keys = x.keys()
keys.sort()
h = 0
for k in keys:
if k == "__BODY__":
continue
self.assertEqual(header[h], "%s: %s\r\n" % (k, x[k]))
h += 1
示例5: test_fromString_RepeatedHeaders_SameOrder
def test_fromString_RepeatedHeaders_SameOrder(self):
"fromString - Repeated headers after each other retain order in dictionary values"
headerset1 = """HeaderA: value 1\r\nHeaderA: value 2\r\nHeaderA: value 3\r\n"""
headerset2 = """HeaderB: value 4\r\nHeaderB: value 5\r\nHeaderB: value 6\r\n"""
x = MimeDict.fromString(headerset1 + headerset2 + "\r\n")
self.assertEqual(x["HeaderA"], ["value 1", "value 2", "value 3"])
self.assertEqual(x["HeaderB"], ["value 4", "value 5", "value 6"])
示例6: test_Roundtrip_InvalidSourceMessageNonEmptyBody
def test_Roundtrip_InvalidSourceMessageNonEmptyBody(self):
"Roundtrip handling (fromString->__str__) for invalid messages with an non-empty body should NOT result in equality"
header = "Header: Twinkle Twinkle Little Star\r\n"
body = "How I wonder what you are"
message = header + "" + body # empty "divider"
x = MimeDict.fromString(message)
self.assertEqual(str(x), message)
示例7: test_fromString_HeaderWithContinuationLines_AllCaptured_ManyContinuations
def test_fromString_HeaderWithContinuationLines_AllCaptured_ManyContinuations(self):
"fromString - A header with many continuation lines is captured as a single string"
value = "Twinkle\r\n Twi nkle\r\n Li ttle Start\r\n How I wonder what y\r\n u are\r\n No Really"
header = "Header: " + value + "\r\n"
body = ""
x = MimeDict.fromString(header + "\r\n" + body)
self.assertEqual(x["Header"], value)
示例8: test_fromString_HeaderWithContinuationLines_AllCaptured_One
def test_fromString_HeaderWithContinuationLines_AllCaptured_One(self):
"fromString - A header with a continuation line is captured as a single string"
value = "Twinkle Twinkle Little Start\r\n How I wonder what you are"
header = "Header: " + value + "\r\n"
body = ""
x = MimeDict.fromString(header + "\r\n" + body)
self.assertEqual(x["Header"], value)
示例9: test_fromString_HeaderMustBeFollowedByEmptyLine_NonEmptyBody
def test_fromString_HeaderMustBeFollowedByEmptyLine_NonEmptyBody(self):
"""fromString - Header not followed by an empty line and non-empty body results is invalid. The result is an empty header and the original message"""
header = "Header: Twinkle Twinkle Little Star\r\n"
body = "How I wonder what you are"
message = header + "" + body # empty "divider"
x = MimeDict.fromString (message)
self.assertEqual(x["__BODY__"], message, "Invalid header results in entire being treated as an unstructured body" )
示例10: test_fromString_HeaderMustBeFollowedByEmptyLine
def test_fromString_HeaderMustBeFollowedByEmptyLine(self):
"""fromString - Header not followed by an empty line and empty body
results is invalid. The result is an empty header and the header as the
body."""
header = "Header: Twinkle Twinkle Little Star\r\n"
body = ""
x = MimeDict.fromString (header + "" + body) # empty "divider"
self.assertEqual(x["__BODY__"], header, "Invalid header results in header being treated as an unstructured body" )
示例11: test_EmbeddedNewlineInHeaderRoundtrip_fromInsertion
def test_EmbeddedNewlineInHeaderRoundtrip_fromInsertion(self):
"A header which contains a single carriage return keeps the carriage return embedded since it *isn't* a carriage return/line feed"
x = MimeDict()
x["header"] = "Hello\nWorld"
y = MimeDict.fromString(str(x))
self.assertEqual(y["__BODY__"], "")
self.assertEqual(y["header"], x["header"])
self.assertEqual(x["header"], "Hello\nWorld")
示例12: test_basicInsertion_Roundtrip
def test_basicInsertion_Roundtrip(self):
"Insertion into a dictionary, then roundtripped -- fromString(str(x)) results in original value"
x = MimeDict()
x["hello"] = ["2hello1", "2hello2"]
x["__BODY__"] = "Hello\nWorld\n"
stringified = str(x)
y = MimeDict.fromString(stringified)
self.assertEqual(x, y)
示例13: test_InformationLossRoundtrip
def test_InformationLossRoundtrip(self):
"If you put a list with a single string into a MimeDict, and try to send that across the network by itself, it will not be reconstituted as a list. This is because we have no real way of determining that the single value should or should not be a list"
x = MimeDict()
x["hello"] = ["hello"]
x["__BODY__"] = "Hello\nWorld\n"
stringified = str(x)
y = MimeDict.fromString(stringified)
self.assertNotEqual(x, y)
示例14: test___str__fromString_MultipleDifferentHeaders_NoBody
def test___str__fromString_MultipleDifferentHeaders_NoBody(self):
"performing __str__/fromString halftrip on a dict with multiple header types multiple times, no body should result in identity"
x = MimeDict(HeaderA=["value 1", "value 2", "value 3"], HeaderB=["value 4", "value 5", "value 6"])
y = MimeDict.fromString(str(x))
self.assertEqual(y, x)
self.assertEqual(y["HeaderA"], ["value 1", "value 2", "value 3"])
self.assertEqual(y["HeaderB"], ["value 4", "value 5", "value 6"])
self.assert_(x is not y)
示例15: test___str__CheckedAgainstOriginalRepeatedSingleHeaderWithContinuations
def test___str__CheckedAgainstOriginalRepeatedSingleHeaderWithContinuations(self):
"__str__ of fromString(message) checked against message for equality"
value1 = "Twinkle \r\n Twinkle"
value2 = "Little\r\n Star"
header = "Header: " + value1 + "\r\n"
header += "Header: " + value2 + "\r\n"
body = ""
message = header + "\r\n" + body
x = MimeDict.fromString(message)
self.assertEqual(str(x), message)