/pidgin/main: 78408ad717bd: Make purlpe-url-handler work with Py...
Dani?l van Eeden
hg at myname.nl
Wed Dec 23 23:30:28 EST 2015
Changeset: 78408ad717bd22ac6d3e5ff2a03c0a9af873d7a3
Author: Dani?l van Eeden <hg at myname.nl>
Date: 2015-07-09 07:35 +0200
Branch: release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/78408ad717bd
Description:
Make purlpe-url-handler work with Python 3
- use print as function
- new exception syntax
- chang in urllib unquote
(grafted from 0a113082ec3a71c9670deab19b03a598192c8f9d)
diffstat:
libpurple/purple-url-handler | 80 ++++++++++++++++++++++----------------------
1 files changed, 40 insertions(+), 40 deletions(-)
diffs (256 lines):
diff --git a/libpurple/purple-url-handler b/libpurple/purple-url-handler
--- a/libpurple/purple-url-handler
+++ b/libpurple/purple-url-handler
@@ -1,19 +1,19 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import dbus
import re
import sys
import time
-import urllib
+import urllib.parse
bus = dbus.SessionBus()
obj = None
try:
obj = bus.get_object("im.pidgin.purple.PurpleService",
"/im/pidgin/purple/PurpleObject")
-except dbus.DBusException, e:
+except dbus.DBusException as e:
if e._dbus_error_name == "org.freedesktop.DBus.Error.ServiceUnknown":
- print "Error: no libpurple-powered client is running. Try starting Pidgin or Finch."
+ print("Error: no libpurple-powered client is running. Try starting Pidgin or Finch.")
sys.exit(1)
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
@@ -59,7 +59,7 @@ def convert(value):
return value
def account_not_found():
- print "No matching account found."
+ print("No matching account found.")
sys.exit(1)
def bring_account_online(account):
@@ -122,16 +122,16 @@ def aim(uri):
protocol = "prpl-aim"
match = re.match(r"^aim:([^?]*)(\?(.*))", uri)
if not match:
- print "Invalid aim URI: %s" % uri
+ print("Invalid aim URI: %s" % uri)
return
- command = urllib.unquote_plus(match.group(1))
+ command = urllib.parse.unquote(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.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
accountname = params.get("account", "")
screenname = params.get("screenname", "")
@@ -148,10 +148,10 @@ def gg(uri):
protocol = "prpl-gg"
match = re.match(r"^gg:(.*)", uri)
if not match:
- print "Invalid gg URI: %s" % uri
+ print("Invalid gg URI: %s" % uri)
return
- screenname = urllib.unquote_plus(match.group(1))
+ screenname = urllib.parse.unquote(match.group(1))
account = findaccount(protocol)
goim(account, screenname)
@@ -159,16 +159,16 @@ def icq(uri):
protocol = "prpl-icq"
match = re.match(r"^icq:([^?]*)(\?(.*))", uri)
if not match:
- print "Invalid icq URI: %s" % uri
+ print("Invalid icq URI: %s" % uri)
return
- command = urllib.unquote_plus(match.group(1))
+ command = urllib.parse.unquote(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.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
accountname = params.get("account", "")
screenname = params.get("screenname", "")
@@ -185,10 +185,10 @@ def irc(uri):
protocol = "prpl-irc"
match = re.match(r"^irc:(//([^/]*))?/?([^?]*)(\?(.*))?", uri)
if not match:
- print "Invalid irc URI: %s" % uri
+ print("Invalid irc URI: %s" % uri)
return
- server = urllib.unquote_plus(match.group(2) or "")
+ server = urllib.parse.unquote(match.group(2) or "")
target = match.group(3) or ""
query = match.group(5) or ""
@@ -204,7 +204,7 @@ def irc(uri):
if paramstring:
for param in paramstring.split("&"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
def correct_server(account):
username = cpurple.PurpleAccountGetUsername(account)
@@ -214,9 +214,9 @@ def irc(uri):
if (target != ""):
if (isnick):
- goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg"))
+ goim(account, urllib.parse.unquote(target.split(",")[0]), params.get("msg"))
else:
- channel = urllib.unquote_plus(target.split(",")[0])
+ channel = urllib.parse.unquote(target.split(",")[0])
if channel[0] != "#":
channel = "#" + channel
gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
@@ -225,16 +225,16 @@ def msnim(uri):
protocol = "prpl-msn"
match = re.match(r"^msnim:([^?]*)(\?(.*))", uri)
if not match:
- print "Invalid msnim URI: %s" % uri
+ print("Invalid msnim URI: %s" % uri)
return
- command = urllib.unquote_plus(match.group(1))
+ command = urllib.parse.unquote(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.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
screenname = params.get("contact", "")
account = findaccount(protocol)
@@ -253,10 +253,10 @@ def sip(uri):
protocol = "prpl-simple"
match = re.match(r"^sip:(.*)", uri)
if not match:
- print "Invalid sip URI: %s" % uri
+ print("Invalid sip URI: %s" % uri)
return
- screenname = urllib.unquote_plus(match.group(1))
+ screenname = urllib.parse.unquote(match.group(1))
account = findaccount(protocol)
goim(account, screenname)
@@ -264,20 +264,20 @@ def xmpp(uri):
protocol = "prpl-jabber"
match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri)
if not match:
- print "Invalid xmpp URI: %s" % uri
+ print("Invalid xmpp URI: %s" % uri)
return
tmp = match.group(2)
if (tmp):
- accountname = urllib.unquote_plus(tmp)
+ accountname = urllib.parse.unquote(tmp)
else:
accountname = ""
- screenname = urllib.unquote_plus(match.group(3))
+ screenname = urllib.parse.unquote(match.group(3))
tmp = match.group(5)
if (tmp):
- command = urllib.unquote_plus(tmp)
+ command = urllib.parse.unquote(tmp)
else:
command = ""
@@ -286,7 +286,7 @@ def xmpp(uri):
if paramstring:
for param in paramstring.split(";"):
key, value = extendlist(param.split("=", 1), 2, "")
- params[key] = urllib.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
account = findaccount(protocol, accountname)
@@ -304,16 +304,16 @@ def gtalk(uri):
protocol = "prpl-jabber"
match = re.match(r"^gtalk:([^?]*)(\?(.*))", uri)
if not match:
- print "Invalid gtalk URI: %s" % uri
+ print("Invalid gtalk URI: %s" % uri)
return
- command = urllib.unquote_plus(match.group(1))
+ command = urllib.parse.unquote(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.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
accountname = params.get("from_jid", "")
jid = params.get("jid", "")
@@ -329,17 +329,17 @@ def ymsgr(uri):
protocol = "prpl-yahoo"
match = re.match(r"^ymsgr:([^?]*)(\?([^&]*)(&(.*))?)", uri)
if not match:
- print "Invalid ymsgr URI: %s" % uri
+ print("Invalid ymsgr URI: %s" % uri)
return
- command = urllib.unquote_plus(match.group(1))
- screenname = urllib.unquote_plus(match.group(3))
+ command = urllib.parse.unquote(match.group(1))
+ screenname = urllib.parse.unquote(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.unquote_plus(value)
+ params[key] = urllib.parse.unquote(value)
account = findaccount(protocol)
@@ -353,8 +353,8 @@ def ymsgr(uri):
def main(argv=sys.argv):
if len(argv) != 2 or argv[1] == "--help" or argv[1] == "-h":
- print "Usage: %s URI" % argv[0]
- print "Example: %s \"xmpp:romeo at montague.net?message\"" % argv[0]
+ print("Usage: %s URI" % argv[0])
+ print("Example: %s \"xmpp:romeo at montague.net?message\"" % argv[0])
if len(argv) != 2:
sys.exit(1)
@@ -386,9 +386,9 @@ def main(argv=sys.argv):
elif type == "ymsgr":
ymsgr(uri)
else:
- print "Unknown protocol: %s" % type
- except dbus.DBusException, e:
- print "Error: %s" % (e.message)
+ print("Unknown protocol: %s" % type)
+ except dbus.DBusException as e:
+ print("Error: %s" % e.message)
sys.exit(1)
if __name__ == "__main__":
More information about the Commits
mailing list