pyams-utils 2.8.2__tar.gz → 2.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/PKG-INFO +12 -1
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/docs/HISTORY.rst +11 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/setup.py +1 -1
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/traversing.rst +40 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/fanstatic.py +1 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/traversing.py +8 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/request.py +2 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/text.py +46 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/traversing.py +52 -3
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/PKG-INFO +12 -1
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/LICENSE +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/MANIFEST.in +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/docs/README.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/setup.cfg +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/__init__.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/adapter.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/attr.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/cache.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/configure.zcml +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/container.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/context.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/country.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/data.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/date.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/decorator.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/dict.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/README.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/adapter.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/attr.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/cache.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/container.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/context.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/data.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/date.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/factory.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/fanstatic.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/i18n.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/inherit.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/intids.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/list.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/location.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/lock.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/monitor.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/progress.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/property.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/protocol-http.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/protocol-socket.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/protocol-xmlrpc.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/pygments.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/registry.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/request.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/rest.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/rpc.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/schema.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/session.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/size.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/tales.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/text.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/timezone.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/transaction.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/url.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/wsgi.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/doctests/zodb.rst +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/encoding.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/factory.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/finder.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/html.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/i18n.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/include.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/inherit.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/__init__.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/data.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/form.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/inherit.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/intids.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/monitor.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/proxy.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/pygments.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/rest.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/size.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/tales.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/text.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/timezone.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/transaction.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/tree.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/url.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/interfaces/zeo.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/intids.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/json.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/list.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/locales/pyams_utils.pot +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/location.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/lock.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/monitor.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/progress.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/property.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/protocol/__init__.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/protocol/http.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/protocol/tcp.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/protocol/xmlrpc.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/pygments.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/registry.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/rest.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/rpc.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/schema.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/session.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/size.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/tales.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/testing.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/tests/__init__.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/tests/test_dotdict.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/tests/test_utilsdocs.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/tests/test_utilsdocstrings.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/timezone/__init__.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/timezone/utility.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/timezone/vocabulary.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/transaction.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/unicode.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/url.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/vocabulary.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/wsgi.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/zodb.py +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/SOURCES.txt +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/dependency_links.txt +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/namespace_packages.txt +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/not-zip-safe +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/requires.txt +0 -0
- {pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyams_utils
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.10.0
|
|
4
4
|
Summary: PyAMS generic modules
|
|
5
5
|
Home-page: https://pyams.readthedocs.io
|
|
6
6
|
Author: Thierry Florac
|
|
@@ -58,6 +58,17 @@ Most PyAMS_utils modules are documented using doctests in the /doctests/ sub-dir
|
|
|
58
58
|
Changelog
|
|
59
59
|
=========
|
|
60
60
|
|
|
61
|
+
2.10.0
|
|
62
|
+
------
|
|
63
|
+
- updated namespace traverser to be able to create views on other views, and to add traversing extensions
|
|
64
|
+
support
|
|
65
|
+
|
|
66
|
+
2.9.0
|
|
67
|
+
-----
|
|
68
|
+
- added new "phrase" TALES extension to extract first phrases of a given text
|
|
69
|
+
- added optional "display_context" argument to custom request factory
|
|
70
|
+
- force injected Fanstatic resources to top page
|
|
71
|
+
|
|
61
72
|
2.8.2
|
|
62
73
|
-----
|
|
63
74
|
- removed CORS headers checkers (imported from PyAMS_security)
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
Changelog
|
|
3
3
|
=========
|
|
4
4
|
|
|
5
|
+
2.10.0
|
|
6
|
+
------
|
|
7
|
+
- updated namespace traverser to be able to create views on other views, and to add traversing extensions
|
|
8
|
+
support
|
|
9
|
+
|
|
10
|
+
2.9.0
|
|
11
|
+
-----
|
|
12
|
+
- added new "phrase" TALES extension to extract first phrases of a given text
|
|
13
|
+
- added optional "display_context" argument to custom request factory
|
|
14
|
+
- force injected Fanstatic resources to top page
|
|
15
|
+
|
|
5
16
|
2.8.2
|
|
6
17
|
-----
|
|
7
18
|
- removed CORS headers checkers (imported from PyAMS_security)
|
|
@@ -24,7 +24,7 @@ DOCS = os.path.join(os.path.dirname(__file__),
|
|
|
24
24
|
README = os.path.join(DOCS, 'README.rst')
|
|
25
25
|
HISTORY = os.path.join(DOCS, 'HISTORY.rst')
|
|
26
26
|
|
|
27
|
-
version = '2.
|
|
27
|
+
version = '2.10.0'
|
|
28
28
|
long_description = open(README).read() + '\n\n' + open(HISTORY).read()
|
|
29
29
|
|
|
30
30
|
tests_require = [
|
|
@@ -283,6 +283,46 @@ Traverser should handle virtual host correctly:
|
|
|
283
283
|
True
|
|
284
284
|
|
|
285
285
|
|
|
286
|
+
Custom '@' extension traverser
|
|
287
|
+
------------------------------
|
|
288
|
+
|
|
289
|
+
You can provide another kind of traverser using the `IExtensionTraverser` interface. This
|
|
290
|
+
extension is called using a '@' character as prefix in the URL:
|
|
291
|
+
|
|
292
|
+
>>> request = DummyRequest(path='/@extension/child', matchdict=None)
|
|
293
|
+
>>> result = traverser(request)
|
|
294
|
+
Traceback (most recent call last):
|
|
295
|
+
...
|
|
296
|
+
pyramid.httpexceptions.HTTPNotFound: The resource could not be found.
|
|
297
|
+
|
|
298
|
+
Let's declare a new extension, which will simply log its path arguments and return the context:
|
|
299
|
+
|
|
300
|
+
>>> from pyams_utils.interfaces.traversing import IExtensionTraverser
|
|
301
|
+
|
|
302
|
+
>>> class ExtensionTraverser(ContextRequestAdapter):
|
|
303
|
+
... def traverse(self, path):
|
|
304
|
+
... print(path)
|
|
305
|
+
... return self.context
|
|
306
|
+
|
|
307
|
+
>>> config.registry.registerAdapter(ExtensionTraverser,
|
|
308
|
+
... required=(object, DummyRequest),
|
|
309
|
+
... provided=IExtensionTraverser,
|
|
310
|
+
... name='extension')
|
|
311
|
+
|
|
312
|
+
>>> result = traverser(request)
|
|
313
|
+
('@extension', 'child')
|
|
314
|
+
>>> pprint.pprint(result)
|
|
315
|
+
{'context': <...MyFolder object at 0x...>,
|
|
316
|
+
'root': <...MyFolder object at 0x...>,
|
|
317
|
+
'subpath': (),
|
|
318
|
+
'traversed': ('@extension', 'child'),
|
|
319
|
+
'view_name': '',
|
|
320
|
+
'virtual_root': <...MyFolder object at 0x...>,
|
|
321
|
+
'virtual_root_path': ()}
|
|
322
|
+
>>> result['context'] is child
|
|
323
|
+
True
|
|
324
|
+
|
|
325
|
+
|
|
286
326
|
Getting context parents
|
|
287
327
|
-----------------------
|
|
288
328
|
|
|
@@ -190,6 +190,7 @@ def inject_resources(request, registry, handler):
|
|
|
190
190
|
config = fanstatic_config(settings)
|
|
191
191
|
config.pop('use_application_uri', None)
|
|
192
192
|
config.pop('injector', None)
|
|
193
|
+
config['bottom'] = False
|
|
193
194
|
injector = TopBottomInjector(config)
|
|
194
195
|
with RequestContext(request):
|
|
195
196
|
try:
|
|
@@ -30,3 +30,11 @@ class IPathElements(Interface):
|
|
|
30
30
|
parents = List(title="Element parents",
|
|
31
31
|
description="Internal IDs of parents objects",
|
|
32
32
|
value_type=Int())
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class IExtensionTraverser(Interface):
|
|
36
|
+
"""Namespace traverser interface"""
|
|
37
|
+
|
|
38
|
+
def traverse(self, path):
|
|
39
|
+
"""Traverse a given name"""
|
|
40
|
+
|
|
@@ -191,11 +191,13 @@ def create_request(path='/', environ=None, base_url=None, headers=None,
|
|
|
191
191
|
factory = PyAMSRequest
|
|
192
192
|
root = kwargs.pop('root', None)
|
|
193
193
|
context = kwargs.pop('context', None)
|
|
194
|
+
display_context = kwargs.pop('display_context', None)
|
|
194
195
|
view_name = kwargs.pop('view_name', '')
|
|
195
196
|
request = factory.blank(path, environ, base_url, headers, POST, **kwargs)
|
|
196
197
|
request.registry = registry # pylint: disable=attribute-defined-outside-init
|
|
197
198
|
request.root = root
|
|
198
199
|
request.context = context
|
|
200
|
+
request.display_context = context if display_context is None else display_context
|
|
199
201
|
request.view_name = view_name
|
|
200
202
|
request.annotations = get_annotations(request)
|
|
201
203
|
if principal_id is not None:
|
|
@@ -78,6 +78,52 @@ def get_text_start(text, length, maxlen=0):
|
|
|
78
78
|
return text
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
def get_first_phrase(text, min_length=50):
|
|
82
|
+
"""Get first sentence of given text
|
|
83
|
+
|
|
84
|
+
>>> from pyams_utils.text import get_first_phrase
|
|
85
|
+
|
|
86
|
+
>>> get_first_phrase(None)
|
|
87
|
+
''
|
|
88
|
+
>>> get_first_phrase('')
|
|
89
|
+
''
|
|
90
|
+
>>> get_first_phrase('A short string')
|
|
91
|
+
'A short string'
|
|
92
|
+
>>> get_first_phrase('This elegant string can have a little more than 50 characters')
|
|
93
|
+
'This elegant string can have a little more than 50 characters'
|
|
94
|
+
>>> get_first_phrase('This elegant string can have a little more than 50 characters', 10)
|
|
95
|
+
'This elegant string can have a little more than 50 characters'
|
|
96
|
+
>>> get_first_phrase('This is a short phrase. Maybe sufficient?')
|
|
97
|
+
'This is a short phrase. Maybe sufficient?'
|
|
98
|
+
>>> get_first_phrase('This is a short phrase. Maybe sufficient?', 10)
|
|
99
|
+
'This is a short phrase.'
|
|
100
|
+
"""
|
|
101
|
+
if not text:
|
|
102
|
+
return ''
|
|
103
|
+
result = ''
|
|
104
|
+
sentences = re.findall(r'[^.!?]*[.!?]', text)
|
|
105
|
+
if not sentences:
|
|
106
|
+
return text
|
|
107
|
+
while sentences and len(result) < min_length:
|
|
108
|
+
result += sentences.pop(0) + ' '
|
|
109
|
+
return result.strip()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@adapter_config(name='phrase',
|
|
113
|
+
required=(Interface, Interface, Interface),
|
|
114
|
+
provides=ITALESExtension)
|
|
115
|
+
class FirstPhraseTalesExtension(ContextRequestViewAdapter):
|
|
116
|
+
"""extension:phrase(value, min_length) TALES expression
|
|
117
|
+
|
|
118
|
+
This expression can be used to get the first sentence of a given text.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
@staticmethod
|
|
122
|
+
def render(value, min_length=50):
|
|
123
|
+
"""Render TALES extension"""
|
|
124
|
+
return get_first_phrase(value, min_length)
|
|
125
|
+
|
|
126
|
+
|
|
81
127
|
def get_text_parts(text, *parts, sep=' '):
|
|
82
128
|
"""Get parts of given text separated with given separator
|
|
83
129
|
|
|
@@ -20,9 +20,9 @@ a given interface.
|
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
22
|
from pyramid.exceptions import NotFound, URLDecodeError
|
|
23
|
-
from pyramid.interfaces import VH_ROOT_KEY
|
|
23
|
+
from pyramid.interfaces import IView, VH_ROOT_KEY
|
|
24
24
|
from pyramid.location import lineage
|
|
25
|
-
from pyramid.traversal import ResourceTreeTraverser,
|
|
25
|
+
from pyramid.traversal import ResourceTreeTraverser, decode_path_info, split_path_info
|
|
26
26
|
from pyramid.util import is_nonstr_iter
|
|
27
27
|
from zope.component import queryAdapter, queryMultiAdapter
|
|
28
28
|
from zope.interface import Interface
|
|
@@ -32,7 +32,7 @@ from zope.location.interfaces import IContained
|
|
|
32
32
|
from zope.traversing.interfaces import BeforeTraverseEvent, ITraversable
|
|
33
33
|
|
|
34
34
|
from pyams_utils.adapter import ContextAdapter, adapter_config
|
|
35
|
-
from pyams_utils.interfaces.traversing import IPathElements
|
|
35
|
+
from pyams_utils.interfaces.traversing import IExtensionTraverser, IPathElements
|
|
36
36
|
from pyams_utils.registry import query_utility
|
|
37
37
|
|
|
38
38
|
|
|
@@ -50,6 +50,7 @@ class NamespaceTraverser(ResourceTreeTraverser):
|
|
|
50
50
|
|
|
51
51
|
PLUS_SELECTOR = '+'
|
|
52
52
|
NAMESPACE_SELECTOR = PLUS_SELECTOR * 2
|
|
53
|
+
EXTENSION_SELECTOR = '@'
|
|
53
54
|
|
|
54
55
|
def __call__(self, request):
|
|
55
56
|
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
|
|
@@ -113,6 +114,7 @@ class NamespaceTraverser(ResourceTreeTraverser):
|
|
|
113
114
|
plus_selector = self.PLUS_SELECTOR
|
|
114
115
|
ns_selector = self.NAMESPACE_SELECTOR
|
|
115
116
|
view_selector = self.VIEW_SELECTOR
|
|
117
|
+
extension_selector = self.EXTENSION_SELECTOR
|
|
116
118
|
vpath_tuple = split_path_info(vpath)
|
|
117
119
|
|
|
118
120
|
for segment in vpath_tuple:
|
|
@@ -172,10 +174,35 @@ class NamespaceTraverser(ResourceTreeTraverser):
|
|
|
172
174
|
'virtual_root_path': vroot_tuple,
|
|
173
175
|
'root': root
|
|
174
176
|
}
|
|
177
|
+
|
|
178
|
+
elif segment[:1] == extension_selector:
|
|
179
|
+
# check for an extension adapter using '@name' annotation
|
|
180
|
+
name = segment[1:]
|
|
181
|
+
traverser = queryMultiAdapter((obj, request), IExtensionTraverser, name=name)
|
|
182
|
+
if traverser is None:
|
|
183
|
+
raise NotFound()
|
|
184
|
+
obj = traverser.traverse(vpath_tuple[vroot_idx + i + 1:])
|
|
185
|
+
i += 1
|
|
186
|
+
continue
|
|
175
187
|
|
|
176
188
|
try:
|
|
177
189
|
getitem = obj.__getitem__
|
|
178
190
|
except AttributeError:
|
|
191
|
+
# check for view matching current segment
|
|
192
|
+
if len(vpath_tuple) > i + 1:
|
|
193
|
+
view = request.registry.queryMultiAdapter((obj, request), IView, name=segment)
|
|
194
|
+
if view is not None:
|
|
195
|
+
try:
|
|
196
|
+
from pyams_pagelet.interfaces import IPagelet, PageletCreatedEvent
|
|
197
|
+
except ImportError:
|
|
198
|
+
pass
|
|
199
|
+
else:
|
|
200
|
+
if IPagelet.providedBy(view):
|
|
201
|
+
request.registry.notify(PageletCreatedEvent(view))
|
|
202
|
+
obj = view
|
|
203
|
+
i += 1
|
|
204
|
+
continue
|
|
205
|
+
|
|
179
206
|
return {
|
|
180
207
|
'context': obj,
|
|
181
208
|
'view_name': segment,
|
|
@@ -189,6 +216,28 @@ class NamespaceTraverser(ResourceTreeTraverser):
|
|
|
189
216
|
try:
|
|
190
217
|
next_item = getitem(segment)
|
|
191
218
|
except KeyError:
|
|
219
|
+
subpath = vpath_tuple[i + 1:]
|
|
220
|
+
if subpath: # check for a view on a view!
|
|
221
|
+
request.context = obj
|
|
222
|
+
view = request.registry.queryMultiAdapter((obj, request), IView, name=segment)
|
|
223
|
+
if view is not None:
|
|
224
|
+
try:
|
|
225
|
+
from pyams_pagelet.interfaces import IPagelet, PageletCreatedEvent
|
|
226
|
+
except ImportError:
|
|
227
|
+
pass
|
|
228
|
+
else:
|
|
229
|
+
if IPagelet.providedBy(view):
|
|
230
|
+
request.registry.notify(PageletCreatedEvent(view))
|
|
231
|
+
return {
|
|
232
|
+
'context': view,
|
|
233
|
+
'view_name': subpath[0],
|
|
234
|
+
'subpath': '',
|
|
235
|
+
'traversed': (),
|
|
236
|
+
'virtual_root': vroot,
|
|
237
|
+
'virtual_root_path': vroot_tuple,
|
|
238
|
+
'root': root
|
|
239
|
+
}
|
|
240
|
+
|
|
192
241
|
return {
|
|
193
242
|
'context': obj,
|
|
194
243
|
'view_name': segment,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyams-utils
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.10.0
|
|
4
4
|
Summary: PyAMS generic modules
|
|
5
5
|
Home-page: https://pyams.readthedocs.io
|
|
6
6
|
Author: Thierry Florac
|
|
@@ -58,6 +58,17 @@ Most PyAMS_utils modules are documented using doctests in the /doctests/ sub-dir
|
|
|
58
58
|
Changelog
|
|
59
59
|
=========
|
|
60
60
|
|
|
61
|
+
2.10.0
|
|
62
|
+
------
|
|
63
|
+
- updated namespace traverser to be able to create views on other views, and to add traversing extensions
|
|
64
|
+
support
|
|
65
|
+
|
|
66
|
+
2.9.0
|
|
67
|
+
-----
|
|
68
|
+
- added new "phrase" TALES extension to extract first phrases of a given text
|
|
69
|
+
- added optional "display_context" argument to custom request factory
|
|
70
|
+
- force injected Fanstatic resources to top page
|
|
71
|
+
|
|
61
72
|
2.8.2
|
|
62
73
|
-----
|
|
63
74
|
- removed CORS headers checkers (imported from PyAMS_security)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo
RENAMED
|
File without changes
|
{pyams_utils-2.8.2 → pyams_utils-2.10.0}/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|