././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1785610635.553569
lazr_delegates-4.0.0/ 0000775 0001750 0001750 00000000000 15233440614 014074 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/.flake8 0000664 0001750 0001750 00000000104 15233437661 015252 0 ustar 00finnrg finnrg [flake8]
ignore =
# Incompatible with Black.
E203,
W503
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/.launchpad.yaml 0000664 0001750 0001750 00000003504 15233437661 017007 0 ustar 00finnrg finnrg pipeline:
- test-focal
- test-jammy
- test-noble
# - test-resolute
- lint
- docs
- audit
jobs:
# focal's apt tox (3.13.2) cannot build a pyproject-only sdist
# ("error: option --formats not recognized"), so install a modern tox in a
# throwaway venv. skip_install envs (lint/docs/audit on noble) are unaffected.
test-focal:
series: focal
architectures: amd64
packages: [git, python3-venv, python3.9]
run: |
python3 -m venv /tmp/tox
/tmp/tox/bin/pip install --upgrade pip
# 4.26.0 dropped Python 3.8 (which runs this venv); 4.25.0 is the newest
# tox that still runs on 3.8. focal ships both 3.8 (default) and 3.9.
/tmp/tox/bin/pip install "tox<4.26"
/tmp/tox/bin/tox -e py38,py39
test-jammy:
series: jammy
architectures: amd64
packages: [git, python3-venv, python3.11]
# jammy's apt tox (3.x) also cannot build a pyproject-only sdist, so use a
# throwaway venv with a modern tox. jammy ships both 3.10 (default) and 3.11.
run: |
python3 -m venv /tmp/tox
/tmp/tox/bin/pip install --upgrade pip
/tmp/tox/bin/pip install tox
/tmp/tox/bin/tox -e py310,py311
test-noble:
series: noble
architectures: amd64
packages: [git, tox]
run: tox -e py312
test-resolute:
series: resolute
architectures: amd64
packages: [git, tox]
run: tox -e py314
lint:
series: noble # align with Python versions used in tox configuration
architectures: amd64
packages: [tox, git]
run: tox -e lint
docs:
series: noble # align with Python versions used in tox configuration
architectures: amd64
packages: [tox, git]
run: tox -e docs
audit:
series: noble # align with Python versions used in tox configuration
architectures: amd64
packages: [tox, git]
run: tox -e audit
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/.pre-commit-config.yaml 0000664 0001750 0001750 00000002062 15233437661 020365 0 ustar 00finnrg finnrg # See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- repo: https://github.com/PyCQA/isort
rev: 9.0.0a3
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade
- repo: https://github.com/mgedmin/check-manifest
rev: "0.51"
hooks:
- id: check-manifest
- repo: https://github.com/psf/black
rev: 26.5.1
hooks:
- id: black
- repo: https://github.com/PyCQA/bandit
rev: 1.9.4
hooks:
- id: bandit
args: ["--severity-level", "high"]
- repo: https://github.com/pypa/pip-audit
rev: v2.10.1
hooks:
- id: pip-audit
additional_dependencies: ["pip>=26.1.2"]
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/.readthedocs.yaml 0000664 0001750 0001750 00000000361 15221773336 017332 0 ustar 00finnrg finnrg version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
python:
install:
- method: pip
path: .
extra_requirements:
- docs
sphinx:
configuration: src/lazr/delegates/docs/conf.py
fail_on_warning: true
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/CONTRIBUTING.rst 0000664 0001750 0001750 00000003002 15233437661 016540 0 ustar 00finnrg finnrg ..
This file is part of lazr.delegates.
lazr.delegates is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, version 3 of the License.
lazr.delegates is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with lazr.delegates. If not, see .
============
Contributing
============
Getting the code
----------------
The source is maintained in git::
git clone https://git.launchpad.net/lazr.delegates
Running the tests
-----------------
Use `tox `_::
tox
This runs the linters, the test suite across supported Python versions, the
documentation build, and a dependency audit.
Documentation
-------------
To update the `project's documentation
`_ trigger a manual build on the
project's dashboard at https://readthedocs.org.
Getting help
------------
If you find bugs in this package, report them at:
https://launchpad.net/lazr.delegates
To discuss this package, join the team and mailing list at:
https://launchpad.net/~lazr-developers
or email:
lazr-developers@lists.launchpad.net
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/COPYING.txt 0000664 0001750 0001750 00000016725 15221773336 015767 0 ustar 00finnrg finnrg GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/MANIFEST.in 0000664 0001750 0001750 00000000176 15233437661 015646 0 ustar 00finnrg finnrg include *.txt *.rst *.md MANIFEST.in *.ini
recursive-include src/lazr *.rst
exclude .bzrignore
include *.yaml
include .flake8
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/NEWS.rst 0000664 0001750 0001750 00000004426 15233437661 015420 0 ustar 00finnrg finnrg =======================
NEWS for lazr.delegates
=======================
4.0.0 (unreleased)
==================
- Replace ``pkg_resources`` namespace with a PEP 420 native namespace.
- Consolidate packaging into a single ``pyproject.toml`` (remove ``setup.py``,
``setup.cfg``).
- Add support for Python 3.14.
- Update security auditing and linting.
- Standardize tox, Launchpad CI, pre-commit, and contributor documentation.
2.1.1 (2024-12-05)
==================
- Add support for Python 3.12 and 3.13.
- Drop support for Python 3.5, 3.6 and 3.7.
2.1.0 (2023-03-20)
==================
- Officially add support for Python 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11.
- Drop support for Python 2, 3.2, 3.3, and 3.4.
- Test using ``zope.testrunner`` rather than ``nose``.
- Bring coverage to 100%.
- Switch to declarative ``setuptools`` configuration.
- Add linters.
- Fix the `woke` linter.
2.0.4 (2017-10-20)
==================
- Adjust versioning strategy to avoid importing pkg_resources, which is slow
in large environments.
2.0.3 (2015-07-08)
==================
- Restore the public import of ``lazr.delegates.Passthrough`` which was
inadvertently lost during the port to Python 3.
- Officially add support for Python 3.5.
- Drop official Python 2.6 support.
2.0.2 (2015-01-05)
==================
- Always use old-style namespace package registration in ``lazr/__init__.py``
since the mere presence of this file subverts PEP 420 style namespace
packages. (LP: #1407816)
2.0.1 (2014-08-21)
==================
- Drop the use of `distribute` in favor of `setuptools`. (LP: #1359927)
- Run the test suite with `tox`.
2.0 (2013-01-10)
================
- Port to Python 3, which requires the use of the ``@delegate_to`` class
decorator instead of the ``delegates()`` function call. Officially support
Python 2.6, 2.7, 3.2, and 3.3.
1.2.0 (2010-07-16)
==================
- Extend Passthrough so that it takes an extra (optional) callable argument,
used to adapt the context before accessing the delegated attribute.
1.1.0 (2009-08-31)
==================
- Remove build dependencies on bzr and egg_info
- remove sys.path hack in setup.py for __version__
1.0.1 (2009-03-24)
==================
- specify only v3 of LGPL
- build/developer improvements
1.0 (2008-12-19)
================
- Initial release
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1785610635.553557
lazr_delegates-4.0.0/PKG-INFO 0000644 0001750 0001750 00000003421 15233440614 015167 0 ustar 00finnrg finnrg Metadata-Version: 2.4
Name: lazr.delegates
Version: 4.0.0
Summary: Easily write objects that delegate behavior
Maintainer: LAZR Developers
License: LGPL v3
Project-URL: Homepage, https://launchpad.net/lazr.delegates
Project-URL: Source, https://code.launchpad.net/lazr.delegates
Project-URL: Issue Tracker, https://bugs.launchpad.net/lazr.delegates
Project-URL: Documentation, https://lazrdelegates.readthedocs.io/en/latest/
Project-URL: Download, https://launchpad.net/lazr.delegates/+download
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.8
Description-Content-Type: text/x-rst
License-File: COPYING.txt
Requires-Dist: zope.interface
Provides-Extra: docs
Requires-Dist: Sphinx; extra == "docs"
Provides-Extra: test
Requires-Dist: zope.testing>=4.6.0; extra == "test"
Requires-Dist: zope.testrunner>=6.6.1; extra == "test"
Dynamic: license-file
The ``lazr.delegates`` package makes it easy to write objects that delegate
behavior to another object. The new object adds some property or behavior on
to the other object, while still providing the underlying interface, and
delegating behavior.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/README.rst 0000664 0001750 0001750 00000000367 15221773336 015600 0 ustar 00finnrg finnrg The ``lazr.delegates`` package makes it easy to write objects that delegate
behavior to another object. The new object adds some property or behavior on
to the other object, while still providing the underlying interface, and
delegating behavior.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/SECURITY.md 0000664 0001750 0001750 00000001745 15221773336 015703 0 ustar 00finnrg finnrg # Launchpad Security Policy
If you discover a security vulnerability, please follow the steps outlined below to report it:
1. **Do not** publicly disclose the vulnerability before discussing it with us.
2. Contact us via email at [feedback@launchpad.net](mailto:feedback@launchpad.net).
3. Provide detailed information about the vulnerability, including:
- A description of the vulnerability.
- Steps to reproduce the issue.
- Potential impact and affected versions.
- Suggested mitigations, if possible.
The [Ubuntu Security disclosure and embargo policy](https://ubuntu.com/security/disclosure-policy) contains more information about what you can expect when you contact us and what we expect from you.
The Launchpad team will be notified of the issue and review the vulnerability. We may reach out to you for further information or clarification if needed. If the issue is confirmed as a valid security vulnerability, we will assign a CVE and coordinate the release of the fix.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/pyproject.toml 0000664 0001750 0001750 00000003532 15233437661 017023 0 ustar 00finnrg finnrg [build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "lazr.delegates"
version = "4.0.0"
description = "Easily write objects that delegate behavior"
readme = "README.rst"
requires-python = ">=3.8"
license = { text = "LGPL v3" }
maintainers = [
{ name = "LAZR Developers" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
dependencies = [
"zope.interface",
]
[project.optional-dependencies]
docs = ["Sphinx"]
test = [
"zope.testing>=4.6.0",
"zope.testrunner>=6.6.1",
]
[project.urls]
Homepage = "https://launchpad.net/lazr.delegates"
Source = "https://code.launchpad.net/lazr.delegates"
"Issue Tracker" = "https://bugs.launchpad.net/lazr.delegates"
Documentation = "https://lazrdelegates.readthedocs.io/en/latest/"
Download = "https://launchpad.net/lazr.delegates/+download"
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
where = ["src"]
namespaces = true
[tool.black]
line-length = 79
target-version = ["py38"]
[tool.isort]
known_first_party = "lazr.delegates"
line_length = 79
profile = "black"
[tool.coverage.run]
source = ["lazr.delegates"]
omit = ["*/docs/conf.py"]
[tool.coverage.paths]
source = ["src", ".tox/*/site-packages"]
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5537024
lazr_delegates-4.0.0/setup.cfg 0000664 0001750 0001750 00000000046 15233440614 015715 0 ustar 00finnrg finnrg [egg_info]
tag_build =
tag_date = 0
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5503795
lazr_delegates-4.0.0/src/ 0000775 0001750 0001750 00000000000 15233440614 014663 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5503795
lazr_delegates-4.0.0/src/lazr/ 0000775 0001750 0001750 00000000000 15233440614 015633 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5523098
lazr_delegates-4.0.0/src/lazr/delegates/ 0000775 0001750 0001750 00000000000 15233440614 017570 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/src/lazr/delegates/__init__.py 0000664 0001750 0001750 00000002317 15233437661 021714 0 ustar 00finnrg finnrg # Copyright 2008-2015 Canonical Ltd. All rights reserved.
#
# This file is part of lazr.delegates.
#
# lazr.delegates is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# lazr.delegates is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.delegates. If not, see .
"""Decorator helpers that simplify class composition."""
__all__ = [
"Passthrough",
"delegate_to",
]
try:
import importlib.metadata as importlib_metadata
except ImportError: # pragma: no cover
import importlib_metadata
from lazr.delegates._delegates import (
Passthrough,
delegate_to,
)
try:
__version__ = importlib_metadata.version("lazr.delegates")
except importlib_metadata.PackageNotFoundError: # pragma: no cover
__version__ = importlib_metadata.version("lazr-delegates")
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/src/lazr/delegates/_delegates.py 0000664 0001750 0001750 00000006564 15233437661 022261 0 ustar 00finnrg finnrg # Copyright 2008-2022 Canonical Ltd. All rights reserved.
#
# This file is part of lazr.delegates.
#
# lazr.delegates is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# lazr.delegates is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.delegates. If not, see .
"""Decorator helpers that simplify class composition."""
__all__ = [
"Passthrough",
"delegate_to",
]
from zope.interface import classImplements
def delegate_to(*interfaces, context="context"):
"""Make an adapter into a decorator.
Use like:
@implementer(IRosettaProject)
@delegate_to(IProject)
class RosettaProject:
def __init__(self, context):
self.context = context
def methodFromRosettaProject(self):
return self.context.methodFromIProject()
If you want to use a different name than "context" then you can explicitly
say so:
@implementer(IRosettaProject)
@delegate_to(IProject, context='project')
class RosettaProject:
def __init__(self, project):
self.project = project
def methodFromRosettaProject(self):
return self.project.methodFromIProject()
The adapter class will implement the interface it is decorating.
The minimal decorator looks like this:
@delegate_to(IProject)
class RosettaProject:
def __init__(self, context):
self.context = context
"""
if len(interfaces) == 0:
raise TypeError("At least one interface is required")
def _decorator(cls):
missing = object()
for interface in interfaces:
classImplements(cls, interface)
for name in interface:
if getattr(cls, name, missing) is missing:
setattr(cls, name, Passthrough(name, context))
return cls
return _decorator
class Passthrough:
"""Call the delegated class for the decorator class.
If the ``adaptation`` argument is not None, it should be a callable. It
will be called with the context, and should return an object that will
have the delegated attribute. The ``adaptation`` argument is expected to
be used with an interface, to adapt the context.
"""
def __init__(self, name, contextvar, adaptation=None):
self.name = name
self.contextvar = contextvar
self.adaptation = adaptation
def __get__(self, inst, cls=None):
if inst is None:
return self
else:
context = getattr(inst, self.contextvar)
if self.adaptation is not None:
context = self.adaptation(context)
return getattr(context, self.name)
def __set__(self, inst, value):
context = getattr(inst, self.contextvar)
if self.adaptation is not None:
context = self.adaptation(context)
setattr(context, self.name, value)
def __delete__(self, inst):
raise NotImplementedError
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5529757
lazr_delegates-4.0.0/src/lazr/delegates/docs/ 0000775 0001750 0001750 00000000000 15233440614 020520 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/docs/CONTRIBUTING.rst 0000664 0001750 0001750 00000000052 15221773336 023165 0 ustar 00finnrg finnrg .. include:: ../../../../CONTRIBUTING.rst
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/docs/NEWS.rst 0000664 0001750 0001750 00000000042 15221773336 022031 0 ustar 00finnrg finnrg .. include:: ../../../../NEWS.rst
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/docs/__init__.py 0000664 0001750 0001750 00000000000 15221773336 022626 0 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/src/lazr/delegates/docs/conf.py 0000664 0001750 0001750 00000001626 15233437661 022034 0 ustar 00finnrg finnrg #!/usr/bin/env python3
#
# lazr.delegates documentation build configuration file.
#
# This file is execfile()d with the current directory set to its
# containing dir.
from lazr.delegates import __version__
# -- General configuration ------------------------------------------------
extensions = []
templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"
project = "lazr.delegates"
copyright = "2013-2021, LAZR developers"
author = "LAZR Developers "
version = __version__
release = __version__
language = "en"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
pygments_style = "sphinx"
# -- Options for HTML output ----------------------------------------------
html_theme = "alabaster"
html_static_path = []
html_sidebars = {
"**": [
"relations.html",
"searchbox.html",
]
}
htmlhelp_basename = "lazrdelegatesdoc"
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/docs/index.rst 0000664 0001750 0001750 00000007502 15221773336 022374 0 ustar 00finnrg finnrg ==============
lazr.delegates
==============
The ``lazr.delegates`` package makes it easy to write objects that delegate
behavior to another object. The new object adds some property or behavior on
to the other object, while still providing the underlying interface, and
delegating behavior.
Usage
=====
The ``@delegate_to`` class decorator makes a class implement zero or more
interfaces by delegating the implementation to another object. In the case of
a class providing an adapter, that object will be the *context*, but it can
really be any object stored in an attribute. So while the interfaces use an
inheritance mechanism, the classes use a composition mechanism.
For example, we can define two interfaces ``IFoo0`` and ``IFoo1`` where the
latter inherits from the former. The first interface defines an attribute.
>>> from zope.interface import Interface, Attribute
>>> class IFoo0(Interface):
... one = Attribute('attribute in IFoo0')
The second (i.e. derived) interface defines a method and an attribute.
>>> class IFoo1(IFoo0):
... def bar():
... """A method in IFoo1"""
... baz = Attribute('attribute in IFoo1')
We also define two classes that mirror the interfaces, and do something
interesting.
::
>>> class Foo0:
... one = 'one'
>>> class Foo1(Foo0):
... def bar(self):
... return 'bar'
... baz = 'I am baz'
Finally, to tie everything together, we can define a class that delegates the
implementation of ``IFoo1`` to an attribute on the instance. By default,
``self.context`` is used as the delegate attribute.
>>> from lazr.delegates import delegate_to
>>> @delegate_to(IFoo1)
... class SomeClass:
... def __init__(self, context):
... self.context = context
When the class doing the delegation is instantiated, an instance of the class
implementing the interface is passed in.
>>> delegate = Foo1()
>>> s = SomeClass(delegate)
Now, the ``bar()`` method comes from ``Foo1``.
>>> print(s.bar())
bar
The ``baz`` attribute also comes from ``Foo1``.
>>> print(s.baz)
I am baz
The ``one`` attribute comes from ``Foo0``.
>>> print(s.one)
one
Even though the interface of ``SomeClass`` is defined through the delegate,
the interface is still provided by the instance.
>>> IFoo1.providedBy(s)
True
Custom context
--------------
The ``@delegate_to`` decorator takes an optional keyword argument to customize
the attribute containing the object to delegate to.
>>> @delegate_to(IFoo1, context='myfoo')
... class SomeOtherClass:
... def __init__(self, foo):
... self.myfoo = foo
The attributes and methods are still delegated correctly.
>>> s = SomeOtherClass(delegate)
>>> print(s.bar())
bar
>>> print(s.baz)
I am baz
Multiple interfaces
===================
The ``@delegate_to`` decorator accepts more than one interface. Note however,
that the context attribute must implement all of the named interfaces.
>>> class IFoo2(Interface):
... another = Attribute('another attribute')
Here is a class that implements the interface. It inherits from the
implementation class that provides the ``IFoo0`` interface. Thus does this
class implement both interfaces.
>>> class Foo2(Foo0):
... another = 'I am another foo'
Again, we tie it all together.
>>> @delegate_to(IFoo0, IFoo2)
... class SomeOtherClass:
... def __init__(self, context):
... self.context = context
Now, the instance of this class has all the expected attributes, and provides
the expected interfaces.
>>> s = SomeOtherClass(Foo2())
>>> print(s.another)
I am another foo
>>> IFoo0.providedBy(s)
True
>>> IFoo2.providedBy(s)
True
.. toctree::
self
Contributing
News
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5532594
lazr_delegates-4.0.0/src/lazr/delegates/tests/ 0000775 0001750 0001750 00000000000 15233440614 020732 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/tests/__init__.py 0000664 0001750 0001750 00000000000 15221773336 023040 0 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1783101150.0
lazr_delegates-4.0.0/src/lazr/delegates/tests/test_api.py 0000664 0001750 0001750 00000001706 15221773336 023127 0 ustar 00finnrg finnrg # Copyright 2013-2015 Canonical Ltd. All rights reserved.
#
# This file is part of lazr.delegates.
#
# lazr.delegates is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# lazr.delegates is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.delegates. If not, see .
"""Test the new API."""
import unittest
from lazr.delegates import delegate_to
class TestAPI(unittest.TestCase):
"""Test various corner cases in the API."""
def test_no_interfaces(self):
self.assertRaises(TypeError, delegate_to)
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/src/lazr/delegates/tests/test_docs.py 0000664 0001750 0001750 00000003153 15233437661 023305 0 ustar 00finnrg finnrg # Copyright 2009-2021 Canonical Ltd. All rights reserved.
#
# This file is part of lazr.delegates.
#
# lazr.delegates is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# lazr.delegates is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.delegates. If not, see .
"""Test harness for doctests."""
__all__ = []
import doctest
import importlib.util
import os
from pathlib import Path
DOCTEST_FLAGS = (
doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF
)
def load_tests(loader, tests, pattern):
"""Load the doc tests (docs/*, if any exist)."""
doctest_files = []
spec = importlib.util.find_spec("lazr.delegates")
if spec and spec.submodule_search_locations:
docs_path = Path(list(spec.submodule_search_locations)[0]) / "docs"
if docs_path.is_dir():
for path in sorted(docs_path.iterdir()):
if path.name.endswith(".rst"):
doctest_files.append(os.path.abspath(str(path)))
tests.addTest(
doctest.DocFileSuite(
*doctest_files,
module_relative=False,
optionflags=DOCTEST_FLAGS,
encoding="UTF-8",
)
)
return tests
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/src/lazr/delegates/tests/test_passthrough.py 0000664 0001750 0001750 00000005433 15233437661 024727 0 ustar 00finnrg finnrg # Copyright 2013-2015 Canonical Ltd. All rights reserved.
#
# This file is part of lazr.delegates.
#
# lazr.delegates is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# lazr.delegates is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.delegates. If not, see .
"""Test the Passthrough implementation."""
import unittest
from lazr.delegates import Passthrough
class Base:
foo = "foo from Base"
@classmethod
def clsmethod(cls):
return cls.__name__
class TestPassthrough(unittest.TestCase):
def setUp(self):
self.p = Passthrough("foo", "mycontext")
self.p2 = Passthrough("clsmethod", "mycontext")
self.base = Base()
class Adapter:
mycontext = self.base
self.Adapter = Adapter
self.adapter = Adapter()
def test_get(self):
self.assertEqual(self.p.__get__(self.adapter), "foo from Base")
self.assertTrue(self.p.__get__(None, self.Adapter) is self.p)
self.assertEqual(self.p2.__get__(self.adapter)(), "Base")
def test_set(self):
self.p.__set__(self.adapter, "new value")
self.assertEqual(self.base.foo, "new value")
def test_no_delete(self):
self.assertRaises(NotImplementedError, self.p.__delete__, self.adapter)
def test_adaptation(self):
# Passthrough's third argument (adaptation) is optional and, when
# provided, should be a zope.interface.Interface subclass (although in
# practice any callable will do) to which the instance is adapted
# before getting/setting the delegated attribute.
class HasNoFoo:
_foo = 1
no_foo = HasNoFoo()
# ... but IHasFooAdapter uses HasNoFoo._foo to provide its own .foo,
# so it works like an adapter for HasNoFoo into some interface that
# provides a 'foo' attribute.
class IHasFooAdapter:
def __init__(self, inst):
self.inst = inst
@property
def foo(self):
return self.inst._foo
@foo.setter
def foo(self, value):
self.inst._foo = value
class Example:
context = no_foo
p = Passthrough("foo", "context", adaptation=IHasFooAdapter)
e = Example()
self.assertEqual(p.__get__(e), 1)
p.__set__(e, 2)
self.assertEqual(p.__get__(e), 2)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1785610635.5532894
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/ 0000775 0001750 0001750 00000000000 15233440614 021261 5 ustar 00finnrg finnrg ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610635.0
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/PKG-INFO 0000644 0001750 0001750 00000003421 15233440613 022353 0 ustar 00finnrg finnrg Metadata-Version: 2.4
Name: lazr.delegates
Version: 4.0.0
Summary: Easily write objects that delegate behavior
Maintainer: LAZR Developers
License: LGPL v3
Project-URL: Homepage, https://launchpad.net/lazr.delegates
Project-URL: Source, https://code.launchpad.net/lazr.delegates
Project-URL: Issue Tracker, https://bugs.launchpad.net/lazr.delegates
Project-URL: Documentation, https://lazrdelegates.readthedocs.io/en/latest/
Project-URL: Download, https://launchpad.net/lazr.delegates/+download
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.8
Description-Content-Type: text/x-rst
License-File: COPYING.txt
Requires-Dist: zope.interface
Provides-Extra: docs
Requires-Dist: Sphinx; extra == "docs"
Provides-Extra: test
Requires-Dist: zope.testing>=4.6.0; extra == "test"
Requires-Dist: zope.testrunner>=6.6.1; extra == "test"
Dynamic: license-file
The ``lazr.delegates`` package makes it easy to write objects that delegate
behavior to another object. The new object adds some property or behavior on
to the other object, while still providing the underlying interface, and
delegating behavior.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610635.0
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/SOURCES.txt 0000664 0001750 0001750 00000001377 15233440613 023154 0 ustar 00finnrg finnrg .flake8
.launchpad.yaml
.pre-commit-config.yaml
.readthedocs.yaml
CONTRIBUTING.rst
COPYING.txt
MANIFEST.in
NEWS.rst
README.rst
SECURITY.md
pyproject.toml
tox.ini
src/lazr.delegates.egg-info/PKG-INFO
src/lazr.delegates.egg-info/SOURCES.txt
src/lazr.delegates.egg-info/dependency_links.txt
src/lazr.delegates.egg-info/requires.txt
src/lazr.delegates.egg-info/top_level.txt
src/lazr/delegates/__init__.py
src/lazr/delegates/_delegates.py
src/lazr/delegates/docs/CONTRIBUTING.rst
src/lazr/delegates/docs/NEWS.rst
src/lazr/delegates/docs/__init__.py
src/lazr/delegates/docs/conf.py
src/lazr/delegates/docs/index.rst
src/lazr/delegates/tests/__init__.py
src/lazr/delegates/tests/test_api.py
src/lazr/delegates/tests/test_docs.py
src/lazr/delegates/tests/test_passthrough.py ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610635.0
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/dependency_links.txt 0000664 0001750 0001750 00000000001 15233440613 025326 0 ustar 00finnrg finnrg
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610635.0
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/requires.txt 0000664 0001750 0001750 00000000121 15233440613 023652 0 ustar 00finnrg finnrg zope.interface
[docs]
Sphinx
[test]
zope.testing>=4.6.0
zope.testrunner>=6.6.1
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610635.0
lazr_delegates-4.0.0/src/lazr.delegates.egg-info/top_level.txt 0000664 0001750 0001750 00000000005 15233440613 024005 0 ustar 00finnrg finnrg lazr
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1785610161.0
lazr_delegates-4.0.0/tox.ini 0000664 0001750 0001750 00000003062 15233437661 015420 0 ustar 00finnrg finnrg [tox]
isolated_build = True
envlist =
lint
py38,py39,py310,py311,py312,py313,py314
coverage
docs
audit
[testenv]
# Python 3.8 only: modern virtualenv seeds pip 26 / setuptools 82 into the env,
# but pip 26 refuses to run on 3.8 and setuptools 82 dropped pkg_resources
# (which zope.testrunner 6.6.1 -- the last 3.8-compatible release -- imports).
# Pin the seeded pip and cap setuptools on 3.8 so pkg_resources stays available.
# 3.9+ need neither: pip 26 runs there and zope.testrunner 8.x drops pkg_resources.
# These are no-ops under tox-uv and on CI (focal ships compatible tooling).
set_env =
py38: VIRTUALENV_PIP = 24.3.1
deps =
.[test]
py38: setuptools < 81
zope.testrunner
commands =
zope-testrunner --test-path src --tests-pattern ^tests {posargs}
[testenv:lint]
# align with .launchpad.yaml
basepython = python3.12
skip_install = true
deps =
pre-commit
commands =
pre-commit run --all-files
[testenv:coverage]
basepython = python3.12
deps =
.[test]
zope.testrunner
coverage
commands =
coverage run --source lazr.delegates -m zope.testrunner \
--test-path src --tests-pattern ^tests {posargs}
coverage report --show-missing --fail-under=100
[testenv:docs]
# align with .launchpad.yaml
basepython = python3.12
deps =
.[docs]
commands =
sphinx-build -b html -d src/lazr/delegates/docs/_build/doctrees src/lazr/delegates/docs src/lazr/delegates/docs/_build/html
[testenv:audit]
# align with .launchpad.yaml
basepython = python3.12
deps =
pip>=26.0
pip-audit
commands =
pip-audit