-
Notifications
You must be signed in to change notification settings - Fork 3
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
Michael Howitz
committed
Mar 21, 2010
1 parent
385900d
commit 676889b
Showing
7 changed files
with
195 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,52 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2006 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Bootstrap a buildout-based project | ||
Simply run this script in a directory containing a buildout.cfg. | ||
The script accepts buildout command-line options, so you can | ||
use the -c option to specify an alternate configuration file. | ||
$Id$ | ||
""" | ||
|
||
import os, shutil, sys, tempfile, urllib2 | ||
|
||
tmpeggs = tempfile.mkdtemp() | ||
|
||
ez = {} | ||
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' | ||
).read() in ez | ||
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) | ||
|
||
import pkg_resources | ||
|
||
cmd = 'from setuptools.command.easy_install import main; main()' | ||
if sys.platform == 'win32': | ||
cmd = '"%s"' % cmd # work around spawn lamosity on windows | ||
|
||
ws = pkg_resources.working_set | ||
assert os.spawnle( | ||
os.P_WAIT, sys.executable, sys.executable, | ||
'-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout', | ||
dict(os.environ, | ||
PYTHONPATH= | ||
ws.find(pkg_resources.Requirement.parse('setuptools')).location | ||
), | ||
) == 0 | ||
|
||
ws.add_entry(tmpeggs) | ||
ws.require('zc.buildout') | ||
import zc.buildout.buildout | ||
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap']) | ||
shutil.rmtree(tmpeggs) |
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,18 @@ | ||
[buildout] | ||
develop = . | ||
parts = test coverage-test coverage-report | ||
|
||
[test] | ||
recipe = zc.recipe.testrunner | ||
eggs = zope.app.localpermission | ||
|
||
[coverage-test] | ||
recipe = zc.recipe.testrunner | ||
eggs = zope.app.localpermission | ||
defaults = ['--coverage', '../../coverage'] | ||
|
||
[coverage-report] | ||
recipe = zc.recipe.egg | ||
eggs = z3c.coverage | ||
scripts = coverage=coverage-report | ||
arguments = ('coverage', 'coverage/report') |
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 @@ | ||
__import__('pkg_resources').declare_namespace(__name__) |
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 @@ | ||
__import__('pkg_resources').declare_namespace(__name__) |
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 @@ | ||
from zope.app.localpermission.permission import LocalPermission |
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,98 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2009 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Persistent Local Permissions | ||
$Id: permission.py 97714 2009-03-09 18:52:31Z nadako $ | ||
""" | ||
__docformat__ = 'restructuredtext' | ||
|
||
from persistent import Persistent | ||
from zope.component import adapter | ||
from zope.component.interfaces import IRegistered, IUnregistered | ||
from zope.i18nmessageid import MessageFactory | ||
from zope.interface import implements | ||
from zope.location import Location | ||
from zope.security.interfaces import IPermission | ||
|
||
_ = MessageFactory('zope') | ||
|
||
NULL_ID = _(u'<permission not activated>') | ||
|
||
|
||
class LocalPermission(Persistent, Location): | ||
implements(IPermission) | ||
|
||
def __init__(self, title=u'', description=u''): | ||
self.id = NULL_ID | ||
self.title = title | ||
self.description = description | ||
|
||
|
||
@adapter(IPermission, IRegistered) | ||
def setIdOnActivation(permission, event): | ||
"""Set the permission id upon registration activation. | ||
Let's see how this notifier can be used. First we need to create an event | ||
using the permission instance and a registration stub: | ||
>>> class Registration: | ||
... def __init__(self, obj, name): | ||
... self.component = obj | ||
... self.name = name | ||
>>> perm1 = LocalPermission('Permission 1', 'A first permission') | ||
>>> perm1.id | ||
u'<permission not activated>' | ||
>>> import zope.component.interfaces | ||
>>> event = zope.component.interfaces.Registered( | ||
... Registration(perm1, 'perm1')) | ||
Now we pass the event into this function, and the id of the permission | ||
should be set to 'perm1'. | ||
>>> setIdOnActivation(perm1, event) | ||
>>> perm1.id | ||
'perm1' | ||
""" | ||
permission.id = event.object.name | ||
|
||
|
||
@adapter(IPermission, IUnregistered) | ||
def unsetIdOnDeactivation(permission, event): | ||
"""Unset the permission id up registration deactivation. | ||
Let's see how this notifier can be used. First we need to create an event | ||
using the permission instance and a registration stub: | ||
>>> class Registration: | ||
... def __init__(self, obj, name): | ||
... self.component = obj | ||
... self.name = name | ||
>>> perm1 = LocalPermission('Permission 1', 'A first permission') | ||
>>> perm1.id = 'perm1' | ||
>>> import zope.component.interfaces | ||
>>> event = zope.component.interfaces.Unregistered( | ||
... Registration(perm1, 'perm1')) | ||
Now we pass the event into this function, and the id of the permission | ||
should be set to NULL_ID. | ||
>>> unsetIdOnDeactivation(perm1, event) | ||
>>> perm1.id | ||
u'<permission not activated>' | ||
""" | ||
permission.id = NULL_ID |
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,24 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2004 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Tests for zope.localpermission. | ||
$Id$ | ||
""" | ||
import unittest | ||
import doctest | ||
|
||
def test_suite(): | ||
return unittest.TestSuite(( | ||
doctest.DocTestSuite('zope.app.localpermission.permission'), | ||
)) |