How to get unicode from python to $INFO label

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bossanova808 Offline
Member+
Posts: 1,532
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #11
Unfortunately that break the entire function...the data that comes back from the server looks like:

Code:
response = self.request('status 0 %i' % amount, True)
        print "response" + str(response)
        encoded_list = response.split('playlist%20index')[1:]
        playlist = []
        for encoded in encoded_list:
            print "encoded" + encoded
            data = [self.__unquote(x) for x in ('position' + encoded).split(' ')]
            print "data" + str(data)


20:08:06 T:5232  NOTICE: response1 player_name%3ASqueezeslave player_connected%3A1 player_ip%3A192.168.1.9%3A49712 power%3A1 signalstrength%3A0 mode%3Astop time%3A0 rate%3A1 duration%3A603.826 can_seek%3A1 mixer%20volume%3A50 playlist%20repeat%3A0 playlist%20shuffle%3A0 playlist%20mode%3Aoff seq_no%3A0 playlist_cur_index%3A1 playlist_timestamp%3A1330160627.81035 playlist_tracks%3A11 playlist%20index%3A0 id%3A11144 title%3AIntro genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A100.493 playlist%20index%3A1 id%3A11145 title%3ASvefn-g-englar genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A603.826 playlist%20index%3A2 id%3A11146 title%3AStar%C3%A1lfur genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A406.933 playlist%20index%3A3 id%3A11147 title%3AFlugufrelsarinn genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A467.84 playlist%20index%3A4 id%3A11148 title%3AN%C3%BD%20batter%C3%AD genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A489.533 playlist%20index%3A5 id%3A11149 title%3AHjarta%C3%B0%20hamast%20(bamm%20bamm%20bamm) genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A430.546 playlist%20index%3A6 id%3A11150 title%3AVi%C3%B0ar%20vel%20tl%20loft%C3%A1rasa genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A617.013 playlist%20index%3A7 id%3A11151 title%3AOlsen%20Olsen genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A484.24 playlist%20index%3A8 id%3A11152 title%3A%C3%81g%C3%A6tis%20byrjun genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A474.653 playlist%20index%3A9 id%3A11153 title%3AAvalon genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A246.146 playlist%20index%3A10 id%3A19959 title%3ASvefn-G-Englar genre%3APop artist%3ASigur%20R%C3%B3s album%3AThe%20Pitchfork%20500 duration%3A604.081

20:08:06 T:5232  NOTICE: encoded%3A0 id%3A11144 title%3AIntro genre%3APop artist%3ASigur%20R%C3%B3s album%3A%C3%81g%C3%A6tis%20byrjun duration%3A100.493

20:08:06 T:5232  NOTICE: data[u'position:0', u'id:11144', u'title:Intro', u'genre:Pop', u'artist:Sigur R\xc3\xb3s', u'album:\xc3\x81g\xc3\xa6tis byrjun', u'duration:100.493', u'']
find quote
giftie Online
Skilled Python Coder
Posts: 2,042
Joined: Mar 2010
Reputation: 35
Post: #12
Found the problem.. It's a bug in the python urillib.unquote() module... -> http://bugs.python.org/issue8136.

Now to find the way to correct it...

The easiest is to modify the __unquote() in the server.py from:
Code:
def __quote(self, text):
        try:
            import urllib.parse
            return urllib.parse.quote(text, encoding=self.charset)
        except ImportError:
            import urllib
            return urllib.quote(text)

TO
Code:
def __quote(self, text):
        try:
            import urllib.parse
            return urllib.parse.quote(text, encoding=self.charset)
        except ImportError:
            #import urllib
            #return urllib.quote(text)
            if isinstance(text, unicode):
                text = text.encode('utf-8')
            res = text.split('%')
            for i in xrange(1, len(res)):
                item = res[i]
                try:
                    res[i] = _hextochr[item[:2]] + item[2:]
                except KeyError:
                    res[i] = '%' + item
                except UnicodeDecodeError:
                    res[i] = unichr(int(item[:2], 16)) + item[2:]
            return "".join(res)


This puts the patched code to fix the urllib.quote() in place of calling the urllib.quote() code.

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


find quote
bossanova808 Offline
Member+
Posts: 1,532
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #13
That looks like some amazing searching and indeed this issue...

However, you seem to have modified __quote instead of __unquote - is that right?

I tried it as __unquote (change the name and the call to __unquote) - I am currently stuck on _hextochr not being recognised....
find quote
giftie Online
Skilled Python Coder
Posts: 2,042
Joined: Mar 2010
Reputation: 35
Post: #14
bossanova808 Wrote:That looks like some amazing searching and indeed this issue...

However, you seem to have modified __quote instead of __unquote - is that right?

I tried it as __unquote (change the name and the call to __unquote) - I am currently stuck on _hextochr not being recognised....

yep my bad... It should be in the __unquote() section.

Heres the real code(found the missing _hextochr):

Code:
def __unquote(self, text):
        try:
            import urllib.parse
            return urllib.parse.unquote(text, encoding=self.charset)
        except ImportError:
            #import urllib
            #return urllib.unquote(text)
            _hexdig = '0123456789ABCDEFabcdef'
            _hextochr = dict((a+b, chr(int(a+b,16))) for a in _hexdig for b in _hexdig)
            if isinstance(text, unicode):
                text = text.encode('utf-8')
            res = text.split('%')
            for i in xrange(1, len(res)):
                item = res[i]
                try:
                    res[i] = _hextochr[item[:2]] + item[2:]
                except KeyError:
                    res[i] = '%' + item
                except UnicodeDecodeError:
                    res[i] = unichr(int(item[:2], 16)) + item[2:]
            return "".join(res)

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


find quote
bossanova808 Offline
Member+
Posts: 1,532
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #15
Give that man a cigar...

Yep, that works, and has the by-product of changing some other funky-ness in my code to something much simpler & neater.

Many many thanks mate, you went above and beyond.
find quote
giftie Online
Skilled Python Coder
Posts: 2,042
Joined: Mar 2010
Reputation: 35
Post: #16
bossanova808 Wrote:Give that man a cigar...

Yep, that works, and has the by-product of changing some other funky-ness in my code to something much simpler & neater.

Many many thanks mate, you went above and beyond.

Happy to help.. The one nice thing about python, there is usually a way to fix a bug.. ..

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


find quote
Post Reply