pidgin/pidgin

Ensure backwards compatibility with Python 2

2015-07-12, Daniƫl van Eeden
a6f8c7cbdb24
Parents 0a113082ec3a
Children 23aa214a723e
Ensure backwards compatibility with Python 2

Use python (which often defaults to python 2.x) instead of forcing python2
Also make it compatible with python 2.7 and 3.4

Tested with:
$ python2.7 libpurple/purple-url-handler xmpp:foo@example.com
$ python3.4 libpurple/purple-url-handler xmpp:bar@example.com
--- a/libpurple/purple-url-handler Thu Jul 09 07:35:21 2015 +0200
+++ b/libpurple/purple-url-handler Sun Jul 12 18:16:36 2015 +0200
@@ -1,10 +1,13 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
import dbus
import re
import sys
import time
-import urllib.parse
+try:
+ from urllib.parse import unquote_plus
+except ImportError:
+ from urllib import unquote_plus
bus = dbus.SessionBus()
obj = None
@@ -125,13 +128,13 @@
print("Invalid aim URI: %s" % uri)
return
- command = urllib.parse.unquote(match.group(1))
+ command = unquote_plus(match.group(1))
paramstring = match.group(3)
params = {}
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
accountname = params.get("account", "")
screenname = params.get("screenname", "")
@@ -151,7 +154,7 @@
print("Invalid gg URI: %s" % uri)
return
- screenname = urllib.parse.unquote(match.group(1))
+ screenname = unquote_plus(match.group(1))
account = findaccount(protocol)
goim(account, screenname)
@@ -162,13 +165,13 @@
print("Invalid icq URI: %s" % uri)
return
- command = urllib.parse.unquote(match.group(1))
+ command = unquote_plus(match.group(1))
paramstring = match.group(3)
params = {}
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
accountname = params.get("account", "")
screenname = params.get("screenname", "")
@@ -188,7 +191,7 @@
print("Invalid irc URI: %s" % uri)
return
- server = urllib.parse.unquote(match.group(2) or "")
+ server = unquote_plus(match.group(2) or "")
target = match.group(3) or ""
query = match.group(5) or ""
@@ -204,7 +207,7 @@
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
def correct_server(account):
username = cpurple.PurpleAccountGetUsername(account)
@@ -214,9 +217,9 @@
if (target != ""):
if (isnick):
- goim(account, urllib.parse.unquote(target.split(",")[0]), params.get("msg"))
+ goim(account, unquote_plus(target.split(",")[0]), params.get("msg"))
else:
- channel = urllib.parse.unquote(target.split(",")[0])
+ channel = unquote_plus(target.split(",")[0])
if channel[0] != "#":
channel = "#" + channel
gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
@@ -228,13 +231,13 @@
print("Invalid msnim URI: %s" % uri)
return
- command = urllib.parse.unquote(match.group(1))
+ command = unquote_plus(match.group(1))
paramstring = match.group(3)
params = {}
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
screenname = params.get("contact", "")
account = findaccount(protocol)
@@ -251,7 +254,7 @@
print("Invalid sip URI: %s" % uri)
return
- screenname = urllib.parse.unquote(match.group(1))
+ screenname = unquote_plus(match.group(1))
account = findaccount(protocol)
goim(account, screenname)
@@ -264,15 +267,15 @@
tmp = match.group(2)
if (tmp):
- accountname = urllib.parse.unquote(tmp)
+ accountname = unquote_plus(tmp)
else:
accountname = ""
- screenname = urllib.parse.unquote(match.group(3))
+ screenname = unquote_plus(match.group(3))
tmp = match.group(5)
if (tmp):
- command = urllib.parse.unquote(tmp)
+ command = unquote_plus(tmp)
else:
command = ""
@@ -281,7 +284,7 @@
if paramstring:
for param in paramstring.split(";"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
account = findaccount(protocol, accountname)
@@ -302,13 +305,13 @@
print("Invalid gtalk URI: %s" % uri)
return
- command = urllib.parse.unquote(match.group(1))
+ command = unquote_plus(match.group(1))
paramstring = match.group(3)
params = {}
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
accountname = params.get("from_jid", "")
jid = params.get("jid", "")
@@ -327,14 +330,14 @@
print("Invalid ymsgr URI: %s" % uri)
return
- command = urllib.parse.unquote(match.group(1))
- screenname = urllib.parse.unquote(match.group(3))
+ command = unquote_plus(match.group(1))
+ screenname = unquote_plus(match.group(3))
paramstring = match.group(5)
params = {}
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.parse.unquote(value)
+ params[key] = unquote_plus(value)
account = findaccount(protocol)