changeset 6dde8dcbf882 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=6dde8dcbf882
description: Remove the sequence constraint, that is never used
diffstat:
src/command_system/mapping.py | 26 --------------------------
1 files changed, 0 insertions(+), 26 deletions(-)
diffs (57 lines):
diff -r 400638ce2686 -r 6dde8dcbf882 src/command_system/mapping.py
--- a/src/command_system/mapping.py Fri Feb 26 12:35:09 2010 +0200
+++ b/src/command_system/mapping.py Fri Feb 26 12:53:06 2010 +0200
@@ -24,7 +24,6 @@
import re
from types import BooleanType, UnicodeType
-from types import TupleType, ListType
from operator import itemgetter
from errors import DefinitionError, CommandError
@@ -125,10 +124,6 @@
an option which does not take an argument. If a switch is followed
by an argument - then this argument will be treated just like a
normal positional argument.
-
- If the initial value of a keyword argument is a sequence, that is a
- tuple or list - then a value of this option will be considered
- correct only if it is present in the sequence.
"""
spec_args, spec_kwargs, var_args, var_kwargs = command.extract_specification()
norm_kwargs = dict(spec_kwargs)
@@ -274,25 +269,6 @@
if not isinstance(value, BooleanType):
raise CommandError("%s: Switch can not take an argument" % key, command)
- # Detect every sequence constraint and ensure that if corresponding
- # options are given - they contain proper values, within the
- # constraint range.
- for key, value in opts:
- initial = norm_kwargs.get(key)
- if isinstance(initial, (TupleType, ListType)):
- if value not in initial:
- raise CommandError("%s: Invalid argument" % key, command)
-
- # If argument to an option constrained by a sequence was not given -
- # then it's value should be set to None.
- for spec_key, spec_value in spec_kwargs:
- if isinstance(spec_value, (TupleType, ListType)):
- for key, value in opts:
- if spec_key == key:
- break
- else:
- opts.append((spec_key, None))
-
# We need to encode every keyword argument to a simple string, not
# the unicode one, because ** expansion does not support it.
for index, (key, value) in enumerate(opts):
@@ -331,8 +307,6 @@
if isinstance(value, BooleanType):
value = str()
- elif isinstance(value, (TupleType, ListType)):
- value = '={%s}' % ', '.join(value)
else:
value = '=%s' % value
changeset 400638ce2686 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=400638ce2686
description: Realigned width of text meant for humans to 72 characters
diffstat:
src/command_system/__init__.py | 6 +-
src/command_system/dispatching.py | 7 +-
src/command_system/errors.py | 5 +-
src/command_system/framework.py | 184 +++++++++++-----------
src/command_system/implementation/__init__.py | 5 +-
src/command_system/implementation/custom.py | 34 ++-
src/command_system/implementation/hosts.py | 16 +-
src/command_system/implementation/middleware.py | 20 +-
src/command_system/implementation/standard.py | 15 +-
src/command_system/mapping.py | 194 ++++++++++++-----------
10 files changed, 257 insertions(+), 229 deletions(-)
diffs (truncated from 951 to 300 lines):
diff -r f31c4dd57084 -r 400638ce2686 src/command_system/__init__.py
--- a/src/command_system/__init__.py Thu Feb 25 22:56:38 2010 +0100
+++ b/src/command_system/__init__.py Fri Feb 26 12:35:09 2010 +0200
@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-The command system providing scalable, clean and convenient architecture in
-combination with declarative way of defining commands and a fair amount of
-automatization for routine processes.
+The command system providing scalable, clean and convenient architecture
+in combination with declarative way of defining commands and a fair
+amount of automatization for routine processes.
"""
diff -r f31c4dd57084 -r 400638ce2686 src/command_system/dispatching.py
--- a/src/command_system/dispatching.py Thu Feb 25 22:56:38 2010 +0100
+++ b/src/command_system/dispatching.py Fri Feb 26 12:35:09 2010 +0200
@@ -14,9 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-The backbone of the command system. Provides automatic dispatching which does
-not require explicit registering commands or containers and remains active even
-after everything is done, so new commands can be added during the runtime.
+The backbone of the command system. Provides automatic dispatching which
+does not require explicit registering commands or containers and remains
+active even after everything is done, so new commands can be added
+during the runtime.
"""
from types import NoneType
diff -r f31c4dd57084 -r 400638ce2686 src/command_system/errors.py
--- a/src/command_system/errors.py Thu Feb 25 22:56:38 2010 +0100
+++ b/src/command_system/errors.py Fri Feb 26 12:35:09 2010 +0200
@@ -15,8 +15,9 @@
class BaseError(Exception):
"""
- Common base for errors which relate to a specific command. Encapsulates
- everything needed to identify a command, by either its object or name.
+ Common base for errors which relate to a specific command.
+ Encapsulates everything needed to identify a command, by either its
+ object or name.
"""
def __init__(self, message, command=None, name=None):
diff -r f31c4dd57084 -r 400638ce2686 src/command_system/framework.py
--- a/src/command_system/framework.py Thu Feb 25 22:56:38 2010 +0100
+++ b/src/command_system/framework.py Fri Feb 26 12:35:09 2010 +0200
@@ -14,8 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-Provides a tiny framework with simple, yet powerful and extensible architecture
-to implement commands in a streight and flexible, declarative way.
+Provides a tiny framework with simple, yet powerful and extensible
+architecture to implement commands in a streight and flexible,
+declarative way.
"""
import re
@@ -28,42 +29,43 @@
class CommandHost(object):
"""
- Command host is a hub between numerous command processors and command
- containers. Aimed to participate in a dispatching process in order to
- provide clean and transparent architecture.
+ Command host is a hub between numerous command processors and
+ command containers. Aimed to participate in a dispatching process in
+ order to provide clean and transparent architecture.
"""
__metaclass__ = HostDispatcher
class CommandContainer(object):
"""
- Command container is an entity which holds defined commands, allowing them
- to be dispatched and proccessed correctly. Each command container may be
- bound to a one or more command hosts.
+ Command container is an entity which holds defined commands,
+ allowing them to be dispatched and proccessed correctly. Each
+ command container may be bound to a one or more command hosts.
- Bounding is controlled by the HOSTS variable, which must be defined in the
- body of the command container. This variable should contain a list of hosts
- to bound to, as a tuple or list.
+ Bounding is controlled by the HOSTS variable, which must be defined
+ in the body of the command container. This variable should contain a
+ list of hosts to bound to, as a tuple or list.
"""
__metaclass__ = ContainerDispatcher
class CommandProcessor(object):
"""
- Command processor is an immediate command emitter. It does not participate
- in the dispatching process directly, but must define a host to bound to.
+ Command processor is an immediate command emitter. It does not
+ participate in the dispatching process directly, but must define a
+ host to bound to.
- Bounding is controlled by the COMMAND_HOST variable, which must be defined
- in the body of the command processor. This variable should be set to a
- specific command host.
+ Bounding is controlled by the COMMAND_HOST variable, which must be
+ defined in the body of the command processor. This variable should
+ be set to a specific command host.
"""
- # This defines a command prefix (or an initializer), which should preceede a
- # a text in order it to be processed as a command.
+ # This defines a command prefix (or an initializer), which should
+ # preceede a a text in order it to be processed as a command.
COMMAND_PREFIX = '/'
def process_as_command(self, text):
"""
- Try to process text as a command. Returns True if it has been processed
- as a command and False otherwise.
+ Try to process text as a command. Returns True if it has been
+ processed as a command and False otherwise.
"""
prefix = text.startswith(self.COMMAND_PREFIX)
length = len(text) > len(self.COMMAND_PREFIX)
@@ -97,28 +99,28 @@
def command_preprocessor(self, command, name, arguments, args, kwargs):
"""
- Redefine this method in the subclass to execute custom code before
- command gets executed.
+ Redefine this method in the subclass to execute custom code
+ before command gets executed.
- If returns True then command execution will be interrupted and command
- will not be executed.
+ If returns True then command execution will be interrupted and
+ command will not be executed.
"""
pass
def command_postprocessor(self, command, name, arguments, args, kwargs, value):
"""
- Redefine this method in the subclass to execute custom code after
- command gets executed.
+ Redefine this method in the subclass to execute custom code
+ after command gets executed.
"""
pass
def looks_like_command(self, text, body, name, arguments):
"""
- This hook is being called before any processing, but after it was
- determined that text looks like a command.
+ This hook is being called before any processing, but after it
+ was determined that text looks like a command.
- If returns value other then None - then further processing will be
- interrupted and that value will be used to return from
+ If returns value other then None - then further processing will
+ be interrupted and that value will be used to return from
process_as_command.
"""
pass
@@ -136,8 +138,9 @@
class Command(object):
- # These two regular expression patterns control how command documentation
- # will be formatted to be transformed to a normal, readable state.
+ # These two regular expression patterns control how command
+ # documentation will be formatted to be transformed to a normal,
+ # readable state.
DOC_STRIP_PATTERN = re.compile(r'(?:^[ \t]+|\A\n)', re.MULTILINE)
DOC_FORMAT_PATTERN = re.compile(r'(?<!\n)\n(?!\n)', re.MULTILINE)
@@ -145,8 +148,8 @@
self.handler = handler
self.names = names
- # Automatically set all the properties passed to a constructor by the
- # command decorator.
+ # Automatically set all the properties passed to a constructor
+ # by the command decorator.
for key, value in properties.iteritems():
setattr(self, key, value)
@@ -154,18 +157,20 @@
try:
return self.handler(*args, **kwargs)
- # This allows to use a shortcuted way of raising an exception inside a
- # handler. That is to raise a CommandError without command or name
- # attributes set. They will be set to a corresponding values right here
- # in case if they was not set by the one who raised an exception.
+ # This allows to use a shortcuted way of raising an exception
+ # inside a handler. That is to raise a CommandError without
+ # command or name attributes set. They will be set to a
+ # corresponding values right here in case if they was not set by
+ # the one who raised an exception.
except CommandError, error:
if not error.command and not error.name:
raise CommandError(error.message, self)
raise
# This one is a little bit too wide, but as Python does not have
- # anything more constrained - there is no other choice. Take a look here
- # if command complains about invalid arguments while they are ok.
+ # anything more constrained - there is no other choice. Take a
+ # look here if command complains about invalid arguments while
+ # they are ok.
except TypeError:
raise CommandError("Command received invalid arguments", self)
@@ -185,8 +190,8 @@
def extract_documentation(self):
"""
- Extract handler's documentation which is a doc-string and transform it
- to a usable format.
+ Extract handler's documentation which is a doc-string and
+ transform it to a usable format.
Transformation is done based on the DOC_STRIP_PATTERN and
DOC_FORMAT_PATTERN regular expression patterns.
@@ -211,19 +216,19 @@
def extract_specification(self):
"""
- Extract handler's arguments specification, as it was defined preserving
- their order.
+ Extract handler's arguments specification, as it was defined
+ preserving their order.
"""
names, var_args, var_kwargs, defaults = getargspec(self.handler)
- # Behavior of this code need to be checked. Might yield incorrect
- # results on some rare occasions.
+ # Behavior of this code need to be checked. Might yield
+ # incorrect results on some rare occasions.
spec_args = names[:-len(defaults) if defaults else len(names)]
spec_kwargs = list(zip(names[-len(defaults):], defaults)) if defaults else {}
- # Removing self from arguments specification. Command handler should
- # receive the processors as a first argument, which should be self by
- # the canonical means.
+ # Removing self from arguments specification. Command handler
+ # should receive the processors as a first argument, which
+ # should be self by the canonical means.
if spec_args.pop(0) != 'self':
raise DefinitionError("First argument must be self", self)
@@ -231,44 +236,47 @@
def command(*names, **properties):
"""
- A decorator for defining commands in a declarative way. Provides facilities
- for setting command's names and properties.
+ A decorator for defining commands in a declarative way. Provides
+ facilities for setting command's names and properties.
- Names should contain a set of names (aliases) by which the command can be
- reached. If no names are given - the the native name (the one extracted from
- the command handler) will be used.
+ Names should contain a set of names (aliases) by which the command
+ can be reached. If no names are given - the the native name (the one
+ extracted from the command handler) will be used.
- If include_native=True is given (default) and names is non-empty - then the
- native name of the command will be prepended in addition to the given names.
+ If include_native=True is given (default) and names is non-empty -
+ then the native name of the command will be prepended in addition to
+ the given names.
- If usage=True is given (default) - then command help will be appended with
- autogenerated usage info, based of the command handler arguments
- introspection.
+ If usage=True is given (default) - then command help will be
+ appended with autogenerated usage info, based of the command handler
+ arguments introspection.
- If source=True is given - then the first argument of the command will
- receive the source arguments, as a raw, unprocessed string. The further
- mapping of arguments and options will not be affected.
+ If source=True is given - then the first argument of the command
+ will receive the source arguments, as a raw, unprocessed string. The
+ further mapping of arguments and options will not be affected.
- If raw=True is given - then command considered to be raw and should define
- positional arguments only. If it defines only one positional argument - this
- argument will receive all the raw and unprocessed arguments. If the command
- defines more then one positional argument - then all the arguments except
- the last one will be processed normally; the last argument will get what is
- left after the processing as raw and unprocessed string.
+ If raw=True is given - then command considered to be raw and should
+ define positional arguments only. If it defines only one positional
+ argument - this argument will receive all the raw and unprocessed
+ arguments. If the command defines more then one positional argument
+ - then all the arguments except the last one will be processed
+ normally; the last argument will get what is left after the
+ processing as raw and unprocessed string.
changeset f31c4dd57084 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=f31c4dd57084
description: don't remove keepalive and xmpp ping timeouts when we get an expected stanza.
diffstat:
src/common/xmpp/dispatcher_nb.py | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diffs (14 lines):
diff -r d4314c43a512 -r f31c4dd57084 src/common/xmpp/dispatcher_nb.py
--- a/src/common/xmpp/dispatcher_nb.py Thu Feb 25 15:33:27 2010 +0100
+++ b/src/common/xmpp/dispatcher_nb.py Thu Feb 25 22:56:38 2010 +0100
@@ -469,10 +469,6 @@
# we have released dispatcher, so self._owner has no methods
if not res:
return
- if 'remove_timeout' in self._owner.__dict__:
- # When we receive data after we started disconnecting, Transport may
- # already be plugged out
- self._owner.remove_timeout()
for (_id, _iq) in self._expected.items():
if _iq is None:
# If the expected Stanza would have arrived, ProcessNonBlocking