Opened 12 years ago

Closed 12 years ago

Last modified 6 years ago

#2225 closed patch (Fixed)

Change common.decode_string to actually decode (return unicode)

Reported by: Bro Owned by:
Priority: minor Milestone: 2.0.0
Component: Unknown Version: master
Keywords: Cc:

Description

This patch changes the decode_string so that it tries to decode the input string with different encodings, and returns the decoded output as unicode.

https://github.com/bendikro/deluge/tree/master-decode-string

Previous calls to decode_string are replaced with common.utf8_encoded

Change History (6)

comment:1 by andar, 12 years ago

Why are lambdas being used in this function? Can't encodings just be a list of tuples?

comment:2 by Bro, 12 years ago

In the first commit it was a list of tuples, but as gazpachoking commented here it's unnecessary to call chardet.detect when it's not needed.

An alternative would be a method that returns the encoding based on the input e.g:

def get_encoding(index):
    if index == 0:
        return ("utf8", 'strict')
    elif index == 1:
        return ("iso-8859-1", 'strict')
    ...

in reply to:  2 comment:3 by andar, 12 years ago

Replying to bro:

In the first commit it was a list of tuples, but as gazpachoking commented here it's unnecessary to call chardet.detect when it's not needed.

An alternative would be a method that returns the encoding based on the input e.g:

def get_encoding(index):
    if index == 0:
        return ("utf8", 'strict')
    elif index == 1:
        return ("iso-8859-1", 'strict')
    ...

Oh, I see.. The intention is to only run chardet when absolutely necessary.

Yea, there are alternatives, but using lambda works just fine in this circumstance.

comment:4 by Calum, 12 years ago

Resolution: fixed
Status: newclosed

comment:5 by Calum, 9 years ago

Milestone: 2.0.x2.0

comment:6 by Calum, 6 years ago

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.