libpurple/purple-url-handler

Wed, 30 Aug 2017 20:33:01 -0300

author
dx <dx@dxzone.com.ar>
date
Wed, 30 Aug 2017 20:33:01 -0300
changeset 38648
9ff9acf9fa14
parent 38358
30ba44276e74
permissions
-rwxr-xr-x

facebook: Fix "Failed to read thrift" with unknown fields in /t_p payload

>Login error: Failed to read thrift: facebook-api.c:1815
>fb_api_cb_publish_pt: assertion 'FALSE' failed

37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
1 #!/usr/bin/env python
38313
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
2
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
3 from __future__ import absolute_import, division, print_function
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
4
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
5 import dbus
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
6 import re
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
7 import sys
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
8 import time
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
9 try:
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
10 from urllib.parse import unquote_plus
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
11 except ImportError:
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
12 from urllib import unquote_plus
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
13
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
14
23562
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
15 bus = dbus.SessionBus()
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
16 obj = None
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
17 try:
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
18 obj = bus.get_object("im.pidgin.purple.PurpleService",
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
19 "/im/pidgin/purple/PurpleObject")
37443
78408ad717bd Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents: 31582
diff changeset
20 except dbus.DBusException as e:
23562
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
21 if e._dbus_error_name == "org.freedesktop.DBus.Error.ServiceUnknown":
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
22 print("Error: no libpurple-powered client is running. "
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
23 "Try starting Pidgin or Finch.")
23562
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
24 sys.exit(1)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
25 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
26
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
27
38313
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
28 class CheckedObject(object):
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
29 def __init__(self, obj):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
30 self.obj = obj
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
31
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
32 def __getattr__(self, attr):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
33 return CheckedAttribute(self, attr)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
34
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
35
38313
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
36 class CheckedAttribute(object):
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
37 def __init__(self, cobj, attr):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
38 self.cobj = cobj
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
39 self.attr = attr
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
40
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
41 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
42 # 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
43 # 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
44 # 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
45 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
46 sys.stderr = None
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
47 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
48 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
49
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
50 # This can be useful for debugging.
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
51 # if result == 0:
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
52 # print("Error:", self.attr, str(args), "returned", str(result))
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
53
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
54 return result
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
55
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
56
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
57 cpurple = CheckedObject(purple)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
58
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
59
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
60 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
61 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
62 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
63 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
64 return list
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
65
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
66
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
67 def convert(value):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
68 try:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
69 return int(value)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
70 except:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
71 return value
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
72
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
73
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
74 def account_not_found():
37443
78408ad717bd Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents: 31582
diff changeset
75 print("No matching account found.")
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
76 sys.exit(1)
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
77
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
78
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
79 def bring_account_online(account):
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
80 if not cpurple.PurpleAccountIsConnected(account):
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
81 # The last argument is meant to be a GList * but the D-Bus binding
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
82 # generator thing just wants a UInt32, which is pretty failing.
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
83 # Happily, passing a 0 to mean an empty list turns out to work anyway.
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
84 purple.PurpleAccountSetStatusList(account, "online", 1, 0)
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
85 purple.PurpleAccountConnect(account)
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
86
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
87
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
88 def findaccount(protocolname, accountname="", matcher=None):
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
89 if matcher:
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
90 for account in cpurple.PurpleAccountsGetAll():
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
91 if protocolname != cpurple.PurpleAccountGetProtocolId(account):
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
92 continue
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
93 if (accountname != "" and
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
94 accountname != cpurple.PurpleAccountGetUsername(account)):
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
95 continue
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
96 if matcher(account):
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
97 bring_account_online(account)
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
98 return account
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
99 account_not_found()
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
100
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
101 # 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
102 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
103 if account != 0:
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
104 return account
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
105
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
106 # 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
107 account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
108 if account == 0:
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
109 account_not_found()
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
110
23563
04877760aaf1 Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents: 23562
diff changeset
111 bring_account_online(account)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
112 return account
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
113
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
114
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
115 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
116 # 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
117 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
118 if message:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
119 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
120
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
121
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
122 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
123 connection = cpurple.PurpleAccountGetConnection(account)
37900
07caaa17a5a6 Fix xmpp:jid?join URIs in purple-uri-handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 37441
diff changeset
124 purple.PurpleServJoinChat(connection, params)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
125
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
126 if message is not None:
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
127 for i in range(20):
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
128 # XXX: 2 == PURPLE_CONV_TYPE_CHAT
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
129 conversation = purple.PurpleFindConversationWithAccount(
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
130 2,
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
131 params.get("channel", params.get("room")),
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
132 account)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
133 if conversation:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
134 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
135 break
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
136 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
137 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
138
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
139
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
140 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
141 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
142
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
143
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
144 def aim(uri):
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
145 protocol = "prpl-aim"
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
146 match = re.match(r"^aim:([^?]*)(\?(.*))", uri)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
147 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
148 print("Invalid aim URI: %s" % (uri, ))
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
149 return
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
150
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
151 command = unquote_plus(match.group(1))
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
152 paramstring = match.group(3)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
153 params = {}
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
154 if paramstring:
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
155 for param in paramstring.split("&"):
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
156 key, value = extendlist(param.split("=", 1), 2, "")
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
157 params[key] = unquote_plus(value)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
158 accountname = params.get("account", "")
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
159 screenname = params.get("screenname", "")
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
160
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
161 account = findaccount(protocol, accountname)
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
162
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
163 if command.lower() == "goim":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
164 goim(account, screenname, params.get("message"))
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
165 elif command.lower() == "gochat":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
166 gochat(account, params)
14597
f6b179d6babb [gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents: 14582
diff changeset
167 elif command.lower() == "addbuddy":
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
168 addbuddy(account, screenname, params.get("group", ""))
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
169
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
170
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
171 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
172 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
173 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
174 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
175 print("Invalid gg URI: %s" % (uri, ))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
176 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
177
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
178 screenname = unquote_plus(match.group(1))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
179 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
180 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
181
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
182
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
183 def icq(uri):
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
184 protocol = "prpl-icq"
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
185 match = re.match(r"^icq:([^?]*)(\?(.*))", uri)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
186 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
187 print("Invalid icq URI: %s" % (uri, ))
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
188 return
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
189
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
190 command = unquote_plus(match.group(1))
16502
a5e2a4b96d31 Ticket #320 from ltm
Richard Laager <rlaager@pidgin.im>
parents: 16207
diff changeset
191 paramstring = match.group(3)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
192 params = {}
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
193 if paramstring:
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
194 for param in paramstring.split("&"):
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
195 key, value = extendlist(param.split("=", 1), 2, "")
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
196 params[key] = unquote_plus(value)
16205
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
197 accountname = params.get("account", "")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
198 screenname = params.get("screenname", "")
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
199
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
200 account = findaccount(protocol, accountname)
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
201
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
202 if command.lower() == "goim":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
203 goim(account, screenname, params.get("message"))
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
204 elif command.lower() == "gochat":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
205 gochat(account, params)
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
206 elif command.lower() == "addbuddy":
397be242f4a4 Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents: 15987
diff changeset
207 addbuddy(account, screenname, params.get("group", ""))
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
208
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
209
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
210 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
211 protocol = "prpl-irc"
30530
8f5fecc9b6c8 Some fixes to IRC handling in purple-url-handler, mainly to fix
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 26065
diff changeset
212 match = re.match(r"^irc:(//([^/]*))?/?([^?]*)(\?(.*))?", uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
213 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
214 print("Invalid irc URI: %s" % (uri, ))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
215 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
216
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
217 server = unquote_plus(match.group(2) or "")
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
218 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
219 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
220
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
221 modifiers = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
222 if target:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
223 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
224 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
225
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
226 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
227 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
228 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
229 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
230 key, value = extendlist(param.split("=", 1), 2, "")
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
231 params[key] = unquote_plus(value)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
232
23564
9ccc8c1ddc6b Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents: 23563
diff changeset
233 def correct_server(account):
9ccc8c1ddc6b Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents: 23563
diff changeset
234 username = cpurple.PurpleAccountGetUsername(account)
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
235 return (server == "" or
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
236 "@" in username and server == username.split("@")[1])
23564
9ccc8c1ddc6b Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents: 23563
diff changeset
237
9ccc8c1ddc6b Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents: 23563
diff changeset
238 account = findaccount(protocol, matcher=correct_server)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
239
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
240 if target != "":
37985
c3bab3be9695 Remove some "clever" Python code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37984
diff changeset
241 if "isnick" in modifiers:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
242 goim(account, unquote_plus(target.split(",")[0]),
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
243 params.get("msg"))
23564
9ccc8c1ddc6b Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents: 23563
diff changeset
244 else:
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
245 channel = unquote_plus(target.split(",")[0])
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
246 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
247 channel = "#" + channel
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
248 gochat(account,
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
249 {"server": server,
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
250 "channel": channel,
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
251 "password": params.get("key", "")},
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
252 params.get("msg"))
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
253
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
254
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
255 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
256 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
257 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
258 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
259 print("Invalid sip URI: %s" % (uri, ))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
260 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
261
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
262 screenname = unquote_plus(match.group(1))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
263 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
264 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
265
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
266
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
267 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
268 protocol = "prpl-jabber"
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
269 match = re.match(
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
270 r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?",
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
271 uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
272 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
273 print("Invalid xmpp URI: %s" % (uri, ))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
274 return
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
275
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
276 tmp = match.group(2)
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
277 if tmp:
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
278 accountname = unquote_plus(tmp)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
279 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
280 accountname = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
281
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
282 screenname = unquote_plus(match.group(3))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
283
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
284 tmp = match.group(5)
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
285 if tmp:
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
286 command = unquote_plus(tmp)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
287 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
288 command = ""
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
289
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
290 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
291 params = {}
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
292 if paramstring:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
293 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
294 key, value = extendlist(param.split("=", 1), 2, "")
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
295 params[key] = unquote_plus(value)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
296
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
297 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
298
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
299 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
300 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
301 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
302 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
303 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
304 elif command.lower() == "roster":
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
305 addbuddy(account, screenname, params.get("group", ""),
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
306 params.get("name", ""))
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
307 else:
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
308 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
309
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
310
25327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
311 def gtalk(uri):
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
312 protocol = "prpl-jabber"
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
313 match = re.match(r"^gtalk:([^?]*)(\?(.*))", uri)
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
314 if not match:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
315 print("Invalid gtalk URI: %s" % (uri, ))
25327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
316 return
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
317
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
318 command = unquote_plus(match.group(1))
25327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
319 paramstring = match.group(3)
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
320 params = {}
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
321 if paramstring:
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
322 for param in paramstring.split("&"):
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
323 key, value = extendlist(param.split("=", 1), 2, "")
37444
8c851c1bc85b Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents: 37443
diff changeset
324 params[key] = unquote_plus(value)
25327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
325 accountname = params.get("from_jid", "")
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
326 jid = params.get("jid", "")
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
328 account = findaccount(protocol, accountname)
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
329
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
330 if command.lower() == "chat":
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
331 goim(account, jid)
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
332 elif command.lower() == "call":
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
333 # XXX V&V prompt to establish call
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
334 goim(account, jid)
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
335
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
336
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
337 def main(argv=sys.argv):
23237
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
338 if len(argv) != 2 or argv[1] == "--help" or argv[1] == "-h":
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
339 print("Usage: %s URI" % (argv[0], ))
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
340 print("Example: %s \"xmpp:romeo@montague.net?message\"" % (argv[0], ))
23237
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
341
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
342 if len(argv) != 2:
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
343 sys.exit(1)
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
344 else:
7ec42e06496f Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents: 22141
diff changeset
345 return 0
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
346
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
347 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
348 type = uri.split(":")[0]
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
349
16207
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
350 try:
b4b168c28673 Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents: 16205
diff changeset
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 irc(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
359 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
360 sip(uri)
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
361 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
362 xmpp(uri)
25327
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
363 elif type == "gtalk":
f24162b33a66 Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents: 23565
diff changeset
364 gtalk(uri)
17323
f92574b24329 Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17145
diff changeset
365 else:
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
366 print("Unknown protocol: %s" % (type, ))
37443
78408ad717bd Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents: 31582
diff changeset
367 except dbus.DBusException as e:
38313
38a40ddbb9b7 Ensure all Python scripts are Py3k compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38089
diff changeset
368 print("Error: %s" % (str(e), ))
23562
312323547538 Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents: 23237
diff changeset
369 sys.exit(1)
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
370
37984
6a5ca046a90d Make all Python files PEP8 compatible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37983
diff changeset
371
14582
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
372 if __name__ == "__main__":
ae974395b9da [gaim-migrate @ 17240]
Lars T. Mikkelsen
parents:
diff changeset
373 main()

mercurial