Skip to content

Commit

Permalink
Merge c1eea90 into 9936469
Browse files Browse the repository at this point in the history
  • Loading branch information
sallner committed Feb 22, 2022
2 parents 9936469 + c1eea90 commit 9449eab
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 17 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Expand Up @@ -92,6 +92,7 @@ jobs:
# with `test`, and `docs` must use a subset.
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version:
- 2.7
Expand Down Expand Up @@ -171,6 +172,7 @@ jobs:
needs: build-package
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version:
- 2.7
Expand Down Expand Up @@ -229,11 +231,9 @@ jobs:
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
run: |
python -m coverage run -p -m zope.testrunner --test-path=src --auto-color --auto-progress
# This is not supported
# - name: Run tests without C extensions
# run:
# # coverage makes PyPy run about 3x slower!
# PURE_PYTHON=1 python -m coverage run -p -m zope.testrunner --test-path=src --auto-color --auto-progress
- name: Run tests without C extensions
run: |
PURE_PYTHON=1 python -m coverage run -p -m zope.testrunner --test-path=src --auto-color --auto-progress
- name: Report Coverage
run: |
coverage combine
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -8,6 +8,8 @@ For changes before version 3.0, see ``HISTORY.rst``.

- Provide ``AccessControl.get_safe_globals`` to facilitate safe use.

- Honor ``PURE_PYTHON`` environment variable to enable python implementation
during runtime.


5.2 (2021-07-30)
Expand Down
1 change: 0 additions & 1 deletion buildout.cfg
Expand Up @@ -7,7 +7,6 @@ parts = interpreter test coverage

[versions]
AccessControl =
RestrictedPython =

[interpreter]
recipe = zc.recipe.egg
Expand Down
17 changes: 9 additions & 8 deletions src/AccessControl/ImplPython.py
Expand Up @@ -26,13 +26,12 @@
from ExtensionClass import Base
from zope.interface import implementer

# This is used when a permission maps explicitly to no permission. We
# try and get this from cAccessControl first to make sure that if both
# security implementations exist, we can switch between them later.
try:
from AccessControl.cAccessControl import _what_not_even_god_should_do
except ImportError:
PURE_PYTHON = int(os.environ.get('PURE_PYTHON', '0'))
if PURE_PYTHON:
# We need our own to not depend on the C implementation:
_what_not_even_god_should_do = []
else:
from AccessControl.cAccessControl import _what_not_even_god_should_do

from AccessControl.interfaces import ISecurityManager
from AccessControl.interfaces import ISecurityPolicy
Expand All @@ -42,6 +41,8 @@
from AccessControl.SimpleObjectPolicies import _noroles
from AccessControl.unauthorized import Unauthorized
from AccessControl.ZopeGuards import guarded_getitem # NOQA


# AccessControl.ZopeSecurityPolicy
# --------------------------------
#
Expand Down Expand Up @@ -76,8 +77,8 @@ def rolesForPermissionOn(perm, object, default=_default_roles, n=None):
roles = getattr(object, n)
if roles is None:
if _embed_permission_in_roles:
return ('Anonymous', n)
return 'Anonymous'
return (('Anonymous',), n)
return ('Anonymous',)

t = type(roles)
if t is tuple:
Expand Down
12 changes: 11 additions & 1 deletion src/AccessControl/Implementation.py
Expand Up @@ -26,6 +26,12 @@
"""
from __future__ import absolute_import

import os


PURE_PYTHON = int(os.environ.get('PURE_PYTHON', '0'))
CAPI = not PURE_PYTHON


def getImplementationName():
"""Return the name of the implementation currently being used."""
Expand Down Expand Up @@ -96,7 +102,11 @@ def setImplementation(name):
),
}

setImplementation(_default_implementation)

if CAPI:
setImplementation(_default_implementation)
else:
setImplementation('PYTHON')

# allow the implementation to change from the default
_implementation_set = 0
2 changes: 2 additions & 0 deletions src/AccessControl/tests/testSecurityManager.py
Expand Up @@ -14,6 +14,7 @@
"""Tests for the SecurityManager implementations
"""

import os
import unittest


Expand Down Expand Up @@ -250,6 +251,7 @@ def _getTargetClass(self):
return SecurityManager


@unittest.skipIf(os.environ.get('PURE_PYTHON'), reason="Test expects C impl.")
class C_SecurityManagerTests(SecurityManagerTestBase,
ISecurityManagerConformance,
unittest.TestCase):
Expand Down
2 changes: 2 additions & 0 deletions src/AccessControl/tests/testZopeGuards.py
Expand Up @@ -167,9 +167,11 @@ class TestGuardedHasattr(GuardTestCase):
def setUp(self):
self.__sm = SecurityManager()
self.__old = self.setSecurityManager(self.__sm)
gc.disable()

def tearDown(self):
self.setSecurityManager(self.__old)
gc.enable()

def test_miss(self):
from AccessControl.ZopeGuards import guarded_hasattr
Expand Down
6 changes: 4 additions & 2 deletions src/AccessControl/tests/testZopeSecurityPolicy.py
Expand Up @@ -11,6 +11,7 @@
#
##############################################################################

import os
import sys
import unittest
from doctest import DocTestSuite
Expand Down Expand Up @@ -775,9 +776,10 @@ def loop():
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Python_ZSPTests))
suite.addTest(unittest.makeSuite(C_ZSPTests))
suite.addTest(unittest.makeSuite(Python_SMTests))
suite.addTest(unittest.makeSuite(C_SMTests))
if not os.environ.get('PURE_PYTHON'):
suite.addTest(unittest.makeSuite(C_ZSPTests))
suite.addTest(unittest.makeSuite(C_SMTests))
suite.addTest(DocTestSuite())
suite.addTest(unittest.makeSuite(GetRolesWithMultiThreadTest))
return suite
2 changes: 2 additions & 0 deletions tox.ini
Expand Up @@ -19,6 +19,8 @@ deps =
setuptools < 52
zc.buildout
skip_install = true
setenv =
PURE_PYTHON=1

[testenv:coverage]
basepython = python3
Expand Down

0 comments on commit 9449eab

Please sign in to comment.