-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idea: allow traversing with pathlib semantics #1200
Comments
How is that better than |
Cool :) BTW it will be more convenient to do it like this: content = root / "and/now/get/some/content" See what we have in pathlib: >>> from pathlib import Path
>>> Path("foo") / "bar/baz"
PosixPath('foo/bar/baz') However, using Will the Theoretically, you could do: content_path = root / "and/now/get/some/content"
content_path.restricted_get()
content_path.unrestricted_get() With this it already starts to be less cool :D |
@davisagli less obvious is you already know that you can do dictionary-like traversing, but with all the rage of using pathlib everywhere (maybe I'm biased here 😓 ) and that Zope/Plone always use the metaphor of storing objects like folders and files, well, it makes it easier for onboarding IMHO @ale-rt good point on the (un)restricted that's not obvious at first sight... but maybe it could be a method of the object itself, i.e.: obj_path = root / 'my/deep/nested/obj'
obj = obj_path.resolve()
# vs
obj = obj_path.unrestricted_resolve() So one thing could be constructing the path to the object, and once you have that you need to decide how you want to use it. Overriding the If I keep dreaming about this, So, it would be a """"""matter"""""" of creating one such specific path meant for traversing a ZODB storage ✨ I don't have any specific need to implement it myself, but I thought that as an idea it would be worth sharing it here 😊 |
Gil Forcada Codinachs wrote at 2024-3-14 04:53 -0700:
...
```python
obj_path = root / 'my/deep/nested/obj'
obj = obj_path.resolve()
# vs
obj = obj_path.unrestricted_resolve()
```
What about support of `Pathlib` objects by `[un]restrictedTraverse`?
This would give:
path = <construct in whatever way you want>
robj = obj.[un]restrictedTraverse](path)
Very similar to the above and does not need an extra special method.
|
I like @d-maurer's idea best of the ones listed here, but I'm not sure that I would actually use it much. It's already pretty convenient to construct string paths using f-strings. Different topic, but something that I would use is an easier way to get the string path of a Zope object, instead of doing |
David Glick wrote at 2024-3-14 09:41 -0700:
...
Different topic, but something that I _would_ use is an easier way to get the string path of a Zope object, instead of doing `"/".join(obj.getPhysicalPath())`
Why do you need the path as a string?
Can you use `absolute_url_path` or `absolute_url(relative=1)`
in those cases?
|
@d-maurer Yep, |
In Zope/Plone we use traversal for almost everything:
Wouldn't it be cool to be able to do instead:
✨
The text was updated successfully, but these errors were encountered: