Exemplo n.º 1
0
def force_unicode(*args, **kwargs):
    res = django_force_unicode(*args, **kwargs)

    #django not fix some "not_real_unicode" like lxml.etree._ElementUnicodeResult
    #witch is bad for mysqlDb
    if res.__class__ is not unicode:
        res = unicode(res)

    return res
Exemplo n.º 2
0
def force_unicode(msg, encodings=None):
    """Attempt to decode message into unicode, using the given encodings.
    Defaults to the value of settings.IRC_INPUT_ENCODINGS. or utf-8, then
    CP1252 if settings.IRC_INPUT_ENCODINGS. is not set."""

    # Use a default if the settings is not set
    if not encodings:
        encodings = getattr(settings, 'IRC_INPUT_ENCODINGS',
                ['utf_8', 'cp1252'])
            
    if not encodings:
        raise ValueError("No input encodings specified")

    for encoding in encodings:
        try:
            return django_force_unicode(msg, encoding)
        except DjangoUnicodeDecodeError as e:
            last_exception = e
    # If we haven't returned, raise the last exception (giving up)
    raise last_exception
Exemplo n.º 3
0
def force_unicode(msg, encodings=None):
    """Attempt to decode message into unicode, using the given encodings.
    Defaults to the value of settings.IRC_INPUT_ENCODINGS. or utf-8, then
    CP1252 if settings.IRC_INPUT_ENCODINGS. is not set."""

    # Use a default if the settings is not set
    if not encodings:
        encodings = getattr(settings, 'IRC_INPUT_ENCODINGS',
                            ['utf_8', 'cp1252'])

    if not encodings:
        raise ValueError("No input encodings specified")

    for encoding in encodings:
        try:
            return django_force_unicode(msg, encoding)
        except DjangoUnicodeDecodeError as e:
            last_exception = e
    # If we haven't returned, raise the last exception (giving up)
    raise last_exception