/pidgin/main: a6f8c7cbdb24: Ensure backwards compatibility with ...
Dani?l van Eeden
hg at myname.nl
Wed Dec 23 23:30:28 EST 2015
Changeset: a6f8c7cbdb24eb7113268beede61db120f940917
Author: Dani?l van Eeden <hg at myname.nl>
Date: 2015-07-12 18:16 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/a6f8c7cbdb24
Description:
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 at example.com
$ python3.4 libpurple/purple-url-handler xmpp:bar at example.com
diffstat:
libpurple/purple-url-handler | 49 +++++++++++++++++++++++--------------------
1 files changed, 26 insertions(+), 23 deletions(-)
diffs (177 lines):
diff --git a/libpurple/purple-url-handler b/libpurple/purple-url-handler
--- a/libpurple/purple-url-handler
+++ b/libpurple/purple-url-handler
@@ -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 @@ def aim(uri):
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 @@ def gg(uri):
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 @@ def icq(uri):
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 @@ def irc(uri):
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 @@ def irc(uri):
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 @@ def irc(uri):
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 @@ def msnim(uri):
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 @@ def sip(uri):
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 @@ def xmpp(uri):
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 @@ def xmpp(uri):
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 @@ def gtalk(uri):
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 @@ def ymsgr(uri):
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)
More information about the Commits
mailing list