Author: bree Date: Fri Mar 10 08:00:04 2006 New Revision: 2568 Added: azax/branches/plugin/unicode_quirks.py Log: Forgot to add this file.
Added: azax/branches/plugin/unicode_quirks.py ============================================================================== --- (empty file) +++ azax/branches/plugin/unicode_quirks.py Fri Mar 10 08:00:04 2006 @@ -0,0 +1,14 @@ + +class AzaxUnicodeError(RuntimeError): + pass + +def force_unicode(value, encoding='ascii'): + 'Force value to be unicode - allow also value in a specific encoding (by default, ascii).' + if isinstance(value, str): + try: + value = unicode(value, encoding) + except UnicodeDecodeError, exc: + raise AzaxUnicodeError, 'Content must be unicode or ascii string, original exception: %s' % (exc, ) + else: + assert isinstance(value, unicode) + return value -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins