diff --git a/gramps/gen/plug/utils.py b/gramps/gen/plug/utils.py index f2ecfac9c..cb541a055 100644 --- a/gramps/gen/plug/utils.py +++ b/gramps/gen/plug/utils.py @@ -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): diff --git a/gramps/plugins/export/exportvcard.py b/gramps/plugins/export/exportvcard.py index ff8150a78..185dae400 100644 --- a/gramps/plugins/export/exportvcard.py +++ b/gramps/plugins/export/exportvcard.py @@ -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