| Home | Trees | Index | Help |
|
|---|
| Package aquarium :: Package util :: Module ProtectUTF8 |
|
Temporarily convert a UTF-8 string to Unicode to prevent breakage.
WARNING: This code is duplicated! Please update both:
godspeed/godlib/protect_utf8.py godspeed/ui/webui/aquarium/aquarium/util/ProtectUTF8.py
The code needs to be duplicated because it must be used in two completely separate projects that can't share a dependency.
| Function Summary | |
|---|---|
Temporarily convert a UTF-8 string to Unicode to prevent breakage. | |
truncate(s,
*args,
**kargs)
| |
| Function Details |
|---|
protect_utf8(wrapped_function, encoding='UTF-8')Temporarily convert a UTF-8 string to Unicode to prevent breakage. protect_utf8 is a function decorator that can prevent naive functions from breaking UTF-8. If the wrapped function takes a string, and that string happens to be valid UTF-8, convert it to a unicode object and call the wrapped function. If a conversion was done and if a unicode object was returned, convert it back to a UTF-8 string. The wrapped function should take a string as its first parameter and it may return an object of the same type. Anything else is optional. For example:
def truncate(s):
return s[:1]
Pass encoding if you want to protect something other than UTF-8. Ideally, we'd have unicode objects everywhere, but sometimes life is not ideal. :) |
| Home | Trees | Index | Help |
|
|---|
| Generated by Epydoc 2.1 on Mon Jan 1 16:34:19 2007 | http://epydoc.sf.net |