Skip to content

Commit

Permalink
Merge pull request #9 from plone/config-with-default-template-4a20aeff
Browse files Browse the repository at this point in the history
Config with default template
  • Loading branch information
jensens authored Apr 10, 2023
2 parents 4a20aef + 6bdb61b commit cab6ce2
Show file tree
Hide file tree
Showing 21 changed files with 803 additions and 641 deletions.
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
#
# EditorConfig Configuration file, for more details see:
# http://EditorConfig.org
# EditorConfig is a convention description, that could be interpreted
# by multiple editors to enforce common coding conventions for specific
# file types

# top-most EditorConfig file:
# Will ignore other EditorConfig files in Home directory or upper tree level.
root = true


[*] # For All Files
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# Set default charset
charset = utf-8
# Indent style default
indent_style = space
# Max Line Length - a hard line wrap, should be disabled
max_line_length = off

[*.{py,cfg,ini}]
# 4 space indentation
indent_size = 4

[*.{yml,zpt,pt,dtml,zcml}]
# 2 space indentation
indent_size = 2

[{Makefile,.gitmodules}]
# Tab indentation (no size specified, but view as 4 spaces)
indent_style = tab
indent_size = unset
tab_width = unset
5 changes: 5 additions & 0 deletions .meta.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
[meta]
template = "default"
commit-id = "3b8337e6"
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
ci:
autofix_prs: false
autoupdate_schedule: monthly

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/collective/zpretty
rev: 3.0.3
hooks:
- id: zpretty
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
- repo: https://github.com/regebro/pyroma
rev: "4.2"
hooks:
- id: pyroma
2 changes: 2 additions & 0 deletions news/3b8337e6.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update configuration files.
[plone devs]
3 changes: 1 addition & 2 deletions plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
1 change: 0 additions & 1 deletion plone/caching/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
73 changes: 43 additions & 30 deletions plone/caching/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="plone">

<include package="z3c.caching" file="meta.zcml" />
<include package="z3c.caching" />

<include package="plone.registry" />
<include package="plone.transformchain" />

<!-- Default lookup -->
<adapter factory=".lookup.DefaultRulesetLookup" />

<!-- The 'Chain' operation -->
<adapter factory=".operations.Chain" name="plone.caching.operations.chain" />
<utility component=".operations.Chain" name="plone.caching.operations.chain" />

<!-- Intercepts are performed by raising an exception prior to view
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone"
>

<include
package="z3c.caching"
file="meta.zcml"
/>
<include package="z3c.caching" />

<include package="plone.registry" />
<include package="plone.transformchain" />

<!-- Default lookup -->
<adapter factory=".lookup.DefaultRulesetLookup" />

<!-- The 'Chain' operation -->
<adapter
factory=".operations.Chain"
name="plone.caching.operations.chain"
/>
<utility
name="plone.caching.operations.chain"
component=".operations.Chain"
/>

<!-- Intercepts are performed by raising an exception prior to view
invocation. There is a view on this exception which renders the
intercepted response.
-->
<subscriber handler=".hooks.intercept" />
<browser:page
name="index.html"
for=".hooks.Intercepted"
class=".hooks.InterceptorResponse"
permission="zope2.Public"
/>

<!-- Mutator: plone.transformchain order 12000 -->
<adapter factory=".hooks.MutatorTransform" name="plone.caching.mutator" />

<!-- Mutator for streaming responses -->
<subscriber handler=".hooks.modifyStreamingResponse" />
<subscriber handler=".hooks.intercept" />
<browser:page
name="index.html"
for=".hooks.Intercepted"
class=".hooks.InterceptorResponse"
permission="zope2.Public"
/>

<!-- Mutator: plone.transformchain order 12000 -->
<adapter
factory=".hooks.MutatorTransform"
name="plone.caching.mutator"
/>

<!-- Mutator for streaming responses -->
<subscriber handler=".hooks.modifyStreamingResponse" />

</configure>
39 changes: 13 additions & 26 deletions plone/caching/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.caching.interfaces import X_CACHE_OPERATION_HEADER
from plone.caching.interfaces import X_CACHE_RULE_HEADER
from plone.caching.utils import findOperation
Expand All @@ -16,7 +15,7 @@
import logging


logger = logging.getLogger('plone.caching')
logger = logging.getLogger("plone.caching")


class IStreamedResponse(Interface):
Expand All @@ -36,12 +35,12 @@ class Intercepted(Exception):
responseBody = None
status = None

def __init__(self, status=304, responseBody=u""):
def __init__(self, status=304, responseBody=""):
self.status = status
self.responseBody = responseBody


class InterceptorResponse(object):
class InterceptorResponse:
"""View for the Intercepted exception, serving to return an empty
response in the case of an intercepted response.
"""
Expand All @@ -67,18 +66,15 @@ def intercept(event):

try:
request = event.request
published = request.get('PUBLISHED', None)
published = request.get("PUBLISHED", None)
rule, operationName, operation = findOperation(request)

if rule is None:
return

request.response.setHeader(X_CACHE_RULE_HEADER, rule)
logger.debug(
'Published: %s Ruleset: %s Operation: %s',
repr(published),
rule,
operation
"Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation
)

if operation is not None:
Expand All @@ -87,10 +83,7 @@ def intercept(event):
if responseBody is not None:
# Only put this in the response if the operation actually
# intercepted something
request.response.setHeader(
X_CACHE_OPERATION_HEADER,
operationName
)
request.response.setHeader(X_CACHE_OPERATION_HEADER, operationName)

# Stop any post-processing, including the operation's response
# modification
Expand All @@ -111,14 +104,13 @@ def intercept(event):
raise
except Exception:
logging.exception(
'Swallowed exception in plone.caching IPubAfterTraversal event '
'handler'
"Swallowed exception in plone.caching IPubAfterTraversal event " "handler"
)


@implementer(ITransform)
@adapter(Interface, Interface)
class MutatorTransform(object):
class MutatorTransform:
"""Transformation using plone.transformchain.
This is registered at order 12000, i.e. "late". A typical transform
Expand Down Expand Up @@ -159,24 +151,22 @@ def mutate(self):
if IStreamedResponse.providedBy(request):
return

published = request.get('PUBLISHED', None)
published = request.get("PUBLISHED", None)
rule, operationName, operation = findOperation(request)

if rule is None:
return

request.response.setHeader(X_CACHE_RULE_HEADER, rule)
logger.debug(
'Published: %s Ruleset: %s Operation: %s',
repr(published),
rule,
operation
"Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation
)

if operation is not None:
request.response.setHeader(X_CACHE_OPERATION_HEADER, operationName)
operation.modifyResponse(rule, request.response)


# Hook for streaming responses - does not use plone.transformchain, since
# sequencing is less likely to be an issue here

Expand All @@ -199,7 +189,7 @@ def modifyStreamingResponse(event):
# again in the normal hook above
alsoProvides(request, IStreamedResponse)

published = request.get('PUBLISHED', None)
published = request.get("PUBLISHED", None)

rule, operationName, operation = findOperation(request)

Expand All @@ -208,10 +198,7 @@ def modifyStreamingResponse(event):

response.setHeader(X_CACHE_RULE_HEADER, rule)
logger.debug(
'Published: %s Ruleset: %s Operation: %s',
repr(published),
rule,
operation
"Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation
)

if operation is not None:
Expand Down
Loading

0 comments on commit cab6ce2

Please sign in to comment.