[FIX] Unicode encoding

bzr revid: stephane@tinyerp.com-20090205234352-6wjwlcuuvm3gjv0j
This commit is contained in:
Stephane Wirtel 2009-02-06 00:43:52 +01:00
parent 9b4d0613a6
commit 736c26758b
5 changed files with 61 additions and 4 deletions

View File

@ -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:

View File

@ -20,6 +20,7 @@
#
##############################################################################
import copy
import win32
from config import *
from misc import *
from convert import *

View File

@ -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'):

View File

@ -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:

51
bin/tools/win32.py Normal file
View File

@ -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: