Bug 9545 and 9546 Vcard export on Windows problems

This commit is contained in:
prculley 2016-06-25 10:11:30 -05:00
parent 6c67053e1f
commit 403f53cc57
2 changed files with 7 additions and 5 deletions

View File

@ -397,18 +397,19 @@ def load_addon_file(path, callback=None):
#-------------------------------------------------------------------------
class OpenFileOrStdout:
"""Context manager to open a file or stdout for writing."""
def __init__(self, filename, encoding=None):
def __init__(self, filename, encoding=None, errors=None, newline=None):
self.filename = filename
self.filehandle = None
self.encoding = encoding
self.errors = errors
self.newline = newline
def __enter__(self):
if self.filename == '-':
self.filehandle = sys.stdout
elif self.encoding:
self.filehandle = open(self.filename, 'w', encoding=self.encoding)
else:
self.filehandle = open(self.filename, 'w')
self.filehandle = open(self.filename, 'w', encoding=self.encoding,
errors=self.errors, newline=self.newline)
return self.filehandle
def __exit__(self, exc_type, exc_value, traceback):

View File

@ -148,7 +148,8 @@ class VCardWriter:
def export_data(self):
"""Open the file and loop over everyone too write their VCards."""
with OpenFileOrStdout(self.filename) as self.filehandle:
with OpenFileOrStdout(self.filename, encoding='utf-8',
errors='strict', newline='') as self.filehandle:
if self.filehandle:
self.count = 0
self.oldval = 0