Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
snakes
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2013-03-03 09:00:32 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5361dd23d859f17248d3fba8e3934c9a4f05842c
5361dd23
1 parent
ab3eb498
doc converted
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
26 deletions
snakes/plugins/hello.py
snakes/plugins/hello.py
View file @
5361dd2
"""An example plugin that allows instances class
C{PetriNet}
to say hello.
"""An example plugin that allows instances class
`PetriNet`
to say hello.
A new method
C{hello}
is added. The constructor is added a keyword
argument
C{hello} that must be the C{str} to print when calling
C{hello}, with one C{
%
s} that will be replaced by the name of the net
when C{hello}
is called.
A new method
`hello`
is added. The constructor is added a keyword
argument
`hello` that must be the `str` to print when calling `hello`,
with one `
%
s` that will be replaced by the name of the net when
`hello`
is called.
Defining a plugins need writing a module with a single function called
C{extend}
that takes a single argument that is the module to be
`extend`
that takes a single argument that is the module to be
extended.
Inside the function, extensions of the classes in the module are
defined as normal sub-classes.
The function
C{extend}
should return the extended module created by
C{snakes.plugins.build}
that takes as arguments: the name of the
The function
`extend`
should return the extended module created by
`snakes.plugins.build`
that takes as arguments: the name of the
extended module, the module taken as argument and the sub-classes
defined (expected as a list argument
C{*args}
in no special order).
defined (expected as a list argument
`*args`
in no special order).
If the plugin depends on other plugins, for instance C{foo} and
C{bar}, the function C{extend} should be decorated by
C{@depends('foo', 'bar')}.
If the plugin depends on other plugins, for instance `foo` and `bar`,
the function `extend` should be decorated by `@depends('foo', 'bar')`.
Read the source code of this module to have an example
"""
...
...
@@ -28,34 +27,34 @@ import snakes.plugins
@snakes.plugins.plugin
(
"snakes.nets"
)
def
extend
(
module
)
:
"""Extends
C{module}
"""Extends
`module`
"""
class
PetriNet
(
module
.
PetriNet
)
:
"""Extension of the class
C{PetriNet} in C{module}
"""Extension of the class
`PetriNet` in `module`
"""
def
__init__
(
self
,
name
,
**
args
)
:
"""When extending an existing method, take care that you
may
be working on an already extended class, so you so not
"""When extending an existing method, take care that you
may
be working on an already extended class, so you so not
know how its arguments have been changed. So, always use
those from the unextended class plus
C{**args}, remove
from it what your plugin needs and pass it to the method
of the
extended class if you need to call it.
those from the unextended class plus
`**args`, remove from
it what your plugin needs and pass it to the method of the
extended class if you need to call it.
>>> PetriNet('N').hello()
Hello from N
>>> PetriNet('N', hello='Hi! This is
%
s...').hello()
Hi! This is N...
@param args: plugin options
@keyword hello: the message to print, with
C{
%
s}
where the
net name should appear.
@type hello:
C{str}
@keyword hello: the message to print, with
`
%
s`
where the
net name should appear.
@type hello:
`str`
"""
self
.
_hello
=
args
.
pop
(
"hello"
,
"Hello from
%
s"
)
module
.
PetriNet
.
__init__
(
self
,
name
,
**
args
)
def
hello
(
self
)
:
"""A new method
C{hello}
"""A new method
`hello`
>>> n = PetriNet('N')
>>> n.hello()
Hello from N
...
...
Please
register
or
login
to post a comment