From 76d552e5401df990a601f245f30f45d7c13cdd1e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 12 Jul 2009 08:38:40 -0400 Subject: Added be-mbox-to-xml. Reworked to allow "be comment" to handle unicode strings (see bug e4ed63f6-9000-4d0b-98c3-487269140141). The solution was to escape all the unicode to produce and ASCII string before calling ElementTree.XML, and then converting back to unicode afterwards. Added a unicode-containing comment to the end of bug f7ccd916-b5c7-4890-a2e3-8c8ace17ae3a so that there's a handy unicode comment for testing. XML headers (e.g. '') are now added to all xml output from be. Switched non-text/* encoding library to base64 instead of email.encoders, which makes that code in libbe/comment.py simpler. Changed libbe/mapfile.py error encoding from string_escape to unicode_escape so it can handle unicode. Everything's still untested, and be-xml-to-mbox doesn't handle unicode yet, but I felt this commit was getting a bit unwieldy ;). --- becommands/comment.py | 5 +++-- becommands/show.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'becommands') diff --git a/becommands/comment.py b/becommands/comment.py index 1e6ecd4..c4b074f 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -117,7 +117,8 @@ def execute(args, test=False): new.content_type = options.content_type else: # import XML comment [list] # read in the comments - comment_list = ElementTree.XML(body) + str_body = body.strip().encode("unicode_escape") + comment_list = ElementTree.XML(str_body) if comment_list.tag not in ["bug", "comment-list"]: raise comment.InvalidXML( comment_list, "root element must be or ") @@ -130,7 +131,7 @@ def execute(args, test=False): for child in comment_list.getchildren(): if child.tag == "comment": new = comment.Comment(bug) - new.from_xml(ElementTree.tostring(child)) + new.from_xml(unicode(ElementTree.tostring(child)).decode("unicode_escape")) if new.alt_id in ids: raise cmdutil.UserError( "Clashing comment alt_id: %s" % new.alt_id) diff --git a/becommands/show.py b/becommands/show.py index a4208c3..f700caa 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -40,6 +40,7 @@ def execute(args, test=False): Bug A >>> execute (["--xml", "a"], test=True) # doctest: +ELLIPSIS + a a @@ -70,6 +71,7 @@ def execute(args, test=False): bug = bd.bug_from_shortname(bugname) if is_comment == False: if options.dumpXML: + print '' % bd.encoding print bug.xml(show_comments=True) else: print bug.string(show_comments=True) -- cgit