From 823e2b32ebe1d64bfebd19e0d45c7212ebd88345 Mon Sep 17 00:00:00 2001 From: James Douglass Date: Mon, 1 Jun 2015 16:25:22 -0700 Subject: [PATCH] Using preferred encoding instead of UTF-8 Updates issue #2. --- dbfpy3/fields.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbfpy3/fields.py b/dbfpy3/fields.py index 883d035..9257560 100644 --- a/dbfpy3/fields.py +++ b/dbfpy3/fields.py @@ -33,6 +33,7 @@ import datetime import struct import sys +import locale from . import utils @@ -125,7 +126,7 @@ def fromString(cls, string, start, ignoreErrors=False): """ assert len(string) == 32 _length = string[16] - return cls(utils.unzfill(string)[:11].decode('utf-8'), _length, + return cls(utils.unzfill(string)[:11].decode(locale.getpreferredencoding()), _length, string[17], start, start + _length, ignoreErrors=ignoreErrors) fromString = classmethod(fromString) @@ -209,7 +210,7 @@ def decodeValue(self, value): Return value is a ``value`` argument with stripped right spaces. """ - return value.rstrip(b' ').decode('utf-8') + return value.rstrip(b' ').decode(locale.getpreferredencoding()) def encodeValue(self, value): """Return raw data string encoded from a ``value``."""