Did I find the right examples for you? yes no

All Samples(2)  |  Call(2)  |  Derive(0)  |  Import(0)
Try to get the stdin encoding and use it to convert the input string into unicode.
It is dependent on the platform (mac osx,linux, windows 

        def convert_to_unicode(a_str):
    """
       Try to get the stdin encoding and use it to convert the input string into unicode.
       It is dependent on the platform (mac osx,linux, windows 
    """
    #encoding can be forced from conf
    term_encoding = get_conf_defaults().get('Localisation', 'term_encoding', None)
    if not term_encoding:
        term_encoding = locale.getpreferredencoding() #use it to find the encoding for text terminal
        if not term_encoding:
            loc = locale.getdefaultlocale() #try to get defaultlocale()
            if loc and len(loc) == 2:
                term_encoding = loc[1]
            else:
                LOG.debug("Odd. loc = %s. Do not specify the encoding, let Python do its own investigation" % (loc))
    else:
        LOG.debug("Encoding forced. Read it from [Localisation]:term_encoding=%s" % (term_encoding))
        
    try: #encode
        u_str = unicode(a_str, term_encoding, errors='ignore')
           
        LOG.debug("raw unicode     = %s." % (u_str))
        LOG.debug("chosen encoding = %s." % (term_encoding))
        LOG.debug("unicode_escape val = %s." % ( u_str.encode('unicode_escape')))
    except Exception, err:
        LOG.error(err)
        get_exception_traceback()
        LOG.debug("Cannot convert to unicode from encoding:%s" % (term_encoding)) #add error
        u_str = unicode(a_str, errors='ignore')

    LOG.debug("hexval %s" % (ascii_hex(u_str)))
    
    return u_str
        


src/g/m/gmvault-HEAD/src/gmv/gmv_cmd.py   gmvault(Download)
 
            #convert args to unicode
            args['request']['req']     = gmvault_utils.convert_to_unicode(args['request']['req'])
            args['request']['charset'] = 'utf-8' #for the moment always utf-8
            args['request']['mode']    = 'custom'

src/g/m/gmvault-1.8.1-beta/src/gmv/gmv_cmd.py   gmvault(Download)
 
            #convert args to unicode
            args['request']['req']     = gmvault_utils.convert_to_unicode(args['request']['req'])
            args['request']['charset'] = 'utf-8' #for the moment always utf-8
            args['request']['mode']    = 'custom'