diff --git a/bin/osv/fields.py b/bin/osv/fields.py index ecc4c1d4c73671019dbebe145d4c6328065fd411..a1069f8e386b04f2f700aa41b15bb7b660fb3237 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -34,6 +34,7 @@ # import string import netsvc +import sys from psycopg2 import Binary import warnings @@ -155,7 +156,7 @@ class char(_column): # we need to convert the string to a unicode object to be able # to evaluate its length (and possibly truncate it) reliably if isinstance(symb, str): - u_symb = unicode(symb, 'utf8') + u_symb = unicode(symb.replace('\xa0', '\xc2\xa0'), 'utf8') elif isinstance(symb, unicode): u_symb = symb else: diff --git a/bin/tools/__init__.py b/bin/tools/__init__.py index f188864820d5582d191e1915df8e929c1af57501..6bc7629f6c558d95e0e1b2ed73f841fcbfba1b63 100644 --- a/bin/tools/__init__.py +++ b/bin/tools/__init__.py @@ -20,6 +20,7 @@ # ############################################################################## import copy +import win32 from config import * from misc import * from convert import * diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 04a1bba0ab50f2c8a86ac6564478e24622dd66cf..9da554ffd0af5f2e8fcd81f4957e3c7654a18a3b 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -677,7 +677,11 @@ def ustr(value): if not isinstance(value, str): value = str(value) - return unicode(value, 'utf-8') + try: + return unicode(value, 'utf-8') + except: + from locale import getlocale + return unicode(value, getlocale()[1]) def exception_to_unicode(e): if hasattr(e, 'message'): diff --git a/bin/tools/translate.py b/bin/tools/translate.py index b2ef256d11afc2c53f1c73ced110aa18d47083e3..25bd39a4c76fa8cca86a1422255044c6765eba51 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -546,8 +546,8 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= 'translatable': 1, 'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')), 'time_format' : str(locale.nl_langinfo(locale.T_FMT)), - 'decimal_point' : str(locale.nl_langinfo(locale.RADIXCHAR)), - 'thousands_sep' : str(locale.nl_langinfo(locale.THOUSEP)) + 'decimal_point' : str(locale.localeconv()['decimal_point']), + 'thousands_sep' : str(locale.localeconv()['thousands_sep']), } try: diff --git a/bin/tools/win32.py b/bin/tools/win32.py new file mode 100644 index 0000000000000000000000000000000000000000..a338c3b383b58a6db365b88b7be7ac6eca7f6677 --- /dev/null +++ b/bin/tools/win32.py @@ -0,0 +1,51 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import locale +import time +import datetime + +if not hasattr(locale, 'D_FMT'): + locale.D_FMT = 1 + +if not hasattr(locale, 'T_FMT'): + locale.T_FMT = 2 + +if not hasattr(locale, 'nl_langinfo'): + def nl_langinfo(param): + if param == locale.D_FMT: + val = time.strptime('30/12/2004', '%d/%m/%Y') + dt = datetime.datetime(*val[:-2]) + format_date = dt.strftime('%x') + for x, y in [('30', '%d'),('12', '%m'),('2004','%Y'),('04', '%Y')]: + format_date = format_date.replace(x, y) + return format_date + if param == locale.T_FMT: + val = time.strptime('13:24:56', '%H:%M:%S') + dt = datetime.datetime(*val[:-2]) + format_time = dt.strftime('%X') + for x, y in [('13', '%H'),('24', '%M'),('56','%S')]: + format_time = format_time.replace(x, y) + return format_time + locale.nl_langinfo = nl_langinfo + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: