Opened 8 years ago

Closed 8 years ago

Last modified 3 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 Changed 8 years ago by andar

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

comment:2 follow-up: Changed 8 years ago by 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')
    ...

comment:3 in reply to: ↑ 2 Changed 8 years ago by andar

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 Changed 8 years ago by Cas

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 6 years ago by Cas

  • Milestone changed from 2.0.x to 2.0

comment:6 Changed 3 years ago by Cas

  • Milestone changed from 2.0 to 2.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.