Bug 9545 and 9546 Vcard export on Windows problems
This commit is contained in:
@@ -397,18 +397,19 @@ def load_addon_file(path, callback=None):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class OpenFileOrStdout:
|
class OpenFileOrStdout:
|
||||||
"""Context manager to open a file or stdout for writing."""
|
"""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.filename = filename
|
||||||
self.filehandle = None
|
self.filehandle = None
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
self.errors = errors
|
||||||
|
self.newline = newline
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
if self.filename == '-':
|
if self.filename == '-':
|
||||||
self.filehandle = sys.stdout
|
self.filehandle = sys.stdout
|
||||||
elif self.encoding:
|
|
||||||
self.filehandle = open(self.filename, 'w', encoding=self.encoding)
|
|
||||||
else:
|
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
|
return self.filehandle
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
@@ -148,7 +148,8 @@ class VCardWriter:
|
|||||||
|
|
||||||
def export_data(self):
|
def export_data(self):
|
||||||
"""Open the file and loop over everyone too write their VCards."""
|
"""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:
|
if self.filehandle:
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.oldval = 0
|
self.oldval = 0
|
||||||
|
Reference in New Issue
Block a user