Home Download Buy Blog Forum Support

Encoding issues in plugin

Encoding issues in plugin

Postby silverkors on Mon Oct 10, 2011 8:07 pm

Hi!

I've made a plugin that takes a search query in a input panel, does a google search for that and returns a quick panel with the 10 first results. It then runs a snippet, on your selected text, with the result you picked, in markdown.

It works wonderfully, except I need to encode the google-result as pure ASCII for the quick panel to accept the input. Which is non-optimal for me, as I am swedish, and really like to have my å, ä and ö:s to stay in their respective places in the link title.

Is there something I've missed or is it possible that ST2 will have support for utf-8 in the quick panel in the future?

Anyhow, I really really love ST2, it's a wonderful editor! :D
silverkors
 
Posts: 2
Joined: Mon Oct 10, 2011 7:58 pm

Re: Encoding issues in plugin

Postby bizoo on Tue Oct 11, 2011 8:08 am

ST2 API use unicode string.
It's your job to convert your string to unicode otherwise Python try to decode it as ASCII, it's probably your problem here.
Code: Select all
myunistr = myutf8str.decode('utf8')
myunistr = "Planète".decode('utf8')

Replace myutf8str with your string and 'utf8' with the encoding of your string.
bizoo
 
Posts: 883
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Encoding issues in plugin

Postby silverkors on Tue Oct 11, 2011 10:11 am

Thank you bizoo!

You were totally right, just removing the encode-methods made it work, it was already unicode strings :D

Anyone know if there is interest in including this plugin in the Package Control-repository?
silverkors
 
Posts: 2
Joined: Mon Oct 10, 2011 7:58 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests