annotate libpurple/purple-url-handler @ 19277:f821d4bffb0a

propagate from branch 'im.pidgin.pidgin' (head 37793415aab363acafa9ca7ce5a76c974dbc6c4c) to branch 'im.pidgin.soc.2007.xmpp' (head c9129cb5ffdd67387b55d418b79fd8c2b6665f55)
author Evan Schoenberg <evan.s@dreskin.net>
date Tue, 14 Aug 2007 22:00:24 +0000
parents 5059a0a071a2
children 8a7238fb7905
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
1 #!/usr/bin/python
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
2
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
3 import dbus
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
4 import re
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
5 import sys
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
6 import time
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
7 import urllib
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
8
16143
598b1b15b199 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@wiktel.com>
parents: 15885
diff changeset
9 obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
598b1b15b199 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@wiktel.com>
parents: 15885
diff changeset
10 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
11
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
12 class CheckedObject:
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
13 def __init__(self, obj):
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
14 self.obj = obj
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
15
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
16 def __getattr__(self, attr):
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
17 return CheckedAttribute(self, attr)
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
18
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
19 class CheckedAttribute:
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
20 def __init__(self, cobj, attr):
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
21 self.cobj = cobj
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
22 self.attr = attr
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
23
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
24 def __call__(self, *args):
16145
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
25 # Redirect stderr to suppress the printing of an " Introspect error"
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
26 # message if nothing is listening on the bus. We print a friendly
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
27 # error message ourselves.
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
28 real_stderr = sys.stderr
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
29 sys.stderr = None
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
30 result = self.cobj.obj.__getattr__(self.attr)(*args)
16145
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
31 sys.stderr = real_stderr
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
32
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
33 # This can be useful for debugging.
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
34 # if (result == 0):
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
35 # print "Error: " + self.attr + " " + str(args) + " returned " + str(result)
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
36
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
37 return result
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
38
16143
598b1b15b199 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@wiktel.com>
parents: 15885
diff changeset
39 cpurple = CheckedObject(purple)
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
40
17282
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
41 def extendlist(list, length, fill):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
42 if len(list) < length:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
43 return list + [fill] * (length - len(list))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
44 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
45 return list
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
46
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
47 def findaccount(protocolname, accountname=""):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
48 # prefer connected accounts
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
49 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
50 if (account != 0):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
51 return account
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
52
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
53 # try to get any account and connect it
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
54 account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
55 if (account == 0):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
56 print "No matching account found."
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
57 sys.exit(1)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
58
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
59 purple.PurpleAccountSetStatusVargs(account, "online", 1)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
60 purple.PurpleAccountConnect(account)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
61 return account
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
62
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
63 def goim(account, screenname, message=None):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
64 # XXX: 1 == PURPLE_CONV_TYPE_IM
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
65 conversation = cpurple.PurpleConversationNew(1, account, screenname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
66 if message:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
67 purple.PurpleConvSendConfirm(conversation, message)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
68
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
69 def gochat(account, params, message=None):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
70 connection = cpurple.PurpleAccountGetConnection(account)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
71 purple.ServJoinChat(connection, params)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
72
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
73 if message != None:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
74 for i in range(20):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
75 # XXX: 2 == PURPLE_CONV_TYPE_CHAT
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
76 conversation = purple.PurpleFindConversationWithAccount(2, params.get("channel", params.get("room")), account)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
77 if conversation:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
78 purple.PurpleConvSendConfirm(conversation, message)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
79 break
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
80 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
81 time.sleep(0.5)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
82
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
83 def addbuddy(account, screenname, group="", alias=""):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
84 cpurple.PurpleBlistRequestAddBuddy(account, screenname, group, alias)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
85
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
86
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
87 def gg(uri):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
88 protocol = "prpl-gg"
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
89 match = re.match(r"^gg:(.*)", uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
90 if not match:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
91 print "Invalid gg URI: %s" % uri
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
92 return
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
93
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
94 screenname = urllib.unquote_plus(match.group(1))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
95 account = findaccount(protocol)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
96 goim(account, screenname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
97
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
98 def irc(uri):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
99 protocol = "prpl-irc"
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
100 match = re.match(r"^irc:(//([^/]*)/)?([^?]*)(\?(.*))?", uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
101 if not match:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
102 print "Invalid irc URI: %s" % uri
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
103 return
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
104
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
105 server = urllib.unquote_plus(match.group(2)) or ""
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
106 target = match.group(3) or ""
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
107 query = match.group(5) or ""
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
108
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
109 modifiers = {}
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
110 if target:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
111 for modifier in target.split(",")[1:]:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
112 modifiers[modifier] = True
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
113
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
114 isnick = modifiers.has_key("isnick")
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
115
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
116 paramstring = match.group(5)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
117 params = {}
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
118 if paramstring:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
119 for param in paramstring.split("&"):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
120 key, value = extendlist(param.split("=", 1), 2, "")
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
121 params[key] = urllib.unquote_plus(value)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
122
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
123 account = findaccount(protocol)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
124
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
125 if (target != ""):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
126 if (isnick):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
127 goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg"))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
128 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
129 channel = urllib.unquote_plus(target.split(",")[0])
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
130 if channel[0] != "#":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
131 channel = "#" + channel
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
132 gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
133
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
134 def sip(uri):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
135 protocol = "prpl-simple"
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
136 match = re.match(r"^sip:(.*)", uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
137 if not match:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
138 print "Invalid sip URI: %s" % uri
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
139 return
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
140
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
141 screenname = urllib.unquote_plus(match.group(1))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
142 account = findaccount(protocol)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
143 goim(account, screenname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
144
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
145 def xmpp(uri):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
146 protocol = "prpl-jabber"
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
147 match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
148 if not match:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
149 print "Invalid xmpp URI: %s" % uri
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
150 return
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
151
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
152 tmp = match.group(2)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
153 if (tmp):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
154 accountname = urllib.unquote_plus(tmp)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
155 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
156 accountname = ""
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
157
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
158 screenname = urllib.unquote_plus(match.group(3))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
159
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
160 tmp = match.group(5)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
161 if (tmp):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
162 command = urllib.unquote_plus(tmp)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
163 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
164 command = ""
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
165
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
166 paramstring = match.group(7)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
167 params = {}
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
168 if paramstring:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
169 for param in paramstring.split(";"):
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
170 key, value = extendlist(param.split("=", 1), 2, "")
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
171 params[key] = urllib.unquote_plus(value)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
172
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
173 account = findaccount(protocol, accountname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
174
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
175 if command.lower() == "message":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
176 goim(account, screenname, params.get("body"))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
177 elif command.lower() == "join":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
178 room, server = screenname.split("@")
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
179 gochat(account, {"room": room, "server": server})
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
180 elif command.lower() == "roster":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
181 addbuddy(account, screenname, params.get("group", ""), params.get("name", ""))
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
182 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
183 goim(account, screenname)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
184
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
185 def main(argv=sys.argv):
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
186 if len(argv) != 2:
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
187 print "Usage: %s URI" % argv[0]
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
188 print "Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0]
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
189 return
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
190
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
191 uri = argv[1]
17282
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
192 type = uri.split(":")[0]
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
193
16145
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
194 try:
17282
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
195 if type == "gg":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
196 gg(uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
197 elif type == "irc":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
198 irc(uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
199 elif type == "sip":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
200 sip(uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
201 elif type == "xmpp":
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
202 xmpp(uri)
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
203 else:
5059a0a071a2 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <stu@nosnilmot.com>
parents: 17048
diff changeset
204 cpurple.PurpleGotProtocolHandlerUri(uri)
16145
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
205 except dbus.dbus_bindings.DBusException:
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
206 print "ERROR: Is there a libpurple-powered client (e.g. Pidgin or Finch) running?"
d06673964ff9 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@wiktel.com>
parents: 16143
diff changeset
207
15885
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
208
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
209 if __name__ == "__main__":
c6e563dfaa7a More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
210 main()