file isExecutable
Prep for 2.10.10
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") except dbus.DBusException, e: if e._dbus_error_name == "org.freedesktop.DBus.Error.ServiceUnknown": print "Error: no libpurple-powered client is running. Try starting Pidgin or Finch." purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") def __getattr__(self, attr): return CheckedAttribute(self, attr) def __init__(self, cobj, attr): def __call__(self, *args): # Redirect stderr to suppress the printing of an " Introspect error" # message if nothing is listening on the bus. We print a friendly # error message ourselves. result = self.cobj.obj.__getattr__(self.attr)(*args) # This can be useful for debugging. # print "Error: " + self.attr + " " + str(args) + " returned " + str(result) cpurple = CheckedObject(purple) def extendlist(list, length, fill): return list + [fill] * (length - len(list)) print "No matching account found." def bring_account_online(account): if not cpurple.PurpleAccountIsConnected(account): # The last argument is meant to be a GList * but the D-Bus binding # generator thing just wants a UInt32, which is pretty failing. # Happily, passing a 0 to mean an empty list turns out to work anyway. purple.PurpleAccountSetStatusList(account, "online", 1, 0) purple.PurpleAccountConnect(account) def findaccount(protocolname, accountname="", matcher=None): for account in cpurple.PurpleAccountsGetAll(): if (protocolname != cpurple.PurpleAccountGetProtocolId(account)) or \
(accountname != "" and accountname != cpurple.PurpleAccountGetUsername(account)): bring_account_online(account) # prefer connected accounts account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) # try to get any account and connect it account = cpurple.PurpleAccountsFindAny(accountname, protocolname) bring_account_online(account) def goim(account, screenname, message=None): # XXX: 1 == PURPLE_CONV_TYPE_IM conversation = cpurple.PurpleConversationNew(1, account, screenname) purple.PurpleConvSendConfirm(conversation, message) def gochat(account, params, message=None): connection = cpurple.PurpleAccountGetConnection(account) purple.ServJoinChat(connection, params) # XXX: 2 == PURPLE_CONV_TYPE_CHAT conversation = purple.PurpleFindConversationWithAccount(2, params.get("channel", params.get("room")), account) purple.PurpleConvSendConfirm(conversation, message) def addbuddy(account, screenname, group="", alias=""): cpurple.PurpleBlistRequestAddBuddy(account, screenname, group, alias) match = re.match(r"^aim:([^?]*)(\?(.*))", uri) print "Invalid aim URI: %s" % uri command = urllib.unquote_plus(match.group(1)) paramstring = match.group(3) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) accountname = params.get("account", "") screenname = params.get("screenname", "") account = findaccount(protocol, accountname) if command.lower() == "goim": goim(account, screenname, params.get("message")) elif command.lower() == "gochat": elif command.lower() == "addbuddy": addbuddy(account, screenname, params.get("group", "")) match = re.match(r"^gg:(.*)", uri) print "Invalid gg URI: %s" % uri screenname = urllib.unquote_plus(match.group(1)) account = findaccount(protocol) goim(account, screenname) match = re.match(r"^icq:([^?]*)(\?(.*))", uri) print "Invalid icq URI: %s" % uri command = urllib.unquote_plus(match.group(1)) paramstring = match.group(3) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) accountname = params.get("account", "") screenname = params.get("screenname", "") account = findaccount(protocol, accountname) if command.lower() == "goim": goim(account, screenname, params.get("message")) elif command.lower() == "gochat": elif command.lower() == "addbuddy": addbuddy(account, screenname, params.get("group", "")) match = re.match(r"^irc:(//([^/]*))?/?([^?]*)(\?(.*))?", uri) print "Invalid irc URI: %s" % uri server = urllib.unquote_plus(match.group(2) or "") target = match.group(3) or "" query = match.group(5) or "" for modifier in target.split(",")[1:]: modifiers[modifier] = True isnick = modifiers.has_key("isnick") paramstring = match.group(5) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) def correct_server(account): username = cpurple.PurpleAccountGetUsername(account) return ((server == "") or ("@" in username) and (server == (username.split("@"))[1])) account = findaccount(protocol, matcher=correct_server) goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg")) channel = urllib.unquote_plus(target.split(",")[0]) gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg")) match = re.match(r"^msnim:([^?]*)(\?(.*))", uri) print "Invalid msnim URI: %s" % uri command = urllib.unquote_plus(match.group(1)) paramstring = match.group(3) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) screenname = params.get("contact", "") account = findaccount(protocol) if command.lower() == "chat": goim(account, screenname) elif command.lower() == "add": addbuddy(account, screenname) protocol = "prpl-myspace" print "TODO: send uri: ", uri assert False, "Not implemented" match = re.match(r"^sip:(.*)", uri) print "Invalid sip URI: %s" % uri screenname = urllib.unquote_plus(match.group(1)) account = findaccount(protocol) goim(account, screenname) match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri) print "Invalid xmpp URI: %s" % uri accountname = urllib.unquote_plus(tmp) screenname = urllib.unquote_plus(match.group(3)) command = urllib.unquote_plus(tmp) paramstring = match.group(7) for param in paramstring.split(";"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) account = findaccount(protocol, accountname) if command.lower() == "message": goim(account, screenname, params.get("body")) elif command.lower() == "join": room, server = screenname.split("@") gochat(account, {"room": room, "server": server}) elif command.lower() == "roster": addbuddy(account, screenname, params.get("group", ""), params.get("name", "")) goim(account, screenname) match = re.match(r"^gtalk:([^?]*)(\?(.*))", uri) print "Invalid gtalk URI: %s" % uri command = urllib.unquote_plus(match.group(1)) paramstring = match.group(3) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) accountname = params.get("from_jid", "") jid = params.get("jid", "") account = findaccount(protocol, accountname) if command.lower() == "chat": elif command.lower() == "call": # XXX V&V prompt to establish call match = re.match(r"^ymsgr:([^?]*)(\?([^&]*)(&(.*))?)", uri) print "Invalid ymsgr URI: %s" % uri command = urllib.unquote_plus(match.group(1)) screenname = urllib.unquote_plus(match.group(3)) paramstring = match.group(5) for param in paramstring.split("&"): key, value = extendlist(param.split("=", 1), 2, "") params[key] = urllib.unquote_plus(value) account = findaccount(protocol) if command.lower() == "sendim": goim(account, screenname, params.get("m")) elif command.lower() == "chat": gochat(account, {"room": screenname}) elif command.lower() == "addfriend": addbuddy(account, screenname) if len(argv) != 2 or argv[1] == "--help" or argv[1] == "-h": print "Usage: %s URI" % argv[0] print "Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0] print "Unknown protocol: %s" % type except dbus.DBusException, e: print "Error: %s" % (e.message) if __name__ == "__main__":