src/cm/utils/string_utils.py
author Simon Descarpentries <sid@sopinspace.com>
Fri, 20 Sep 2013 16:28:40 +0200
changeset 536 0c625ce49a81
parent 236 725653080973
permissions -rw-r--r--
- updating jQuery (1.3.2 -> 1.10.2), jQuery UI, jQuery modules - [text_view_frame.html] Add some JS driven CSS tricks for iPad - [text_view_frame.html] move throbber's hiding-call in nested text_view_comments iframe onload signal (so it works with jQuery 1.10.2 and the hiding timing is good) - [text_view_frame.html][base.html] factorize req_yui.html et req_jquery.html - [main_tabs][text_tabs][f_client-min.js] rewrite jQuery UI Tabs API calls select in active - [base.css] CSS fix grey frame appearence for all tabs - hg remove bgiframe -> not loaded in templates anymore - hg remove header_custom.html -> the file has been empty since 4 years - hg remove controls.html -> the file has been empty since 4 years

import chardet
import re

def to_unicode(input):
    if type(input) == str:
        res = None
        encodings = ['utf8', 'latin1']
        doc_enc = chardet.detect(input)['encoding']
        if doc_enc:
            encodings = [doc_enc,] + encodings  
        for encoding in encodings:
            try:
                res = unicode(input, encoding)
                break;
            except UnicodeDecodeError:
                pass
        if not res:
            raise Exception('UnicodeDecodeError: could not decode')
        return res
    return input

# strip carriage returns
def strip_cr(input):
    return re.sub('\r\n|\r|\n', '\n', input)