X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=lib%2Ftesttools%2Ftesttools%2Fcontent.py;fp=lib%2Ftesttools%2Ftesttools%2Fcontent.py;h=86df09fc6e4fd2cd21a2ba8166270331a0cd2511;hb=297434055e2e2b28a2f9cacc09a30786edf8903a;hp=843133aa1aa86801add19bac1d4f8aede11a190c;hpb=e6974b0ff0100bb292d57e58ae11bc2e6b0d4053;p=nivanova%2Fsamba-autobuild%2F.git diff --git a/lib/testtools/testtools/content.py b/lib/testtools/testtools/content.py index 843133aa1aa..86df09fc6e4 100644 --- a/lib/testtools/testtools/content.py +++ b/lib/testtools/testtools/content.py @@ -5,10 +5,13 @@ import codecs from testtools.compat import _b -from testtools.content_type import ContentType +from testtools.content_type import ContentType, UTF8_TEXT from testtools.testresult import TestResult +_join_b = _b("").join + + class Content(object): """A MIME-like Content object. @@ -31,7 +34,7 @@ class Content(object): def __eq__(self, other): return (self.content_type == other.content_type and - ''.join(self.iter_bytes()) == ''.join(other.iter_bytes())) + _join_b(self.iter_bytes()) == _join_b(other.iter_bytes())) def iter_bytes(self): """Iterate over bytestrings of the serialised content.""" @@ -68,7 +71,7 @@ class Content(object): def __repr__(self): return "" % ( - self.content_type, ''.join(self.iter_bytes())) + self.content_type, _join_b(self.iter_bytes())) class TracebackContent(Content): @@ -89,3 +92,11 @@ class TracebackContent(Content): value = self._result._exc_info_to_unicode(err, test) super(TracebackContent, self).__init__( content_type, lambda: [value.encode("utf8")]) + + +def text_content(text): + """Create a `Content` object from some text. + + This is useful for adding details which are short strings. + """ + return Content(UTF8_TEXT, lambda: [text.encode('utf8')])