Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
7bec311c
Commit
7bec311c
authored
15 years ago
by
red-agent
Browse files
Options
Downloads
Patches
Plain Diff
Made some cosmetic API changes to the command system
parent
0a1ef72c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/custom.py
+4
-4
4 additions, 4 deletions
src/commands/custom.py
src/commands/framework.py
+12
-13
12 additions, 13 deletions
src/commands/framework.py
src/commands/implementation.py
+6
-6
6 additions, 6 deletions
src/commands/implementation.py
with
22 additions
and
23 deletions
src/commands/custom.py
+
4
−
4
View file @
7bec311c
...
...
@@ -29,7 +29,7 @@ class CustomCommonCommands(ChatCommands, PrivateChatCommands, GroupChatCommands)
here will be available to all of them.
"""
IS
_COMMAND_PROCESSOR
=
True
D
IS
PATCH
=
True
HOSTED_BY
=
ChatCommands
,
PrivateChatCommands
,
GroupChatCommands
@command
...
...
@@ -52,7 +52,7 @@ class CustomChatCommands(ChatCommands):
only to a chat.
"""
IS
_COMMAND_PROCESSOR
=
True
D
IS
PATCH
=
True
HOSTED_BY
=
ChatCommands
@command
...
...
@@ -66,7 +66,7 @@ class CustomPrivateChatCommands(PrivateChatCommands):
available only to a private chat.
"""
IS
_COMMAND_PROCESSOR
=
True
D
IS
PATCH
=
True
HOSTED_BY
=
PrivateChatCommands
@command
...
...
@@ -80,7 +80,7 @@ class CustomGroupChatCommands(GroupChatCommands):
available only to a group chat.
"""
IS
_COMMAND_PROCESSOR
=
True
D
IS
PATCH
=
True
HOSTED_BY
=
GroupChatCommands
@command
...
...
This diff is collapsed.
Click to expand it.
src/commands/framework.py
+
12
−
13
View file @
7bec311c
...
...
@@ -201,8 +201,8 @@ class Dispatcher(type):
@classmethod
def
is_suitable
(
cls
,
proc
,
dct
):
is_not_root
=
dct
.
get
(
'
__metaclass__
'
)
is
not
cls
is_processor
=
bool
(
dct
.
get
(
'
IS
_COMMAND_PROCESSOR
'
))
return
is_not_root
and
is_processor
to_be_dispatched
=
bool
(
dct
.
get
(
'
D
IS
PATCH
'
))
return
is_not_root
and
to_be_dispatched
@classmethod
def
check_if_dispatchable
(
cls
,
bases
,
dct
):
...
...
@@ -231,18 +231,18 @@ class Dispatcher(type):
@classmethod
def
register_processor
(
cls
,
proc
):
cls
.
table
[
proc
]
=
{}
inherit
ed
=
proc
.
__dict__
.
get
(
'
INHERIT
ED
'
)
inherit
=
proc
.
__dict__
.
get
(
'
INHERIT
'
)
if
'
HOSTED_BY
'
in
proc
.
__dict__
:
cls
.
register_adhocs
(
proc
)
commands
=
cls
.
traverse_commands
(
proc
,
inherit
ed
)
commands
=
cls
.
traverse_commands
(
proc
,
inherit
)
cls
.
register_commands
(
proc
,
commands
)
@classmethod
def
sanitize_names
(
cls
,
proc
):
inherit
ed
=
proc
.
__dict__
.
get
(
'
INHERIT
ED
'
)
commands
=
cls
.
traverse_commands
(
proc
,
inherit
ed
)
inherit
=
proc
.
__dict__
.
get
(
'
INHERIT
'
)
commands
=
cls
.
traverse_commands
(
proc
,
inherit
)
for
key
,
command
in
commands
:
if
not
proc
.
SAFE_NAME_SCAN_PATTERN
.
match
(
key
):
setattr
(
proc
,
proc
.
SAFE_NAME_SUBS_PATTERN
%
key
,
command
)
...
...
@@ -252,8 +252,8 @@ class Dispatcher(type):
pass
@classmethod
def
traverse_commands
(
cls
,
proc
,
inherit
ed
=
True
):
keys
=
dir
(
proc
)
if
inherit
ed
else
proc
.
__dict__
.
iterkeys
()
def
traverse_commands
(
cls
,
proc
,
inherit
=
True
):
keys
=
dir
(
proc
)
if
inherit
else
proc
.
__dict__
.
iterkeys
()
for
key
in
keys
:
value
=
getattr
(
proc
,
key
)
if
isinstance
(
value
,
Command
):
...
...
@@ -295,8 +295,8 @@ class Dispatcher(type):
commands
=
dict
(
cls
.
traverse_commands
(
proc
.
DISPATCHED_BY
))
if
proc
.
DISPATCHED_BY
in
cls
.
hosted
:
for
adhoc
in
cls
.
hosted
[
proc
.
DISPATCHED_BY
]:
inherit
ed
=
adhoc
.
__dict__
.
get
(
'
INHERIT
ED
'
)
commands
.
update
(
dict
(
cls
.
traverse_commands
(
adhoc
,
inherit
ed
)))
inherit
=
adhoc
.
__dict__
.
get
(
'
INHERIT
'
)
commands
.
update
(
dict
(
cls
.
traverse_commands
(
adhoc
,
inherit
)))
return
commands
.
values
()
class
CommandProcessor
(
object
):
...
...
@@ -311,8 +311,7 @@ class CommandProcessor(object):
to an object you are adding commands to.
Your subclass, which will contain commands should define in its body
IS_COMMAND_PROCESSOR = True in order to be included in the dispatching
table.
DISPATCH = True in order to be included in the dispatching table.
Every class you will drop the processor in should define DISPATCHED_BY set
to the same processor you are inheriting from.
...
...
@@ -326,7 +325,7 @@ class CommandProcessor(object):
whatever includes the host) you need to inherit you processor from the host
and set HOSTED_BY to that host.
INHERIT
ED
controls whether commands inherited from base classes (which could
INHERIT controls whether commands inherited from base classes (which could
include other processors) will be registered or not. This is disabled
by-default because it leads to unpredictable consequences when used in adhoc
processors which inherit from more then one processor or has such processors
...
...
This diff is collapsed.
Click to expand it.
src/commands/implementation.py
+
6
−
6
View file @
7bec311c
...
...
@@ -92,8 +92,8 @@ class ChatCommands(CommonCommands):
an instance of ChatControl when command is being called.
"""
IS
_COMMAND_PROCESSOR
=
True
INHERIT
ED
=
True
D
IS
PATCH
=
True
INHERIT
=
True
@command
def
ping
(
self
):
...
...
@@ -111,8 +111,8 @@ class PrivateChatCommands(CommonCommands):
self is set to an instance of PrivateChatControl when command is being called.
"""
IS
_COMMAND_PROCESSOR
=
True
INHERIT
ED
=
True
D
IS
PATCH
=
True
INHERIT
=
True
class
GroupChatCommands
(
CommonCommands
):
"""
...
...
@@ -121,8 +121,8 @@ class GroupChatCommands(CommonCommands):
self is set to an instance of GroupchatControl when command is being called.
"""
IS
_COMMAND_PROCESSOR
=
True
INHERIT
ED
=
True
D
IS
PATCH
=
True
INHERIT
=
True
@command
(
raw
=
True
)
def
nick
(
self
,
new_nick
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment