Skip to content

Commit

Permalink
Merge pull request #24 from plone/config-with-default-template-3f6d9cbf
Browse files Browse the repository at this point in the history
Config with default template 3f6d9cb
  • Loading branch information
jensens authored Apr 13, 2023
2 parents 3f6d9cb + ad4de54 commit 89731e1
Show file tree
Hide file tree
Showing 25 changed files with 450 additions and 262 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 = "a9dd65cc"
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
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ New features:


- New option ``former_dotted_names`` that allows to register the former name
under which a behavior used to be registerd. This can be useful to ensure a
under which a behavior used to be registered. This can be useful to ensure a
smooth transition in case a behavior's dotted name is changed. [pysailor]
(#18)

Expand Down
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ The directive supports the attributes:
``name``
Convenience lookup name for this behavior (optional).
The behavior will be always registered under the dotted name of ``provides`` attribute.
This are usally long names. ``name`` is a short name for this.
This are usually long names. ``name`` is a short name for this.
If ``name`` is given the behavior is registered additional under it.
Anyway using short namespaces in ``name`` is recommended.

Expand Down Expand Up @@ -189,13 +189,13 @@ ZCML Examples

Example usage, given

- some ``context`` (some arbitary object) which is ``IBehaviorAssignable``,
- an ``IMyBehavior`` interface intented to be used as ``provides``,
- an ``IMyMarker`` interface intented to be used as ``marker``,
- some ``context`` (some arbitrary object) which is ``IBehaviorAssignable``,
- an ``IMyBehavior`` interface intended to be used as ``provides``,
- an ``IMyMarker`` interface intended to be used as ``marker``,
- a ``MyFactory`` class implementing ``IMyBehavior`` ,
- a ``MySchemaAwareFactory`` class implementing ``IMyBehavior`` and ``plone.behavior.interfaces.ISchemaAwareFactory``,
- an ``IMyType`` intented to be used as ``for``.
- some ``typed_context`` (some arbitary object) which is ``IBehaviorAssignable`` and provides ``IMyType``,
- an ``IMyType`` intended to be used as ``for``.
- some ``typed_context`` (some arbitrary object) which is ``IBehaviorAssignable`` and provides ``IMyType``,
- an ``MyTypedFactory`` class implementing ``IMyBehavior`` and adapting ``IMyType``,

``title`` and ``description`` is trivial, so we dont cover it here in the explanantion.
Expand All @@ -220,7 +220,7 @@ I.e. both is done by ``plone.dexterity``.
.. warning::
Using the same Interface as marker and behavior works, but is not recommended and will be deprecated in future.
It is semantically wrong!

Go for Example 3 instead!

::
Expand Down
2 changes: 2 additions & 0 deletions news/a9dd65cc.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__)
3 changes: 1 addition & 2 deletions plone/behavior/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Convenience import
from plone.behavior.annotation import AnnotationStorage # noqa

import logging


logger = logging.getLogger('plone.behavior')
logger = logging.getLogger("plone.behavior")
30 changes: 14 additions & 16 deletions plone/behavior/annotation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.behavior.interfaces import ISchemaAwareFactory
from zope.annotation.interfaces import IAnnotatable
from zope.annotation.interfaces import IAnnotations
Expand All @@ -8,7 +7,7 @@


@adapter(IAnnotatable)
class AnnotationsFactoryImpl(object):
class AnnotationsFactoryImpl:
"""A factory that knows how to store data in annotations.
Each value will be stored as a primitive in the annotations under a key
Expand All @@ -20,34 +19,33 @@ class AnnotationsFactoryImpl(object):
"""

def __init__(self, context, schema):
self.__dict__['schema'] = schema
self.__dict__['prefix'] = schema.__identifier__ + '.'
self.__dict__['annotations'] = IAnnotations(context)
self.__dict__["schema"] = schema
self.__dict__["prefix"] = schema.__identifier__ + "."
self.__dict__["annotations"] = IAnnotations(context)
alsoProvides(self, schema)

def __getattr__(self, name):
if name not in self.__dict__['schema']:
if name not in self.__dict__["schema"]:
raise AttributeError(name)

annotations = self.__dict__['annotations']
key_name = self.__dict__['prefix'] + name
annotations = self.__dict__["annotations"]
key_name = self.__dict__["prefix"] + name
if key_name not in annotations:
return self.__dict__['schema'][name].missing_value
return self.__dict__["schema"][name].missing_value

return annotations[key_name]

def __setattr__(self, name, value):
if name not in self.__dict__['schema']:
super(AnnotationsFactoryImpl, self).__setattr__(name, value)
if name not in self.__dict__["schema"]:
super().__setattr__(name, value)
else:
prefixed_name = self.__dict__['prefix'] + name
self.__dict__['annotations'][prefixed_name] = value
prefixed_name = self.__dict__["prefix"] + name
self.__dict__["annotations"][prefixed_name] = value


@provider(ISchemaAwareFactory)
class AnnotationStorage(object):
"""Behavior adapter factory class for storing data in annotations.
"""
class AnnotationStorage:
"""Behavior adapter factory class for storing data in annotations."""

def __init__(self, schema):
self.schema = schema
Expand Down
6 changes: 3 additions & 3 deletions plone/behavior/annotation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ Let's look at the annotations also::

If we now set the value, it will be stored in annotations::

>>> adapted.some_field = u'New value'
>>> adapted.some_field = 'New value'
>>> sorted(IAnnotations(context).items())
[('plone.behavior.tests.IAnnotationStored.some_field', u'New value')]
[('plone.behavior.tests.IAnnotationStored.some_field', 'New value')]

And of course we can get it back again::

>>> adapted.some_field
u'New value'
'New value'

If we try to get some other field, we get an AttributeError::

Expand Down
11 changes: 6 additions & 5 deletions plone/behavior/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="plone.behavior">
i18n_domain="plone.behavior"
>

<utility
component=".vocab.BehaviorsVocabularyFactory"
name="Behaviors"
/>
<utility
name="Behaviors"
component=".vocab.BehaviorsVocabularyFactory"
/>

</configure>
Loading

0 comments on commit 89731e1

Please sign in to comment.