z3c.objpath


Namez3c.objpath JSON
Version 2.0 PyPI version JSON
download
home_pagehttps://github.com/zopefoundation/z3c.objpath
SummaryGenerate and resolve paths to to objects.
upload_time2023-08-21 06:32:39
maintainer
docs_urlNone
authorMartijn Faassen
requires_python>=3.7
licenseZPL
keywords zope
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ObjectPath
**********

This package contains two things:

* the ``z3c.objpath.interfaces.IObjectPath`` interface.

* some helper functions to construct (relative) object paths, in
  ``z3c.objpath.path``.

The idea is that a particular application can implement a utility that
fulfills the ``IObjectPath`` interface, so that it is possible to
construct paths to objects in a uniform way. The implementation may be
done with ``zope.traversing``, but in some cases you want
application-specific object paths. In this case, the functions in
``z3c.objpath.path`` might be useful.

We'll have a simple item::

  >>> class Item(object):
  ...   __name__ = None
  ...   __parent__ = None
  ...   def __repr__(self):
  ...     return '<Item %s>' % self.__name__

Let's create a simple container-like object::

  >>> class Container(Item):
  ...   def __init__(self):
  ...     self._d = {}
  ...   def __setitem__(self, name, obj):
  ...     self._d[name] = obj
  ...     obj.__name__ = name
  ...     obj.__parent__ = self
  ...   def __getitem__(self, name):
  ...     return self._d[name]
  ...   def __repr__(self):
  ...     return '<Container %s>' % self.__name__

Now let's create a structure::

  >>> root = Container()
  >>> root.__name__ = 'root'
  >>> data = root['data'] = Container()
  >>> a = data['a'] = Container()
  >>> b = data['b'] = Container()
  >>> c = data['c'] = Item()
  >>> d = a['d'] = Item()
  >>> e = a['e'] = Container()
  >>> f = e['f'] = Item()
  >>> g = b['g'] = Item()

We will now exercise two functions, ``path`` and ``resolve``, which
are inverses of each other::

  >>> from z3c.objpath import path, resolve

We can create a path to ``a`` from ``root``::

  >>> path(root, a)
  '/root/data/a'

We can also resolve it again::

  >>> resolve(root, '/root/data/a')
  <Container a>

We can also create a path to ``a`` from ``data``::

  >>> path(data, a)
  '/data/a'

And resolve it again::

  >>> resolve(data, '/data/a')
  <Container a>

We can make a deeper path::

  >>> path(root, f)
  '/root/data/a/e/f'

And resolve it::

  >>> resolve(root, '/root/data/a/e/f')
  <Item f>

The path `'/'` leads to the root object::

  >>> resolve(root, '/')
  <Container root>

We get an error if we cannot construct a path::

  >>> path(e, a)
  Traceback (most recent call last):
   ...
  ValueError: Cannot create path for <Container a>

We also get an error if we cannot resolve a path::

  >>> resolve(root, '/root/data/a/f/e')
  Traceback (most recent call last):
   ...
  ValueError: Cannot resolve path /root/data/a/f/e

z3c.objpath changes
*******************

2.0 (2023-08-21)
================

* Drop support for Python 2.7, 3.5, 3.6.


1.3 (2022-12-02)
================

- Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.


1.2 (2018-06-14)
================

* Add support for Python 3.5, 3.6, PyPy and PyPy3.

1.1 (2012-10-13)
================

* Add name space declaration for `z3c`.

* Added a `test` extra, as test require ``zope.testing``.

1.0 (2008-04-15)
================

* Initial public release.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zopefoundation/z3c.objpath",
    "name": "z3c.objpath",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "Zope",
    "author": "Martijn Faassen",
    "author_email": "faassen@startifact.com",
    "download_url": "https://files.pythonhosted.org/packages/a6/22/453702a2bf6f7e70a2d70cc5723b9084077ddb8e207b544fc24968d1901b/z3c.objpath-2.0.tar.gz",
    "platform": null,
    "description": "ObjectPath\n**********\n\nThis package contains two things:\n\n* the ``z3c.objpath.interfaces.IObjectPath`` interface.\n\n* some helper functions to construct (relative) object paths, in\n  ``z3c.objpath.path``.\n\nThe idea is that a particular application can implement a utility that\nfulfills the ``IObjectPath`` interface, so that it is possible to\nconstruct paths to objects in a uniform way. The implementation may be\ndone with ``zope.traversing``, but in some cases you want\napplication-specific object paths. In this case, the functions in\n``z3c.objpath.path`` might be useful.\n\nWe'll have a simple item::\n\n  >>> class Item(object):\n  ...   __name__ = None\n  ...   __parent__ = None\n  ...   def __repr__(self):\n  ...     return '<Item %s>' % self.__name__\n\nLet's create a simple container-like object::\n\n  >>> class Container(Item):\n  ...   def __init__(self):\n  ...     self._d = {}\n  ...   def __setitem__(self, name, obj):\n  ...     self._d[name] = obj\n  ...     obj.__name__ = name\n  ...     obj.__parent__ = self\n  ...   def __getitem__(self, name):\n  ...     return self._d[name]\n  ...   def __repr__(self):\n  ...     return '<Container %s>' % self.__name__\n\nNow let's create a structure::\n\n  >>> root = Container()\n  >>> root.__name__ = 'root'\n  >>> data = root['data'] = Container()\n  >>> a = data['a'] = Container()\n  >>> b = data['b'] = Container()\n  >>> c = data['c'] = Item()\n  >>> d = a['d'] = Item()\n  >>> e = a['e'] = Container()\n  >>> f = e['f'] = Item()\n  >>> g = b['g'] = Item()\n\nWe will now exercise two functions, ``path`` and ``resolve``, which\nare inverses of each other::\n\n  >>> from z3c.objpath import path, resolve\n\nWe can create a path to ``a`` from ``root``::\n\n  >>> path(root, a)\n  '/root/data/a'\n\nWe can also resolve it again::\n\n  >>> resolve(root, '/root/data/a')\n  <Container a>\n\nWe can also create a path to ``a`` from ``data``::\n\n  >>> path(data, a)\n  '/data/a'\n\nAnd resolve it again::\n\n  >>> resolve(data, '/data/a')\n  <Container a>\n\nWe can make a deeper path::\n\n  >>> path(root, f)\n  '/root/data/a/e/f'\n\nAnd resolve it::\n\n  >>> resolve(root, '/root/data/a/e/f')\n  <Item f>\n\nThe path `'/'` leads to the root object::\n\n  >>> resolve(root, '/')\n  <Container root>\n\nWe get an error if we cannot construct a path::\n\n  >>> path(e, a)\n  Traceback (most recent call last):\n   ...\n  ValueError: Cannot create path for <Container a>\n\nWe also get an error if we cannot resolve a path::\n\n  >>> resolve(root, '/root/data/a/f/e')\n  Traceback (most recent call last):\n   ...\n  ValueError: Cannot resolve path /root/data/a/f/e\n\nz3c.objpath changes\n*******************\n\n2.0 (2023-08-21)\n================\n\n* Drop support for Python 2.7, 3.5, 3.6.\n\n\n1.3 (2022-12-02)\n================\n\n- Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.\n\n\n1.2 (2018-06-14)\n================\n\n* Add support for Python 3.5, 3.6, PyPy and PyPy3.\n\n1.1 (2012-10-13)\n================\n\n* Add name space declaration for `z3c`.\n\n* Added a `test` extra, as test require ``zope.testing``.\n\n1.0 (2008-04-15)\n================\n\n* Initial public release.\n",
    "bugtrack_url": null,
    "license": "ZPL",
    "summary": "Generate and resolve paths to to objects.",
    "version": "2.0",
    "project_urls": {
        "Homepage": "https://github.com/zopefoundation/z3c.objpath"
    },
    "split_keywords": [
        "zope"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "111e5d81e8bc4256516f12583bb3f769adf974c15704d273cd0b748bc5c5fb31",
                "md5": "26ce0f05f325410e36e429769298164b",
                "sha256": "c25c8c6c0650716041b7b8cd45b58ef535d2742d4a8018b02351fafccf48a177"
            },
            "downloads": -1,
            "filename": "z3c.objpath-2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26ce0f05f325410e36e429769298164b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7106,
            "upload_time": "2023-08-21T06:32:37",
            "upload_time_iso_8601": "2023-08-21T06:32:37.381310Z",
            "url": "https://files.pythonhosted.org/packages/11/1e/5d81e8bc4256516f12583bb3f769adf974c15704d273cd0b748bc5c5fb31/z3c.objpath-2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a622453702a2bf6f7e70a2d70cc5723b9084077ddb8e207b544fc24968d1901b",
                "md5": "ce062685722831cf53310299c872483f",
                "sha256": "c7a072e5dc5223228e83f179fdf2c15fe2af8cc8ac46d8377c27854a235b88f6"
            },
            "downloads": -1,
            "filename": "z3c.objpath-2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ce062685722831cf53310299c872483f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6809,
            "upload_time": "2023-08-21T06:32:39",
            "upload_time_iso_8601": "2023-08-21T06:32:39.045971Z",
            "url": "https://files.pythonhosted.org/packages/a6/22/453702a2bf6f7e70a2d70cc5723b9084077ddb8e207b544fc24968d1901b/z3c.objpath-2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-21 06:32:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zopefoundation",
    "github_project": "z3c.objpath",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "z3c.objpath"
}
        
Elapsed time: 0.17284s