libpurple/purple-url-handler

Wed, 05 Sep 2007 22:32:14 +0000

author
Andreas Monitzer <am@adiumx.com>
date
Wed, 05 Sep 2007 22:32:14 +0000
branch
soc.2007.xmpp
changeset 19895
158490a51f8b
parent 17904
1128eede9349
child 22141
adb198961d72
permissions
-rwxr-xr-x

propagate from branch 'im.pidgin.pidgin' (head 0853a065e5c3fcb5a6bb13fc23bec44ecf510ecd)
to branch 'im.pidgin.soc.2007.xmpp' (head b273d0db2bdd4a80d0fb22d32fe186e1f496933f)

14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
1 #!/usr/bin/python
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
2
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
3 import dbus
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
4 import re
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
5 import sys
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
6 import time
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
7 import urllib
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
8
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
9 obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
10 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
11
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
12 class CheckedObject:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
13 def __init__(self, obj):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
14 self.obj = obj
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
15
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
16 def __getattr__(self, attr):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
17 return CheckedAttribute(self, attr)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
18
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
19 class CheckedAttribute:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
20 def __init__(self, cobj, attr):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
21 self.cobj = cobj
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
22 self.attr = attr
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
23
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
24 def __call__(self, *args):
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
25 # Redirect stderr to suppress the printing of an " Introspect error"
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
26 # message if nothing is listening on the bus. We print a friendly
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
27 # error message ourselves.
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
28 real_stderr = sys.stderr
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
29 sys.stderr = None
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
30 result = self.cobj.obj.__getattr__(self.attr)(*args)
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
31 sys.stderr = real_stderr
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
32
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
33 # This can be useful for debugging.
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
34 # if (result == 0):
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
35 # print "Error: " + self.attr + " " + str(args) + " returned " + str(result)
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
36
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
37 return result
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
38
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
39 cpurple = CheckedObject(purple)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
40
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
41 def extendlist(list, length, fill):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
42 if len(list) < length:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
43 return list + [fill] * (length - len(list))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
44 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
45 return list
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
46
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
47 def convert(value):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
48 try:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
49 return int(value)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
50 except:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
51 return value
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
52
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
53 def findaccount(protocolname, accountname=""):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
54 # prefer connected accounts
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
55 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
56 if (account != 0):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
57 return account
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
58
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
59 # try to get any account and connect it
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
60 account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
61 if (account == 0):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
62 print "No matching account found."
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
63 sys.exit(1)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
64
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
65 purple.PurpleAccountSetStatusVargs(account, "online", 1)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
66 purple.PurpleAccountConnect(account)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
67 return account
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
68
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
69 def goim(account, screenname, message=None):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
70 # XXX: 1 == PURPLE_CONV_TYPE_IM
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
71 conversation = cpurple.PurpleConversationNew(1, account, screenname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
72 if message:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
73 purple.PurpleConvSendConfirm(conversation, message)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
74
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
75 def gochat(account, params, message=None):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
76 connection = cpurple.PurpleAccountGetConnection(account)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
77 purple.ServJoinChat(connection, params)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
78
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
79 if message != None:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
80 for i in range(20):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
81 # XXX: 2 == PURPLE_CONV_TYPE_CHAT
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
82 conversation = purple.PurpleFindConversationWithAccount(2, params.get("channel", params.get("room")), account)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
83 if conversation:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
84 purple.PurpleConvSendConfirm(conversation, message)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
85 break
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
86 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
87 time.sleep(0.5)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
88
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
89 def addbuddy(account, screenname, group="", alias=""):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
90 cpurple.PurpleBlistRequestAddBuddy(account, screenname, group, alias)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
91
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
92
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
93 def aim(uri):
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
94 protocol = "prpl-aim"
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
95 match = re.match(r"^aim:([^?]*)(\?(.*))", uri)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
96 if not match:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
97 print "Invalid aim URI: %s" % uri
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
98 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
99
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
100 command = urllib.unquote_plus(match.group(1))
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
101 paramstring = match.group(3)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
102 params = {}
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
103 if paramstring:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
104 for param in paramstring.split("&"):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
105 key, value = extendlist(param.split("=", 1), 2, "")
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
106 params[key] = urllib.unquote_plus(value)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
107 accountname = params.get("account", "")
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
108 screenname = params.get("screenname", "")
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
109
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
110 account = findaccount(protocol, accountname)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
111
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
112 if command.lower() == "goim":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
113 goim(account, screenname, params.get("message"))
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
114 elif command.lower() == "gochat":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
115 gochat(account, params)
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
116 elif command.lower() == "addbuddy":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
117 addbuddy(account, screenname, params.get("group", ""))
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
118
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
119 def gg(uri):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
120 protocol = "prpl-gg"
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
121 match = re.match(r"^gg:(.*)", uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
122 if not match:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
123 print "Invalid gg URI: %s" % uri
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
124 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
125
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
126 screenname = urllib.unquote_plus(match.group(1))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
127 account = findaccount(protocol)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
128 goim(account, screenname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
129
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
130 def icq(uri):
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
131 protocol = "prpl-icq"
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
132 match = re.match(r"^icq:([^?]*)(\?(.*))", uri)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
133 if not match:
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
134 print "Invalid icq URI: %s" % uri
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
135 return
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
136
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
137 command = urllib.unquote_plus(match.group(1))
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
138 paramstring = match.group(3)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
139 params = {}
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
140 if paramstring:
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
141 for param in paramstring.split("&"):
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
142 key, value = extendlist(param.split("=", 1), 2, "")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
143 params[key] = urllib.unquote_plus(value)
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
144 accountname = params.get("account", "")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
145 screenname = params.get("screenname", "")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
146
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
147 account = findaccount(protocol, accountname)
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
148
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
149 if command.lower() == "goim":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
150 goim(account, screenname, params.get("message"))
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
151 elif command.lower() == "gochat":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
152 gochat(account, params)
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
153 elif command.lower() == "addbuddy":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
154 addbuddy(account, screenname, params.get("group", ""))
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
155
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
156 def irc(uri):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
157 protocol = "prpl-irc"
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
158 match = re.match(r"^irc:(//([^/]*)/)?([^?]*)(\?(.*))?", uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
159 if not match:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
160 print "Invalid irc URI: %s" % uri
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
161 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
162
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
163 server = urllib.unquote_plus(match.group(2)) or ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
164 target = match.group(3) or ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
165 query = match.group(5) or ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
166
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
167 modifiers = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
168 if target:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
169 for modifier in target.split(",")[1:]:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
170 modifiers[modifier] = True
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
171
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
172 isnick = modifiers.has_key("isnick")
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
173
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
174 paramstring = match.group(5)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
175 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
176 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
177 for param in paramstring.split("&"):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
178 key, value = extendlist(param.split("=", 1), 2, "")
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
179 params[key] = urllib.unquote_plus(value)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
180
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
181 account = findaccount(protocol)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
182
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
183 if (target != ""):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
184 if (isnick):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
185 goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg"))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
186 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
187 channel = urllib.unquote_plus(target.split(",")[0])
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
188 if channel[0] != "#":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
189 channel = "#" + channel
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
190 gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
191
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
192 def msnim(uri):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
193 protocol = "prpl-msn"
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
194 match = re.match(r"^msnim:([^?]*)(\?(.*))", uri)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
195 if not match:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
196 print "Invalid msnim URI: %s" % uri
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
197 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
198
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
199 command = urllib.unquote_plus(match.group(1))
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
200 paramstring = match.group(3)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
201 params = {}
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
202 if paramstring:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
203 for param in paramstring.split("&"):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
204 key, value = extendlist(param.split("=", 1), 2, "")
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
205 params[key] = urllib.unquote_plus(value)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
206 screenname = params.get("contact", "")
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
207
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
208 account = findaccount(protocol)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
209
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
210 if command.lower() == "chat":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
211 goim(account, screenname)
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
212 elif command.lower() == "add":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
213 addbuddy(account, screenname)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
214
17904
1128eede9349 explicit merge of 'c5abad45e8a7ccb777ff38f325d074314ca27dcb'
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 17888 17323
diff changeset
215 def myim(uri):
16325
c444cb0defe2 Add stub for myim: URL handler.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 16207
diff changeset
216 protocol = "prpl-myspace"
c444cb0defe2 Add stub for myim: URL handler.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 16207
diff changeset
217 print "TODO: send uri: ", uri
c444cb0defe2 Add stub for myim: URL handler.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 16207
diff changeset
218 assert False, "Not implemented"
c444cb0defe2 Add stub for myim: URL handler.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 16207
diff changeset
219
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
220 def sip(uri):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
221 protocol = "prpl-simple"
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
222 match = re.match(r"^sip:(.*)", uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
223 if not match:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
224 print "Invalid sip URI: %s" % uri
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
225 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
226
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
227 screenname = urllib.unquote_plus(match.group(1))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
228 account = findaccount(protocol)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
229 goim(account, screenname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
230
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
231 def xmpp(uri):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
232 protocol = "prpl-jabber"
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
233 match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
234 if not match:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
235 print "Invalid xmpp URI: %s" % uri
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
236 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
237
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
238 tmp = match.group(2)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
239 if (tmp):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
240 accountname = urllib.unquote_plus(tmp)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
241 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
242 accountname = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
243
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
244 screenname = urllib.unquote_plus(match.group(3))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
245
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
246 tmp = match.group(5)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
247 if (tmp):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
248 command = urllib.unquote_plus(tmp)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
249 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
250 command = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
251
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
252 paramstring = match.group(7)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
253 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
254 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
255 for param in paramstring.split(";"):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
256 key, value = extendlist(param.split("=", 1), 2, "")
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
257 params[key] = urllib.unquote_plus(value)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
258
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
259 account = findaccount(protocol, accountname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
260
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
261 if command.lower() == "message":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
262 goim(account, screenname, params.get("body"))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
263 elif command.lower() == "join":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
264 room, server = screenname.split("@")
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
265 gochat(account, {"room": room, "server": server})
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
266 elif command.lower() == "roster":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
267 addbuddy(account, screenname, params.get("group", ""), params.get("name", ""))
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
268 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
269 goim(account, screenname)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
270
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
271 def ymsgr(uri):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
272 protocol = "prpl-yahoo"
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
273 match = re.match(r"^ymsgr:([^?]*)(\?([^&]*)(&(.*))?)", uri)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
274 if not match:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
275 print "Invalid ymsgr URI: %s" % uri
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
276 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
277
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
278 command = urllib.unquote_plus(match.group(1))
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
279 screenname = urllib.unquote_plus(match.group(3))
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
280 paramstring = match.group(5)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
281 params = {}
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
282 if paramstring:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
283 for param in paramstring.split("&"):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
284 key, value = extendlist(param.split("=", 1), 2, "")
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
285 params[key] = urllib.unquote_plus(value)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
286
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
287 account = findaccount(protocol)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
288
14601
8aa717885b14 [gaim-migrate @ 17260]
Richard Laager <rlaager@pidgin.im>
parents: 14597
diff changeset
289 if command.lower() == "sendim":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
290 goim(account, screenname, params.get("m"))
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
291 elif command.lower() == "chat":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
292 gochat(account, {"room": screenname})
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
293 elif command.lower() == "addfriend":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
294 addbuddy(account, screenname)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
295
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
296
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
297 def main(argv=sys.argv):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
298 if len(argv) != 2:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
299 print "Usage: %s URI" % argv[0]
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
300 print "Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0]
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
301 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
302
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
303 uri = argv[1]
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
304 type = uri.split(":")[0]
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
305
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
306 try:
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
307 if type == "aim":
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
308 aim(uri)
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
309 elif type == "gg":
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
310 gg(uri)
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
311 elif type == "icq":
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
312 icq(uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
313 elif type == "irc":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
314 irc(uri)
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
315 elif type == "msnim":
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
316 msnim(uri)
16325
c444cb0defe2 Add stub for myim: URL handler.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 16207
diff changeset
317 elif type == "myim":
17904
1128eede9349 explicit merge of 'c5abad45e8a7ccb777ff38f325d074314ca27dcb'
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 17888 17323
diff changeset
318 myim(uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
319 elif type == "sip":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
320 sip(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
321 elif type == "xmpp":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
322 xmpp(uri)
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
323 elif type == "ymsgr":
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
324 ymsgr(uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
325 else:
17904
1128eede9349 explicit merge of 'c5abad45e8a7ccb777ff38f325d074314ca27dcb'
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 17888 17323
diff changeset
326 print "Unknown protocol: %s" % type
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
327 except dbus.dbus_bindings.DBusException:
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
328 print "ERROR: Is there a libpurple-powered client (e.g. Pidgin or Finch) running?"
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
329
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
330
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
331 if __name__ == "__main__":
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
332 main()

mercurial