convert from utf-7 encoded text to normal text?

Walter Dörwald walter at livinglogic.de
Wed Jul 24 06:40:21 EDT 2002


Suresh Ananthan wrote:

> Hello List,
> 
>     I'm working on C/C++ platform.  I have recieved mail in the
> following format. There's utf-7(or utf-8) encoded text.
> 
> ------=_NextPart_000_0057_01C2323C.D9CAFA60
> Content-Transfer-Encoding: 7bit
> Content-Type: text/plain;
> 	charset="utf-7"
> 
> test+AEA-qa21.com+ADs- dig+AEA-qa21.com
> test+AEA-qa21.com+ADs- dig+AEA-qa21.com
>  
> 
>    I hope that this is a unicode format.  I need to convert (or)
> decode this
> string.  What algorithm i should use?  (or) any other sample program
> available for convert this unicode string to normal text?????How to
> decode
> this text to get normal chars? I'm newbie and tried some API / C RTL
> functions, but did not get correct result, so detailed answer will be
> very
> helpfull. Please...

Python 2.2.1 (#1, Apr 10 2002, 19:08:12)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> "test+AEA-qa21.com+ADs- dig+AEA-qa21.com".decode("utf-7")
u'test at qa21.com; dig at qa21.com'

And if "I'm working on C/C++ platform" means you need the
algorithms callable from C, then use the function
PyUnicode_DecodeUTF7().

If "I'm working on C/C++ platform" means your program has nothing
to do with Python, this is really the wrong newsgroup, but you
could take a look at PyUnicode_DecodeUTF7() in the Python source,
(in the file Objects/unicodeobject.c, viewable online at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/unicodeobject.c?rev=HEAD&content-type=text/vnd.viewcvs-markup
) and copy the algorithm from there.

Hope that helps,
    Walter Dörwald





More information about the Python-list mailing list