formatters: use weboob.tools.misc.guess_encoding instead of locale.getpreferredencoding()
Signed-off-by: Matthieu Weber <mweber+weboob@free.fr> Signed-off-by: Romain Bignon <romain@symlink.me>
This commit is contained in:
parent
5e5a8848fb
commit
1d67bf360f
2 changed files with 5 additions and 7 deletions
|
|
@ -22,7 +22,6 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import locale
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -62,7 +61,7 @@ else:
|
||||||
from weboob.capabilities.base import BaseObject
|
from weboob.capabilities.base import BaseObject
|
||||||
from weboob.tools.application.console import ConsoleApplication
|
from weboob.tools.application.console import ConsoleApplication
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
|
from weboob.tools.misc import guess_encoding
|
||||||
|
|
||||||
__all__ = ['IFormatter', 'MandatoryFieldsNotFound']
|
__all__ = ['IFormatter', 'MandatoryFieldsNotFound']
|
||||||
|
|
||||||
|
|
@ -122,7 +121,7 @@ class IFormatter(object):
|
||||||
def output(self, formatted):
|
def output(self, formatted):
|
||||||
if self.outfile != sys.stdout:
|
if self.outfile != sys.stdout:
|
||||||
with open(self.outfile, "a+") as outfile:
|
with open(self.outfile, "a+") as outfile:
|
||||||
outfile.write(formatted.encode(locale.getpreferredencoding(), errors='replace') + os.linesep)
|
outfile.write(formatted.encode(guess_encoding(outfile), errors='replace') + os.linesep)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for line in formatted.split('\n'):
|
for line in formatted.split('\n'):
|
||||||
|
|
@ -134,7 +133,7 @@ class IFormatter(object):
|
||||||
self.print_lines = 0
|
self.print_lines = 0
|
||||||
|
|
||||||
if isinstance(line, unicode):
|
if isinstance(line, unicode):
|
||||||
line = line.encode(locale.getpreferredencoding(), errors='replace')
|
line = line.encode(guess_encoding(self.outfile), errors='replace')
|
||||||
print(line)
|
print(line)
|
||||||
self.print_lines += 1
|
self.print_lines += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,10 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import locale
|
|
||||||
|
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
|
|
||||||
from weboob.capabilities.base import empty
|
from weboob.capabilities.base import empty
|
||||||
|
from weboob.tools.misc import guess_encoding
|
||||||
|
|
||||||
from .iformatter import IFormatter
|
from .iformatter import IFormatter
|
||||||
|
|
||||||
|
|
@ -41,7 +40,7 @@ class TableFormatter(IFormatter):
|
||||||
def flush(self):
|
def flush(self):
|
||||||
s = self.get_formatted_table()
|
s = self.get_formatted_table()
|
||||||
if s is not None:
|
if s is not None:
|
||||||
self.output(s.encode(locale.getpreferredencoding(), errors='replace'))
|
self.output(s.encode(guess_encoding(self.outfile), errors='replace'))
|
||||||
|
|
||||||
def get_formatted_table(self):
|
def get_formatted_table(self):
|
||||||
if len(self.queue) == 0:
|
if len(self.queue) == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue