1.1 --- a/vContent.py Sat Jan 31 23:00:27 2015 +0100
1.2 +++ b/vContent.py Sat Jan 31 23:01:22 2015 +0100
1.3 @@ -4,7 +4,7 @@
1.4 Parsing of vCard, vCalendar and iCalendar files.
1.5
1.6 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011, 2013,
1.7 - 2014 Paul Boddie <paul@boddie.org.uk>
1.8 + 2014, 2015 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -613,13 +613,19 @@
1.13
1.14 def get_input_stream(stream_or_string, encoding=None):
1.15 if is_input_stream(stream_or_string):
1.16 - return stream_or_string
1.17 + if isinstance(stream_or_string, codecs.StreamReader):
1.18 + return stream_or_string
1.19 + else:
1.20 + return codecs.getreader(encoding or default_encoding)(stream_or_string)
1.21 else:
1.22 return codecs.open(stream_or_string, encoding=(encoding or default_encoding))
1.23
1.24 def get_output_stream(stream_or_string, encoding=None):
1.25 if hasattr(stream_or_string, "write"):
1.26 - return stream_or_string
1.27 + if isinstance(stream_or_string, codecs.StreamWriter):
1.28 + return stream_or_string
1.29 + else:
1.30 + return codecs.getwriter(encoding or default_encoding)(stream_or_string)
1.31 else:
1.32 return codecs.open(stream_or_string, "w", encoding=(encoding or default_encoding))
1.33