aboutsummaryrefslogtreecommitdiffstats
path: root/misc/xml
diff options
context:
space:
mode:
Diffstat (limited to 'misc/xml')
-rwxr-xr-xmisc/xml/be-mail-to-xml6
-rwxr-xr-xmisc/xml/be-xml-to-mbox12
2 files changed, 10 insertions, 8 deletions
diff --git a/misc/xml/be-mail-to-xml b/misc/xml/be-mail-to-xml
index 0b33465..5a1a88f 100755
--- a/misc/xml/be-mail-to-xml
+++ b/misc/xml/be-mail-to-xml
@@ -23,20 +23,17 @@ followed by a blank line.
"""
import base64
-import codecs
import email.utils
from libbe.util.encoding import get_output_encoding
from libbe.util.utility import time_to_str
import mailbox # the mailbox people really want an on-disk copy
import optparse
-import sys
from time import asctime, gmtime, mktime
import types
from xml.sax.saxutils import escape
BREAK = u'--' # signature separator
DEFAULT_ENCODING = get_output_encoding()
-sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout)
KNOWN_IDS = []
@@ -172,4 +169,7 @@ def main(argv):
if __name__ == "__main__":
import sys
+ import codecs
+
+ sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout)
main(sys.argv)
diff --git a/misc/xml/be-xml-to-mbox b/misc/xml/be-xml-to-mbox
index 34d0aa3..015444e 100755
--- a/misc/xml/be-xml-to-mbox
+++ b/misc/xml/be-xml-to-mbox
@@ -25,10 +25,9 @@ followed by a blank line.
"""
#from mailbox import mbox, Message # the mailbox people really want an on-disk copy
-import codecs
import email.utils
-from libbe.encoding import get_encoding, set_IO_stream_encodings
-from libbe.utility import str_to_time as rfc2822_to_gmtime_integer
+from libbe.util.encoding import get_output_encoding
+from libbe.util.utility import str_to_time as rfc2822_to_gmtime_integer
from time import asctime, gmtime
import types
try: # import core module, Python >= 2.5
@@ -40,8 +39,7 @@ from xml.sax.saxutils import unescape
DEFAULT_DOMAIN = "invalid.com"
DEFAULT_EMAIL = "dummy@" + DEFAULT_DOMAIN
-DEFAULT_ENCODING = get_encoding()
-set_IO_stream_encodings(DEFAULT_ENCODING)
+DEFAULT_ENCODING = get_output_encoding()
def rfc2822_to_asctime(rfc2822_string):
"""Convert an RFC 2822-fomatted string into a asctime string.
@@ -197,7 +195,11 @@ def print_to_mbox(element):
print_to_mbox(elt)
if __name__ == "__main__":
+ import codecs
import sys
+
+ sys.stdin = codecs.getreader(DEFAULT_ENCODING)(sys.stdin)
+ sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout)
if len(sys.argv) == 1: # no filename given, use stdin
xml_unicode = sys.stdin.read()