libpurple/purple-url-handler

Wed, 30 May 2007 03:55:56 +0000

author
William Ehlhardt <williamehlhardt@gmail.com>
date
Wed, 30 May 2007 03:55:56 +0000
branch
soc.2007.certmgr
changeset 17435
a42f7e095cfd
parent 17323
f92574b24329
child 17904
1128eede9349
permissions
-rwxr-xr-x

- Add documentation for the internal CipherContext struct

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
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
47 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
48 # 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
49 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
50 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
51 return account
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
52
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
53 # 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
54 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
55 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
56 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
57 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
58
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
59 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
60 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
61 return account
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
62
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
63 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
64 # 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
65 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
66 if message:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
67 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
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 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
70 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
71 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
72
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
73 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
74 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
75 # 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
76 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
77 if conversation:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
78 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
79 break
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
80 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
81 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
82
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
83 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
84 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
85
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
86
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
87 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
88 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
89 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
90 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
91 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
92 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
93
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
94 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
95 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
96 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
97
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
98 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
99 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
100 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
101 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
102 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
103 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
104
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
105 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
106 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
107 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
108
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
109 modifiers = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
110 if target:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
111 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
112 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
113
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
114 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
115
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
116 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
117 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
118 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
119 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
120 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
121 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
122
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
123 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
124
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
125 if (target != ""):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
126 if (isnick):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
127 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
128 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
129 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
130 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
131 channel = "#" + channel
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
132 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
133
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
134 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
135 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
136 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
137 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
138 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
139 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
140
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
141 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
142 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
143 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
144
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
145 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
146 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
147 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
148 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
149 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
150 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
151
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
152 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
153 if (tmp):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
154 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
155 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
156 accountname = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
157
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
158 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
159
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
160 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
161 if (tmp):
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
162 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
163 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
164 command = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
165
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
166 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
167 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
168 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
169 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
170 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
171 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
172
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
173 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
174
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
183 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
184
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
185 def main(argv=sys.argv):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
186 if len(argv) != 2:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
187 print "Usage: %s URI" % argv[0]
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
188 print "Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0]
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
189 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
190
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
191 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
192 type = uri.split(":")[0]
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
193
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
194 try:
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
195 if type == "gg":
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
196 gg(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
197 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
198 irc(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
199 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
200 sip(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
201 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
202 xmpp(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
203 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
204 cpurple.PurpleGotProtocolHandlerUri(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
205 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
206 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
207
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
208
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
209 if __name__ == "__main__":
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
210 main()

mercurial