fall back to ISO if error with UTF-8
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2918 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									83f4e5b078
								
							
						
					
					
						commit
						b16be1581a
					
				
					 1 changed files with 5 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -54,10 +54,13 @@ def toStr(value, encoding='UTF-8'):
 | 
			
		|||
        return value.encode(encoding)
 | 
			
		||||
    return str(value)
 | 
			
		||||
 | 
			
		||||
def toUnicode(value, encoding='UTF-8'):
 | 
			
		||||
def toUnicode(value, encoding='UTF-8', fallback='ISO8859-15'):
 | 
			
		||||
    if isinstance(value, unicode):
 | 
			
		||||
        return value
 | 
			
		||||
    elif isinstance(value, str):
 | 
			
		||||
        try:
 | 
			
		||||
            return value.decode(encoding)
 | 
			
		||||
        except UnicodeDecodeError:
 | 
			
		||||
            return value.decode(fallback)
 | 
			
		||||
    else:
 | 
			
		||||
        return u''
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue