Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ask Solem
authored and
Ask Solem
committed
Feb 28, 2008
0 parents
commit 2f644ee
Showing
30 changed files
with
1,937 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Revision history for roleplay | ||
|
||
roleplay v0.8 Wed Jan 16 11:51:00 GMT+2 2007 [askh@opera.com] | ||
|
||
- Roleplay now passes all tests in the Perl6::Roles test suite. :) | ||
|
||
- Runtime composition seems to work now. | ||
|
||
- Now does conflict resolution, summation of roles, roles are not | ||
allowed to inherit from other roles (only use them as roles), requires | ||
|
||
- does() now works properly. It was really incomplete before. | ||
|
||
- has_role(instance, role, **kwargs) is now has_role(cls, *args, | ||
**kwargs) to summate multiple roles at a time. | ||
|
||
- Changed license to GPLv2. I ported the Perl6::Roles unit tests to | ||
python and they are GPL, so I'll change to be sure. | ||
|
||
roleplay v0.12 Mon Jan 14 09:26:00 GMT+2 2007 [askh@opera.com] | ||
|
||
- Now dies on conflict | ||
|
||
- apply flattened some methods from the role base class that shouldn't | ||
be there. fixed. | ||
|
||
- does() now traverses the method resolution order. | ||
|
||
- looks like the dream of using a role in the class definition is | ||
shattered :( The new syntax is: | ||
|
||
class Foo(object): | ||
def hello(self): | ||
return "hello world" | ||
|
||
does(Foo, Role1, Role2, Role3, ..., RoleN) | ||
|
||
|
||
|
||
roleplay v0.11 Mon Jan 14 09:26:00 GMT+2 2007 [askh@opera.com] | ||
|
||
- Just bolds out the fact that this is an alpha release. | ||
|
||
roleplay v0.1 Sat Jan 12 09:26:00 GMT+2 2007 [askh@opera.com] | ||
|
||
- Initial version. :) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
======================================== | ||
``roleplay:`` Python does Roles | ||
======================================== | ||
:Version: 0.8 | ||
|
||
Roleplay is an in-progress implementation of roles for Python. The current | ||
state is that it passes the Perl6-Roles_ test suite, which is not the final | ||
authority on Perl6 roles, but a Perl5 implementation. | ||
|
||
======================================= | ||
Synopsis | ||
======================================= | ||
|
||
Creating Roles | ||
______________ | ||
|
||
>>> from roleplay.role import Role | ||
|
||
>>> class LoadFrobulatorRole(Role): | ||
... ''' | ||
... Simple role example. | ||
... ''' | ||
... | ||
... # Roles can use the '__requires__' attribute to define a set | ||
... # of attributes/methods the class using the role has to | ||
... # define (or else it would get an exception). | ||
... | ||
... __requires__ = ["has_frobulator"] | ||
... | ||
... def save_frobulator(self, data): | ||
... | ||
... # Do something with data | ||
... # ..... | ||
... print "saving frobulator..." | ||
... | ||
... | ||
|
||
>>> class SaveFrobulatorRole(Role): | ||
... ''' | ||
... Another role example | ||
... ''' | ||
... | ||
... | ||
... def load_frobulator(self, article_id): | ||
... | ||
... # Do something with data | ||
... # ..... | ||
... print "loading frobulator..." | ||
... | ||
... | ||
|
||
Using Roles | ||
___________ | ||
|
||
>>> from roleplay import has_role, does | ||
|
||
>>> class Article(object): | ||
... ''' | ||
... This is our class using the roles. | ||
... ''' | ||
... | ||
... def __init__(self): | ||
... pass | ||
... | ||
... def load_article(self, id): | ||
... | ||
... if does(self, LoadFrobulatorRole): | ||
... self.load_frobulator(id) | ||
... # ... do other loading stuff ... # | ||
... | ||
... def save_article(self, data): | ||
... | ||
... if does(self, SaveFrobulatorRole): | ||
... self.save_frobulator(data) | ||
... # ... do other saving stuff ... # | ||
... | ||
... | ||
... # This is the requirement for RoleA. | ||
... def has_frobulator(self): | ||
... frobulator = config.lookup('frobulator') | ||
... return frobulator | ||
... | ||
... | ||
... has_role(Article, LoadFrobulatorRole, SaveFrobulatorRole) | ||
... | ||
... | ||
... article = Article() | ||
... | ||
... art = article.load_article(13) | ||
... article.save_article(art) | ||
... | ||
|
||
====================================== | ||
Installation | ||
====================================== | ||
|
||
To install: | ||
|
||
>>> python ./setup.py install | ||
|
||
|
||
Or via easy_install: | ||
|
||
>>> easy_install roleplay | ||
|
||
|
||
======================================= | ||
Acknowledgements | ||
======================================= | ||
|
||
Thanks to Rob Kinyon and Stevan Little for the Perl6-Roles_ test suite, | ||
hope you don't mind me porting it to python :) | ||
|
||
|
||
.. _Perl6-Roles: http://search.cpan.org/perldoc?Perl6::Role | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* check doesx thingie. How do you get access to the object of the caller class? | ||
* __excludes__ | ||
* aliasing | ||
* conflict resolution | ||
* summation (UNION) | ||
* does: depth-first search of the role hierarchy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
for test in $(find tests -type f -name "*.py"); do | ||
python "$test" | ||
done |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# $Id$ | ||
# $Source$ | ||
# $Author$ | ||
# $HeadURL$ | ||
# $Revision$ | ||
# $Date$ | ||
''' | ||
Example class using the revision role | ||
''' | ||
|
||
from roleplay import does, has_role | ||
from examples.revisions import RevisionRole | ||
|
||
class MyClass(object): | ||
table = "foo" | ||
primary_key = 'id' | ||
|
||
def hello(self): | ||
return self.save_revision() | ||
|
||
has_role(MyClass, RevisionRole) | ||
|
||
obj = MyClass() | ||
|
||
obj.hello() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: ascii -*- | ||
# $Id$ | ||
# $Source$ | ||
# $Author$ | ||
# $HeadURL$ | ||
# $Revision$ | ||
# $Date$ | ||
''' | ||
Example Role | ||
''' | ||
|
||
from roleplay.role import Role | ||
|
||
class RevisionRole(Role): | ||
|
||
__requires__ = "table primary_key".split() | ||
|
||
def save_revision(self): | ||
print "saving revision..." | ||
|
||
class DuplicateRevisionRole(Role): | ||
|
||
__requires__ = "table primary_key".split() | ||
|
||
def save_revision(self): | ||
print "saving revision..." | ||
|
||
# Local Variables: | ||
# mode: cpython | ||
# cpython-indent-level: 4 | ||
# fill-column: 78 | ||
# End: | ||
# vim: expandtab tabstop=4 shiftwidth=4 shiftround |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
Metadata-Version: 1.0 | ||
Name: roleplay | ||
Version: 0.8 | ||
Summary: Python does Roles | ||
Home-page: http://pypi.python.org/pypi/roleplay/ | ||
Author: Ask Solem | ||
Author-email: askh@opera.com | ||
License: UNKNOWN | ||
Description: ======================================== | ||
``roleplay:`` Python does Roles | ||
======================================== | ||
:Version: 0.8 | ||
|
||
Roleplay is an in-progress implementation of roles for Python. The current | ||
state is that it passes the Perl6-Roles_ test suite, which is not the final | ||
authority on Perl6 roles, but a Perl5 implementation. | ||
|
||
======================================= | ||
Synopsis | ||
======================================= | ||
|
||
Creating Roles | ||
______________ | ||
|
||
>>> from roleplay.role import Role | ||
|
||
>>> class LoadFrobulatorRole(Role): | ||
... ''' | ||
... Simple role example. | ||
... ''' | ||
... | ||
... # Roles can use the '__requires__' attribute to define a set | ||
... # of attributes/methods the class using the role has to | ||
... # define (or else it would get an exception). | ||
... | ||
... __requires__ = ["has_frobulator"] | ||
... | ||
... def save_frobulator(self, data): | ||
... | ||
... # Do something with data | ||
... # ..... | ||
... print "saving frobulator..." | ||
... | ||
... | ||
|
||
>>> class SaveFrobulatorRole(Role): | ||
... ''' | ||
... Another role example | ||
... ''' | ||
... | ||
... | ||
... def load_frobulator(self, article_id): | ||
... | ||
... # Do something with data | ||
... # ..... | ||
... print "loading frobulator..." | ||
... | ||
... | ||
|
||
Using Roles | ||
___________ | ||
|
||
>>> from roleplay import has_role, does | ||
|
||
>>> class Article(object): | ||
... ''' | ||
... This is our class using the roles. | ||
... ''' | ||
... | ||
... def __init__(self): | ||
... pass | ||
... | ||
... def load_article(self, id): | ||
... | ||
... if does(self, LoadFrobulatorRole): | ||
... self.load_frobulator(id) | ||
... # ... do other loading stuff ... # | ||
... | ||
... def save_article(self, data): | ||
... | ||
... if does(self, SaveFrobulatorRole): | ||
... self.save_frobulator(data) | ||
... # ... do other saving stuff ... # | ||
... | ||
... | ||
... # This is the requirement for RoleA. | ||
... def has_frobulator(self): | ||
... frobulator = config.lookup('frobulator') | ||
... return frobulator | ||
... | ||
... | ||
... has_role(Article, LoadFrobulatorRole, SaveFrobulatorRole) | ||
... | ||
... | ||
... article = Article() | ||
... | ||
... art = article.load_article(13) | ||
... article.save_article(art) | ||
... | ||
|
||
====================================== | ||
Installation | ||
====================================== | ||
|
||
To install: | ||
|
||
>>> python ./setup.py install | ||
|
||
|
||
Or via easy_install: | ||
|
||
>>> easy_install roleplay | ||
|
||
|
||
======================================= | ||
Acknowledgements | ||
======================================= | ||
|
||
Thanks to Rob Kinyon and Stevan Little for the Perl6-Roles_ test suite, | ||
hope you don't mind me porting it to python :) | ||
|
||
|
||
.. _Perl6-Roles: http://search.cpan.org/perldoc?Perl6::Role | ||
|
||
|
||
|
||
Platform: UNKNOWN | ||
Classifier: Development Status :: 3 - Alpha | ||
Classifier: Intended Audience :: Developers | ||
Classifier: License :: OSI Approved :: GNU General Public License (GPL) | ||
Classifier: Operating System :: OS Independent | ||
Classifier: Programming Language :: Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
README.txt | ||
setup.cfg | ||
setup.py | ||
examples/__init__.py | ||
examples/class_using_roles.py | ||
examples/revision.py | ||
roleplay/__init__.py | ||
roleplay/inheritable.py | ||
roleplay/keyword.py | ||
roleplay/meta.py | ||
roleplay/role.py | ||
roleplay.egg-info/PKG-INFO | ||
roleplay.egg-info/SOURCES.txt | ||
roleplay.egg-info/dependency_links.txt | ||
roleplay.egg-info/top_level.txt | ||
tests/TAP.py | ||
tests/__init__.py | ||
tests/conftest.py | ||
tests/interface.py | ||
tests/roles/__init__.py | ||
tests/roles/does_is_recursive.py | ||
tests/roles/method_conflict.py | ||
tests/roles/requires.py | ||
tests/roles/roles.py | ||
tests/roles/runtime_composition.py | ||
tests/roles/subroles.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.