changeset fff2abdfbe8d in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=fff2abdfbe8d
description: check that we are authenticated to server before sending anything.
diffstat:
src/common/connection.py | 90 ++++++++++++++++++++++++------------------------
1 files changed, 45 insertions(+), 45 deletions(-)
diffs (truncated from 390 to 300 lines):
diff -r 1be252d1caa4 -r fff2abdfbe8d src/common/connection.py
--- a/src/common/connection.py Fri Mar 19 20:46:05 2010 +0000
+++ b/src/common/connection.py Sat Mar 20 19:00:33 2010 +0100
@@ -514,7 +514,7 @@
groupchat_jid is used when we want to send a request to a real jid and
act as if the answer comes from the groupchat_jid
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
to_whom_jid = jid
if resource:
@@ -1317,7 +1317,7 @@
stanza.setAttr('xml:lang', self.lang)
def get_privacy_lists(self):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.getPrivacyLists(self.connection)
@@ -1336,7 +1336,7 @@
Send XMPP Ping (XEP-0199) request. If pingTo is not set, ping is sent to
server to detect connection failure at application level
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
id_ = self.connection.getAnID()
if pingTo:
@@ -1364,12 +1364,12 @@
'accounts', self.name, 'time_for_ping_alive_answer'))
def get_active_default_lists(self):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.getActiveAndDefaultPrivacyLists(self.connection)
def del_privacy_list(self, privacy_list):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
def _on_del_privacy_list_result(result):
if result:
@@ -1383,22 +1383,22 @@
_on_del_privacy_list_result)
def get_privacy_list(self, title):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.getPrivacyList(self.connection, title)
def set_privacy_list(self, listname, tags):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.setPrivacyList(self.connection, listname, tags)
def set_active_list(self, listname):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.setActivePrivacyList(self.connection, listname, 'active')
def set_default_list(self, listname):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
common.xmpp.features_nb.setDefaultPrivacyList(self.connection, listname)
@@ -1441,14 +1441,14 @@
"""
Activate a privacy rule
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq('set', common.xmpp.NS_PRIVACY, xmlns = '')
iq.getTag('query').setTag('active', {'name': name})
self.connection.send(iq)
def send_invisible_presence(self, msg, signed, initial = False):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
if not self.privacy_rules_supported:
self.dispatch('STATUS', gajim.SHOW_LIST[self.connected])
@@ -1519,7 +1519,7 @@
def _discover_server_at_connection(self, con):
self.connection = con
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
self.connection.set_send_timeout(self.keepalives, self.send_keepalive)
self.connection.set_send_timeout2(self.pingalives, self.sendPing)
@@ -1545,7 +1545,7 @@
def send_custom_status(self, show, msg, jid):
if not show in gajim.SHOW_LIST:
return -1
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
sshow = helpers.get_xmpp_show(show)
if not msg:
@@ -1593,7 +1593,7 @@
self.dispatch('STATUS', show)
def send_motd(self, jid, subject = '', msg = '', xhtml = None):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
msg_iq = common.xmpp.Message(to = jid, body = msg, subject = subject,
xhtml = xhtml)
@@ -1626,7 +1626,7 @@
"""
Send contacts with RosterX (Xep-0144)
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
if len(contacts) == 1:
msg = _('Sent contact: "%s" (%s)') % (contacts[0].get_full_jid(),
@@ -1652,14 +1652,14 @@
self.connection.send(stanza)
def ack_subscribed(self, jid):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
log.debug('ack\'ing subscription complete for %s' % jid)
p = common.xmpp.Presence(jid, 'subscribe')
self.connection.send(p)
def ack_unsubscribed(self, jid):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
log.debug('ack\'ing unsubscription complete for %s' % jid)
p = common.xmpp.Presence(jid, 'unsubscribe')
@@ -1667,7 +1667,7 @@
def request_subscription(self, jid, msg='', name='', groups=[],
auto_auth=False, user_nick=''):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
log.debug('subscription request for %s' % jid)
if auto_auth:
@@ -1692,21 +1692,21 @@
self.connection.send(p)
def send_authorization(self, jid):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
p = common.xmpp.Presence(jid, 'subscribed')
p = self.add_sha(p)
self.connection.send(p)
def refuse_authorization(self, jid):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
p = common.xmpp.Presence(jid, 'unsubscribed')
p = self.add_sha(p)
self.connection.send(p)
def unsubscribe(self, jid, remove_auth = True):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
if remove_auth:
self.connection.getRoster().delItem(jid)
@@ -1719,7 +1719,7 @@
self.update_contact(jid, '', [])
def unsubscribe_agent(self, agent):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq('set', common.xmpp.NS_REGISTER, to = agent)
iq.getTag('query').setTag('remove')
@@ -1774,7 +1774,7 @@
groupchat_jid is used when we want to send a request to a real jid and
act as if the answer comes from the groupchat_jid
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
# If we are invisible, do not request
if self.connected == gajim.SHOW_LIST.index('invisible'):
@@ -1797,7 +1797,7 @@
groupchat_jid is used when we want to send a request to a real jid and
act as if the answer comes from the groupchat_jid
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
# If we are invisible, do not request
if self.connected == gajim.SHOW_LIST.index('invisible'):
@@ -1819,7 +1819,7 @@
"""
Get Gajim settings as described in XEP 0049
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='get')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1827,7 +1827,7 @@
self.connection.send(iq)
def _request_bookmarks_xml(self):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='get')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1845,7 +1845,7 @@
storage_type can be set to xml to force request to xml storage
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
if self.pubsub_supported and storage_type != 'xml':
self.send_pb_retrieve('', 'storage:bookmarks')
@@ -1862,7 +1862,7 @@
storage_type can be set to 'pubsub' or 'xml' so store in only one method
else it will be stored on both
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Node(tag='storage', attrs={'xmlns': 'storage:bookmarks'})
for bm in self.bookmarks:
@@ -1907,7 +1907,7 @@
Get Annonations from storage as described in XEP 0048, and XEP 0145
"""
self.annotations = {}
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='get')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1918,7 +1918,7 @@
"""
Set Annonations in private storage as described in XEP 0048, and XEP 0145
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='set')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1935,7 +1935,7 @@
"""
Get metacontacts list from storage as described in XEP 0049
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='get')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1949,7 +1949,7 @@
"""
Send meta contacts to the storage namespace
"""
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ='set')
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
@@ -1964,7 +1964,7 @@
self.connection.send(iq)
def send_agent_status(self, agent, ptype):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
show = helpers.get_xmpp_show(gajim.SHOW_LIST[self.connected])
p = common.xmpp.Presence(to = agent, typ = ptype, show = show)
@@ -1972,7 +1972,7 @@
self.connection.send(p)
def check_unique_room_id_support(self, server, instance):
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
iq = common.xmpp.Iq(typ = 'get', to = server)
iq.setAttr('id', 'unique1')
@@ -1987,7 +1987,7 @@
def join_gc(self, nick, room_jid, password, change_nick=False):
# FIXME: This room JID needs to be normalized; see #1364
- if not self.connection:
+ if not gajim.account_is_connected(self.name):
return
changeset 931969111a91 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=931969111a91
description: merge with default
diffstat:
src/command_system/__init__.py | 2 +-
src/command_system/dispatching.py | 2 +-
src/command_system/errors.py | 8 +-
src/command_system/framework.py | 8 +-
src/command_system/implementation/__init__.py | 2 +-
src/command_system/implementation/custom.py | 6 +-
src/command_system/implementation/hosts.py | 2 +-
src/command_system/implementation/middleware.py | 31 +++++---
src/command_system/implementation/standard.py | 88 ++++++++++++++----------
src/command_system/mapping.py | 2 +-
src/common/multimedia_helpers.py | 4 +-
src/common/xmpp/auth_nb.py | 27 +++---
src/dataforms_widget.py | 2 +-
src/gajim-remote.py | 2 +
14 files changed, 107 insertions(+), 79 deletions(-)
diffs (truncated from 566 to 300 lines):
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/__init__.py
--- a/src/command_system/__init__.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/__init__.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/dispatching.py
--- a/src/command_system/dispatching.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/dispatching.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/errors.py
--- a/src/command_system/errors.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/errors.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -45,3 +45,9 @@
Used to indicate errors occured during command execution.
"""
pass
+
+class NoCommandError(BaseError):
+ """
+ Used to indicate an inability to find the specified command.
+ """
+ pass
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/framework.py
--- a/src/command_system/framework.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/framework.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
from dispatching import Dispatcher, HostDispatcher, ContainerDispatcher
from mapping import parse_arguments, adapt_arguments
-from errors import DefinitionError, CommandError
+from errors import DefinitionError, CommandError, NoCommandError
class CommandHost(object):
"""
@@ -128,7 +128,7 @@
def get_command(self, name):
command = Dispatcher.get_command(self.COMMAND_HOST, name)
if not command:
- raise CommandError("Command does not exist", name=name)
+ raise NoCommandError("Command does not exist", name=name)
return command
def list_commands(self):
@@ -330,7 +330,7 @@
return decorator
-def documentation(text):
+def doc(text):
"""
This decorator is used to bind a documentation (a help) to a
command.
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/implementation/__init__.py
--- a/src/command_system/implementation/__init__.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/implementation/__init__.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/implementation/custom.py
--- a/src/command_system/implementation/custom.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/implementation/custom.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
be executed and commands defined here will not be detected.
"""
-from ..framework import CommandContainer, command, documentation
+from ..framework import CommandContainer, command, doc
from hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
class CustomCommonCommands(CommandContainer):
@@ -58,7 +58,7 @@
HOSTS = (ChatCommands,)
- @documentation(_("The same as using a doc-string, except it supports translation"))
+ @doc(_("The same as using a doc-string, except it supports translation"))
@command
def sing(self):
return "Are you phreaking kidding me? Buy yourself a damn stereo..."
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/implementation/hosts.py
--- a/src/command_system/implementation/hosts.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/implementation/hosts.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/implementation/middleware.py
--- a/src/command_system/implementation/middleware.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/implementation/middleware.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
from common import gajim
from ..framework import CommandProcessor
-from ..errors import CommandError
+from ..errors import CommandError, NoCommandError
class ChatCommandProcessor(CommandProcessor):
"""
@@ -44,33 +44,40 @@
def execute_command(self, name, arguments):
try:
super(ChatCommandProcessor, self).execute_command(name, arguments)
+ except NoCommandError, error:
+ details = dict(name=error.name, message=error.message)
+ message = "%(name)s: %(message)s\n" % details
+ message += "Try using the //%(name)s or /say /%(name)s " % details
+ message += "construct if you intended to send it as a text."
+ self.echo(message, 'error')
except CommandError, error:
- self.echo("%s: %s" %(error.name, error.message), 'error')
+ self.echo("%s: %s" % (error.name, error.message), 'error')
except Exception:
self.echo("An error occured while trying to execute the command", 'error')
print_exc()
def looks_like_command(self, text, body, name, arguments):
- # Command escape stuff ggoes here. If text was prepended by the command
- # prefix twice, like //not_a_command (if prefix is set to /) then it
- # will be escaped, that is sent just as a regular message with one (only
- # one) prefix removed, so message will be /not_a_command.
+ # Command escape stuff ggoes here. If text was prepended by the
+ # command prefix twice, like //not_a_command (if prefix is set
+ # to /) then it will be escaped, that is sent just as a regular
+ # message with one (only one) prefix removed, so message will be
+ # /not_a_command.
if body.startswith(self.COMMAND_PREFIX):
self.send(body)
return True
def command_preprocessor(self, command, name, arguments, args, kwargs):
- # If command argument contain h or help option - forward it to the /help
- # command. Dont forget to pass self, as all commands are unbound. And
- # also don't forget to print output.
+ # If command argument contain h or help option - forward it to
+ # the /help command. Dont forget to pass self, as all commands
+ # are unbound. And also don't forget to print output.
if 'h' in kwargs or 'help' in kwargs:
help = self.get_command('help')
self.echo(help(self, name))
return True
def command_postprocessor(self, command, name, arguments, args, kwargs, value):
- # If command returns a string - print it to a user. A convenient and
- # sufficient in most simple cases shortcut to a using echo.
+ # If command returns a string - print it to a user. A convenient
+ # and sufficient in most simple cases shortcut to a using echo.
if value and isinstance(value, StringTypes):
self.echo(value)
diff -r 18254a32fdd7 -r 931969111a91 src/command_system/implementation/standard.py
--- a/src/command_system/implementation/standard.py Fri Mar 19 08:21:57 2010 +0100
+++ b/src/command_system/implementation/standard.py Fri Mar 19 08:23:24 2010 +0100
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Alexander Cherniuk <ts33kr(a)gmail.com>
+# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr(a)gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
from common.logger import Constants
from ..errors import CommandError
-from ..framework import CommandContainer, command, documentation
+from ..framework import CommandContainer, command, doc
from ..mapping import generate_usage
from hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
@@ -45,18 +45,18 @@
HOSTS = (ChatCommands, PrivateChatCommands, GroupChatCommands)
@command
- @documentation(_("Clear the text window"))
+ @doc(_("Clear the text window"))
def clear(self):
self.conv_textview.clear()
@command
- @documentation(_("Hide the chat buttons"))
+ @doc(_("Hide the chat buttons"))
def compact(self):
new_status = not self.hide_chat_buttons
self.chat_buttons_set_visible(new_status)
@command(overlap=True)
- @documentation(_("Show help on a given command or a list of available commands if -(-a)ll is given"))
+ @doc(_("Show help on a given command or a list of available commands if -(-a)ll is given"))
def help(self, command=None, all=False):
if command:
command = self.get_command(command)
@@ -83,17 +83,17 @@
self.echo(help(self, 'help'))
@command(raw=True)
- @documentation(_("Send a message to the contact"))
+ @doc(_("Send a message to the contact"))
def say(self, message):
self.send(message)
@command(raw=True)
- @documentation(_("Send action (in the third person) to the current chat"))
+ @doc(_("Send action (in the third person) to the current chat"))
def me(self, action):
self.send("/me %s" % action)
@command('lastlog', overlap=True)
- @documentation(_("Show logged messages which mention given text"))
+ @doc(_("Show logged messages which mention given text"))
def grep(self, text, limit=None):
results = gajim.logger.get_search_results_for_query(self.contact.jid,
text, self.account)
@@ -129,7 +129,7 @@
self.echo(formatted)
@command(raw=True, empty=True)
- @documentation(_("""
+ @doc(_("""
Set current the status
Status can be given as one of the following values: online, away,
@@ -142,7 +142,7 @@
connection.change_status(status, message)
@command(raw=True, empty=True)
- @documentation(_("Set the current status to away"))
+ @doc(_("Set the current status to away"))
def away(self, message):
if not message:
message = _("Away")
@@ -150,36 +150,40 @@
connection.change_status('away', message)
@command('back', raw=True, empty=True)
- @documentation(_("Set the current status to online"))
+ @doc(_("Set the current status to online"))
def online(self, message):
if not message:
message = _("Available")
for connection in gajim.connections.itervalues():
connection.change_status('online', message)
-class StandardChatCommands(CommandContainer):
+class StandardCommonChatCommands(CommandContainer):
"""
- This command container contains standard command which are unique to
- a chat.
+ This command container contans standard commands, which are common
+ to a chat and a private chat only.
"""
- HOSTS = (ChatCommands,)
+ HOSTS = (ChatCommands, PrivateChatCommands)
@command
- @documentation(_("Send a ping to the contact"))
+ @doc(_("Toggle the GPG encryption"))
+ def gpg(self):
+ self._toggle_gpg()
+
+ @command
+ @doc(_("Send a ping to the contact"))
def ping(self):
if self.account == gajim.ZEROCONF_ACC_NAME: