Support tinyifiers with UTF-8 results
authorLaurent Bachelier <laurent@bachelier.name>
Tue, 23 Oct 2012 04:48:21 +0000 (06:48 +0200)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 25 Oct 2012 20:35:38 +0000 (16:35 -0400)
This does not change anything for tinyurl (the default), but allows
using http://tinyarro.ws/api-create.php?utfpure=1&url=
In case invalid characters are encountered, fall back to str.

Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
irkerhook.py

index 8e1a88ecfc465cccbd0c7317ac10493e4d9e0345..f79ef5f01dbba4458831cef04da3203a80cc5821 100755 (executable)
@@ -76,6 +76,10 @@ class Commit:
                         # Didn't get a retrieval error or 404 on the web
                         # view, so try to tinyify a reference to it.
                         self.url = open(urllib.urlretrieve(self.tinyifier + webview)[0]).read()
+                        try:
+                            self.url = self.url.decode('UTF-8')
+                        except UnicodeError:
+                            pass
                     except IOError:
                         self.url = webview
                 else: