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
eta
gajim
Commits
48b2bfd7
Commit
48b2bfd7
authored
15 years ago
by
Alexander Cherniuk
Browse files
Options
Downloads
Patches
Plain Diff
Added a comment about command escaping and tiny touchups
parent
faca8c5d
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/command_system/errors.py
+6
-0
6 additions, 0 deletions
src/command_system/errors.py
src/command_system/framework.py
+2
-2
2 additions, 2 deletions
src/command_system/framework.py
src/command_system/implementation/middleware.py
+18
-11
18 additions, 11 deletions
src/command_system/implementation/middleware.py
with
26 additions
and
13 deletions
src/command_system/errors.py
+
6
−
0
View file @
48b2bfd7
...
...
@@ -45,3 +45,9 @@ class CommandError(BaseError):
Used to indicate errors occured during command execution.
"""
pass
class
NoCommandError
(
BaseError
):
"""
Used to indicate an inability to find the specified command.
"""
pass
This diff is collapsed.
Click to expand it.
src/command_system/framework.py
+
2
−
2
View file @
48b2bfd7
...
...
@@ -25,7 +25,7 @@ from inspect import getargspec
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 @@ class CommandProcessor(object):
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
No
CommandError
(
"
Command does not exist
"
,
name
=
name
)
return
command
def
list_commands
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/command_system/implementation/middleware.py
+
18
−
11
View file @
48b2bfd7
...
...
@@ -26,7 +26,7 @@ from traceback import print_exc
from
common
import
gajim
from
..framework
import
CommandProcessor
from
..errors
import
CommandError
from
..errors
import
CommandError
,
NoCommandError
class
ChatCommandProcessor
(
CommandProcessor
):
"""
...
...
@@ -44,33 +44,40 @@ class ChatCommandProcessor(CommandProcessor):
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
)
...
...
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