lsantos2000 / feedjack

Automatically exported from code.google.com/p/feedjack
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

fix to encode function #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
hi Tabo..
I noticed feedjack was complaining when some of the strings were already in
UTF-8
eg...
 'Perennial Lamb\xe2\x80\x99s Ears'

this fixes that issue with a sledgehammer ;-) .. you might have a better
approach.

def encode(tstr):
    """ Encodes a unicode string in utf-8
    """
    if not tstr:
        return ''
    try:
        return tstr.encode('utf-8', "xmlcharrefreplace")
    except UnicodeDecodeError:
        # it's already UTF8.. sigh
        return tstr.decode('utf-8').encode('utf-8')

Original issue reported on code.google.com by kryton.l...@gmail.com on 25 Aug 2006 at 12:18

GoogleCodeExporter commented 8 years ago
I'll have to commit this if  don't find a more elegant solution :)

Original comment by gpicon on 22 Oct 2006 at 11:50

GoogleCodeExporter commented 8 years ago

Original comment by gpicon on 22 Oct 2006 at 11:50

GoogleCodeExporter commented 8 years ago
Fixed in [17]

Original comment by gpicon on 16 Nov 2006 at 2:37