pyams-utils 2.9.0__tar.gz → 3.0.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.
Files changed (136) hide show
  1. pyams_utils-3.0.0/.gitignore +59 -0
  2. pyams_utils-3.0.0/.hgignore +23 -0
  3. pyams_utils-3.0.0/PKG-INFO +95 -0
  4. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/docs/HISTORY.rst +5 -0
  5. pyams_utils-3.0.0/pyproject.toml +114 -0
  6. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/adapter.py +12 -2
  7. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/context.py +0 -1
  8. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/data.py +23 -0
  9. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/date.py +50 -25
  10. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/dict.py +51 -5
  11. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/adapter.rst +2 -1
  12. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/cache.rst +2 -1
  13. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/date.rst +2 -1
  14. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/fanstatic.rst +9 -0
  15. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/intids.rst +2 -1
  16. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/list.rst +26 -0
  17. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/location.rst +2 -1
  18. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/monitor.rst +2 -1
  19. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/progress.rst +12 -3
  20. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/protocol-xmlrpc.rst +1 -1
  21. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/pygments.rst +6 -7
  22. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/registry.rst +2 -1
  23. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/rest.rst +2 -1
  24. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/rpc.rst +2 -1
  25. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/session.rst +2 -1
  26. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/size.rst +2 -1
  27. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/tales.rst +2 -1
  28. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/text.rst +2 -1
  29. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/timezone.rst +3 -2
  30. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/traversing.rst +1 -1
  31. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/url.rst +2 -1
  32. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/wsgi.rst +2 -1
  33. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/fanstatic.py +30 -6
  34. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/include.py +2 -1
  35. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/__init__.py +13 -0
  36. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/monitor.py +6 -1
  37. pyams_utils-3.0.0/src/pyams_utils/interfaces/progress.py +20 -0
  38. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/pygments.py +2 -2
  39. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/traversing.py +7 -0
  40. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/zeo.py +1 -1
  41. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/json.py +19 -7
  42. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/list.py +24 -0
  43. pyams_utils-3.0.0/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo +0 -0
  44. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po +1326 -1282
  45. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/locales/pyams_utils.pot +904 -895
  46. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/progress.py +54 -21
  47. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/protocol/http.py +5 -9
  48. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/protocol/xmlrpc.py +4 -4
  49. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/pygments.py +1 -1
  50. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/registry.py +2 -1
  51. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/request.py +147 -1
  52. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/testing.py +11 -2
  53. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/text.py +2 -1
  54. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/traversing.py +49 -5
  55. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/unicode.py +6 -0
  56. pyams_utils-2.9.0/PKG-INFO +0 -513
  57. pyams_utils-2.9.0/setup.cfg +0 -4
  58. pyams_utils-2.9.0/setup.py +0 -103
  59. pyams_utils-2.9.0/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo +0 -0
  60. pyams_utils-2.9.0/src/pyams_utils.egg-info/PKG-INFO +0 -513
  61. pyams_utils-2.9.0/src/pyams_utils.egg-info/SOURCES.txt +0 -128
  62. pyams_utils-2.9.0/src/pyams_utils.egg-info/dependency_links.txt +0 -1
  63. pyams_utils-2.9.0/src/pyams_utils.egg-info/namespace_packages.txt +0 -1
  64. pyams_utils-2.9.0/src/pyams_utils.egg-info/not-zip-safe +0 -1
  65. pyams_utils-2.9.0/src/pyams_utils.egg-info/requires.txt +0 -41
  66. pyams_utils-2.9.0/src/pyams_utils.egg-info/top_level.txt +0 -1
  67. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/LICENSE +0 -0
  68. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/MANIFEST.in +0 -0
  69. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/docs/README.rst +0 -0
  70. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/__init__.py +0 -0
  71. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/attr.py +0 -0
  72. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/cache.py +0 -0
  73. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/configure.zcml +0 -0
  74. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/container.py +0 -0
  75. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/country.py +0 -0
  76. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/decorator.py +0 -0
  77. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/README.rst +0 -0
  78. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/attr.rst +0 -0
  79. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/container.rst +0 -0
  80. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/context.rst +0 -0
  81. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/data.rst +0 -0
  82. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/factory.rst +0 -0
  83. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/i18n.rst +0 -0
  84. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/inherit.rst +0 -0
  85. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/lock.rst +0 -0
  86. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/property.rst +0 -0
  87. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/protocol-http.rst +0 -0
  88. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/protocol-socket.rst +0 -0
  89. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/request.rst +0 -0
  90. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/schema.rst +0 -0
  91. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/transaction.rst +0 -0
  92. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/doctests/zodb.rst +0 -0
  93. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/encoding.py +0 -0
  94. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/factory.py +0 -0
  95. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/finder.py +0 -0
  96. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/html.py +0 -0
  97. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/i18n.py +0 -0
  98. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/inherit.py +0 -0
  99. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/data.py +0 -0
  100. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/form.py +0 -0
  101. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/inherit.py +0 -0
  102. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/intids.py +0 -0
  103. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/proxy.py +0 -0
  104. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/rest.py +0 -0
  105. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/size.py +0 -0
  106. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/tales.py +0 -0
  107. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/text.py +0 -0
  108. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/timezone.py +0 -0
  109. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/transaction.py +0 -0
  110. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/tree.py +0 -0
  111. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/interfaces/url.py +0 -0
  112. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/intids.py +0 -0
  113. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/location.py +0 -0
  114. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/lock.py +0 -0
  115. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/monitor.py +0 -0
  116. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/property.py +0 -0
  117. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/protocol/__init__.py +0 -0
  118. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/protocol/tcp.py +0 -0
  119. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/rest.py +0 -0
  120. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/rpc.py +0 -0
  121. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/schema.py +0 -0
  122. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/session.py +0 -0
  123. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/size.py +0 -0
  124. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/tales.py +0 -0
  125. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/tests/__init__.py +0 -0
  126. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/tests/test_dotdict.py +0 -0
  127. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/tests/test_utilsdocs.py +0 -0
  128. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/tests/test_utilsdocstrings.py +0 -0
  129. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/timezone/__init__.py +0 -0
  130. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/timezone/utility.py +0 -0
  131. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/timezone/vocabulary.py +0 -0
  132. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/transaction.py +0 -0
  133. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/url.py +0 -0
  134. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/vocabulary.py +0 -0
  135. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/wsgi.py +0 -0
  136. {pyams_utils-2.9.0 → pyams_utils-3.0.0}/src/pyams_utils/zodb.py +0 -0
@@ -0,0 +1,59 @@
1
+ # Dependencies
2
+ node_modules/
3
+ .pnp
4
+ .pnp.js
5
+
6
+ # Testing
7
+ /.gitlab-ci-local/
8
+ coverage/
9
+
10
+ # Production
11
+ build/
12
+ dist/
13
+ src/pyams_utils.egg-info/
14
+ src/pyams_utils-*.dist-info/
15
+
16
+ # Misc
17
+ .DS_Store
18
+ *.pem
19
+
20
+ # Debug
21
+ npm-debug.log*
22
+ yarn-debug.log*
23
+ yarn-error.log*
24
+
25
+ # Local env files
26
+ .env
27
+ .env.local
28
+ .env.development.local
29
+ .env.test.local
30
+ .env.production.local
31
+
32
+ # Vercel
33
+ .vercel
34
+
35
+ # TypeScript
36
+ *.tsbuildinfo
37
+ next-env.d.ts
38
+
39
+ # IDE
40
+ .idea/
41
+ .vscode/
42
+ *.swp
43
+ *.swo
44
+
45
+ # Logs
46
+ logs/
47
+ *.log
48
+
49
+ # Archive files
50
+ *.zip
51
+ *.tar
52
+ *.tar.gz
53
+
54
+ # Python
55
+ __pycache__/
56
+ *.pyc
57
+
58
+ # OS
59
+ Thumbs.db
@@ -0,0 +1,23 @@
1
+
2
+ syntax: regexp
3
+ ^develop-eggs$
4
+ syntax: regexp
5
+ ^parts$
6
+ syntax: regexp
7
+ ^bin$
8
+ syntax: regexp
9
+ ^eggs$
10
+ syntax: regexp
11
+ ^\.installed\.cfg$
12
+ syntax: regexp
13
+ ^\.settings$
14
+ syntax: regexp
15
+ ^build$
16
+ syntax: regexp
17
+ ^dist$
18
+ syntax: regexp
19
+ ^\.idea$
20
+ syntax: regexp
21
+ .*\.pyc$
22
+ syntax: regexp
23
+ ^docs/build$
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyams_utils
3
+ Version: 3.0.0
4
+ Summary: PyAMS generic utility package
5
+ Project-URL: Homepage, https://pyams.readthedocs.io
6
+ Author-email: Thierry Florac <tflorac@ulthar.net>
7
+ License: ZPL
8
+ License-File: LICENSE
9
+ Keywords: PyAMS,Pyramid
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Framework :: Pyramid
12
+ Classifier: License :: OSI Approved :: Zope Public License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
+ Requires-Python: >=3.9
16
+ Requires-Dist: babel
17
+ Requires-Dist: beaker
18
+ Requires-Dist: btrees
19
+ Requires-Dist: chameleon
20
+ Requires-Dist: colander
21
+ Requires-Dist: cornice
22
+ Requires-Dist: cornice-swagger
23
+ Requires-Dist: docutils
24
+ Requires-Dist: fanstatic
25
+ Requires-Dist: httplib2
26
+ Requires-Dist: legacy-cgi; python_version >= '3.13'
27
+ Requires-Dist: lxml
28
+ Requires-Dist: markdown
29
+ Requires-Dist: persistent
30
+ Requires-Dist: pygments
31
+ Requires-Dist: pyramid-fanstatic
32
+ Requires-Dist: pyramid-rpc
33
+ Requires-Dist: pyramid-zodbconn
34
+ Requires-Dist: pyramid>=2.0.0
35
+ Requires-Dist: pysocks
36
+ Requires-Dist: pytz
37
+ Requires-Dist: transaction
38
+ Requires-Dist: venusian
39
+ Requires-Dist: zeo
40
+ Requires-Dist: zodb
41
+ Requires-Dist: zope-annotation
42
+ Requires-Dist: zope-component
43
+ Requires-Dist: zope-container
44
+ Requires-Dist: zope-contentprovider
45
+ Requires-Dist: zope-copy
46
+ Requires-Dist: zope-dublincore
47
+ Requires-Dist: zope-interface
48
+ Requires-Dist: zope-intid
49
+ Requires-Dist: zope-keyreference
50
+ Requires-Dist: zope-lifecycleevent
51
+ Requires-Dist: zope-location
52
+ Requires-Dist: zope-schema
53
+ Requires-Dist: zope-traversing
54
+ Provides-Extra: test
55
+ Requires-Dist: pyramid-chameleon; extra == 'test'
56
+ Requires-Dist: pyramid-zcml; extra == 'test'
57
+ Requires-Dist: zope-site; extra == 'test'
58
+ Description-Content-Type: text/x-rst
59
+
60
+ ===================
61
+ PyAMS_utils package
62
+ ===================
63
+
64
+ .. contents::
65
+
66
+
67
+ What is PyAMS?
68
+ ==============
69
+
70
+ PyAMS (Pyramid Application Management Suite) is a small suite of packages written for applications
71
+ and content management with the Pyramid framework.
72
+
73
+ **PyAMS** is actually mainly used to manage web sites through content management applications (CMS,
74
+ see PyAMS_content package), but many features are generic and can be used inside any kind of web
75
+ application.
76
+
77
+ All PyAMS documentation is available on `ReadTheDocs <https://pyams.readthedocs.io>`_; source code
78
+ is available on `Gitlab <https://gitlab.com/pyams>`_ and pushed to `Github
79
+ <https://github.com/py-ams>`_.
80
+
81
+
82
+ What is PyAMS_utils?
83
+ ====================
84
+
85
+ PyAMS_utils is a large set of small generic modules used to handle PyAMS applications.
86
+
87
+ These modules provide several decorators used to declare object factories, adapters, utilities
88
+ and vocabularies; they also provide a large set of adapters, utilities and predicates related to
89
+ many common operations like caching, dates management, data API, text conversions, request
90
+ properties..., as well as custom schema fields.
91
+
92
+ When included into Pyramid's configuration, this package also register several Zope packages
93
+ through ZCML, typically to automatically inclure DublinCore extensions or IntIDs management.
94
+
95
+ Most PyAMS_utils modules are documented using doctests in the /doctests/ sub-directory.
@@ -2,6 +2,11 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 3.0.0
6
+ -----
7
+ - added support for Python 3.13, 3.14 and 3.15 (3.13 is still the development platform)
8
+ - prepared for ZMI migration to MyAMS v3
9
+
5
10
  2.9.0
6
11
  -----
7
12
  - added new "phrase" TALES extension to extract first phrases of a given text
@@ -0,0 +1,114 @@
1
+ #
2
+ # Copyright (c) 2015-2019 Thierry Florac <tflorac AT ulthar.net>
3
+ # All Rights Reserved.
4
+ #
5
+ # This software is subject to the provisions of the Zope Public License,
6
+ # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7
+ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
+ # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
+ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
+ # FOR A PARTICULAR PURPOSE.
11
+ #
12
+
13
+ [build-system]
14
+ requires = ["hatchling", "hatch-vcs"]
15
+ build-backend = "hatchling.build"
16
+
17
+ [project]
18
+ name = "pyams_utils"
19
+ dynamic = ["version"]
20
+ description = "PyAMS generic utility package"
21
+ readme = {file = "docs/README.rst", content-type = "text/x-rst"}
22
+ license = {text = "ZPL"}
23
+ authors = [
24
+ {name = "Thierry Florac", email = "tflorac@ulthar.net"},
25
+ ]
26
+ keywords = ["Pyramid", "PyAMS"]
27
+ classifiers = [
28
+ "License :: OSI Approved :: Zope Public License",
29
+ "Development Status :: 4 - Beta",
30
+ "Programming Language :: Python",
31
+ "Framework :: Pyramid",
32
+ "Topic :: Software Development :: Libraries :: Python Modules",
33
+ ]
34
+ requires-python = ">=3.9"
35
+ dependencies = [
36
+ "BTrees",
37
+ "ZEO",
38
+ "ZODB",
39
+ "babel",
40
+ "beaker",
41
+ "chameleon",
42
+ "colander",
43
+ "cornice",
44
+ "cornice_swagger",
45
+ "docutils",
46
+ "fanstatic",
47
+ "httplib2",
48
+ "legacy-cgi; python_version >= '3.13'",
49
+ "lxml",
50
+ "markdown",
51
+ "persistent",
52
+ "pygments",
53
+ "pyramid >= 2.0.0",
54
+ "pyramid_fanstatic",
55
+ "pyramid_rpc",
56
+ "pyramid_zodbconn",
57
+ "pysocks",
58
+ "pytz",
59
+ "transaction",
60
+ "venusian",
61
+ "zope.annotation",
62
+ "zope.component",
63
+ "zope.container",
64
+ "zope.contentprovider",
65
+ "zope.copy",
66
+ "zope.dublincore",
67
+ "zope.interface",
68
+ "zope.intid",
69
+ "zope.keyreference",
70
+ "zope.lifecycleevent",
71
+ "zope.location",
72
+ "zope.schema",
73
+ "zope.traversing",
74
+ ]
75
+
76
+ [project.optional-dependencies]
77
+ test = [
78
+ "pyramid_chameleon",
79
+ "pyramid_zcml",
80
+ "zope.site",
81
+ ]
82
+
83
+ [project.urls]
84
+ Homepage = "https://pyams.readthedocs.io"
85
+
86
+ [tool.hatch.build.targets.wheel]
87
+ sources = ["src"]
88
+ packages = ["src/pyams_utils"]
89
+
90
+ [tool.hatch.build.targets.sdist]
91
+ include = [
92
+ "src/",
93
+ "docs/",
94
+ "MANIFEST.in",
95
+ ]
96
+
97
+ [tool.hatch.build]
98
+ include = [
99
+ "*.zcml",
100
+ "*.txt",
101
+ "*.pt",
102
+ "*.pot",
103
+ "*.po",
104
+ "*.mo",
105
+ "*.png",
106
+ "*.gif",
107
+ "*.jpeg",
108
+ "*.jpg",
109
+ "*.css",
110
+ "*.js",
111
+ ]
112
+
113
+ [tool.hatch.version]
114
+ source = "vcs"
@@ -18,6 +18,7 @@ and *context* and *request* and *view*.
18
18
  See :ref:`zca` to see how PyAMS can help components management.
19
19
  """
20
20
 
21
+ import inspect
21
22
  import logging
22
23
  from inspect import isclass
23
24
 
@@ -30,13 +31,19 @@ from zope.location import locate as zope_locate
30
31
  from pyams_utils.factory import get_object_factory, is_interface
31
32
  from pyams_utils.registry import get_current_registry
32
33
 
33
-
34
34
  __docformat__ = 'restructuredtext'
35
35
 
36
36
 
37
37
  LOGGER = logging.getLogger('PyAMS (utils)')
38
38
 
39
39
 
40
+ def call(callable, *args):
41
+ """Call a callable with a variable number of arguments"""
42
+ sig = inspect.signature(callable)
43
+ nb_params = len(sig.parameters)
44
+ return callable(*args[:nb_params])
45
+
46
+
40
47
  class ContextAdapter:
41
48
  """Context adapter"""
42
49
 
@@ -163,7 +170,10 @@ def query_adapter(interface, request, context=None, view=None, name=''):
163
170
  if adapter is None:
164
171
  adapter = registry.queryMultiAdapter((context, request), interface, name=name)
165
172
  if adapter is None:
166
- adapter = registry.queryAdapter(context, interface, name=name)
173
+ if interface.providedBy(context):
174
+ adapter = context
175
+ else:
176
+ adapter = registry.queryAdapter(context, interface, name=name)
167
177
  return adapter
168
178
 
169
179
 
@@ -22,7 +22,6 @@ import sys
22
22
  from contextlib import contextmanager
23
23
  from io import StringIO
24
24
 
25
-
26
25
  __docformat__ = 'restructuredtext'
27
26
 
28
27
  from pyams_utils.factory import is_interface
@@ -61,6 +61,29 @@ def format_data(mapping):
61
61
  return ' '.join((f'data-{k}="{v}"' for k, v in mapping.items()))
62
62
 
63
63
 
64
+ def snake_to_camel(snake_str: str) -> str:
65
+ """Convert a snake_case string to camelCase
66
+
67
+ >>> from pyams_utils.data import snake_to_camel
68
+ >>> snake_to_camel('my_snake_case_string')
69
+ 'mySnakeCaseString'
70
+ >>> snake_to_camel('')
71
+ ''
72
+ >>> snake_to_camel(None)
73
+ ''
74
+
75
+ Untouched strings can be specified by enclosing text with '^' characters:
76
+ >>> snake_to_camel('^my_snake_case_string^')
77
+ 'my_snake_case_string'
78
+ """
79
+ if not snake_str:
80
+ return ''
81
+ if snake_str.startswith('^') and snake_str.endswith('^'):
82
+ return snake_str[1:-1]
83
+ components = snake_str.split('_')
84
+ return components[0] + ''.join(x.title() for x in components[1:])
85
+
86
+
64
87
  @implementer(IObjectData)
65
88
  class ObjectDataManagerMixin:
66
89
  """Object data manager mixin class"""
@@ -302,23 +302,53 @@ def get_age(value, request=None):
302
302
  now = gmtime(datetime.now(timezone.utc))
303
303
  delta = now - gmtime(value)
304
304
  if delta.days > 60:
305
- return translate(_("%d months ago")) % int(round(delta.days * 1.0 / 30))
305
+ return translate(_("{months} months ago")).format(months=int(round(delta.days * 1.0 / 30)))
306
306
  if delta.days > 10:
307
- return translate(_("%d weeks ago")) % int(round(delta.days * 1.0 / 7))
307
+ return translate(_("{weeks} weeks ago")).format(weeks=int(round(delta.days * 1.0 / 7)))
308
308
  if delta.days > 2:
309
- return translate(_("%d days ago")) % delta.days
309
+ return translate(_("{days} days ago")).format(days=delta.days)
310
310
  if delta.days == 2:
311
311
  return translate(_("the day before yesterday"))
312
312
  if delta.days == 1:
313
313
  return translate(_("yesterday"))
314
314
  hours = int(round(delta.seconds * 1.0 / 3600))
315
315
  if hours > 1:
316
- return translate(_("%d hours ago")) % hours
316
+ return translate(_("{hours} hours ago")).format(hours=hours)
317
317
  if delta.seconds > 300:
318
- return translate(_("%d minutes ago")) % int(round(delta.seconds * 1.0 / 60))
318
+ return translate(_("{minutes} minutes ago")).format(minutes=int(round(delta.seconds * 1.0 / 60)))
319
319
  return translate(_("less than 5 minutes ago"))
320
320
 
321
321
 
322
+ def get_delta_duration(delta, request=None):
323
+ """Get 'human' delta as string between two dates
324
+
325
+ :param timedelta delta: input timedelta to be converted to human readable string
326
+ :param request: the request from which to extract localization infos
327
+ :return: str; approximate delta between the two input dates
328
+ """
329
+ if request is None:
330
+ request = check_request()
331
+ translate = request.localizer.translate
332
+ if delta.days > 60:
333
+ return translate(_("{months} months")).format(months=int(round(delta.days * 1.0 / 30)))
334
+ if delta.days > 10:
335
+ return translate(_("{weeks} weeks")).format(weeks=int(round(delta.days * 1.0 / 7)))
336
+ if delta.days >= 2:
337
+ return translate(_("{days} days")).format(days=delta.days)
338
+ hours = int(round(delta.seconds * 1.0 / 3600))
339
+ if delta.days == 1:
340
+ if hours == 0:
341
+ return translate(_("24 hours"))
342
+ return translate(_("1 day and {hours} hours")).format(hours=hours)
343
+ if hours > 2:
344
+ return translate(_("{hours} hours")).format(hours=hours)
345
+ minutes = int(round(delta.seconds * 1.0 / 60))
346
+ if minutes > 2:
347
+ return translate(_("{minutes} minutes")).format(minutes=minutes)
348
+ return translate(_("{seconds} seconds")).format(seconds=delta.seconds) \
349
+ if delta.seconds > 1 else translate(_("less than 1 second"))
350
+
351
+
322
352
  def get_duration(first, last=None, request=None): # pylint: disable=too-many-branches
323
353
  """Get 'human' delta as string between two dates
324
354
 
@@ -393,26 +423,21 @@ def get_duration(first, last=None, request=None): # pylint: disable=too-many-br
393
423
  last = UTC.localize(last)
394
424
  first, last = min(first, last), max(first, last)
395
425
  delta = last - first
396
- if request is None:
397
- request = check_request()
398
- translate = request.localizer.translate
399
- if delta.days > 60:
400
- return translate(_("%d months")) % int(round(delta.days * 1.0 / 30))
401
- if delta.days > 10:
402
- return translate(_("%d weeks")) % int(round(delta.days * 1.0 / 7))
403
- if delta.days >= 2:
404
- return translate(_("%d days")) % delta.days
405
- hours = int(round(delta.seconds * 1.0 / 3600))
406
- if delta.days == 1:
407
- if hours == 0:
408
- return translate(_("24 hours"))
409
- return translate(_("%d day and %d hours")) % (delta.days, hours)
410
- if hours > 2:
411
- return translate(_("%d hours")) % hours
412
- minutes = int(round(delta.seconds * 1.0 / 60))
413
- if minutes > 2:
414
- return translate(_("%d minutes")) % minutes
415
- return translate(_("%d seconds")) % delta.seconds
426
+ return get_delta_duration(delta, request)
427
+
428
+
429
+ def get_seconds_duration(value, request=None):
430
+ """Get 'human' time length of a value given in seconds
431
+
432
+ :param int value: input value in seconds
433
+ :param IRequest request: the request from which to extract localization infos
434
+ :return: str; approximate time length of the input value converted to
435
+ months, weeks, days, hours or minutes
436
+ """
437
+ if not value:
438
+ return MISSING_INFO
439
+ delta = timedelta(seconds=value)
440
+ return get_delta_duration(delta, request)
416
441
 
417
442
 
418
443
  #
@@ -17,8 +17,11 @@ dictionary; if given value argument is a boolean 'true' value, given dictionary'
17
17
  or updated, otherwise dictionary is left unchanged.
18
18
  """
19
19
 
20
+ import string
20
21
  from html import escape
21
22
 
23
+ from pyams_utils.data import snake_to_camel
24
+
22
25
  __docformat__ = 'restructuredtext'
23
26
 
24
27
 
@@ -108,9 +111,15 @@ def update_dict(input_dict: dict, key, value):
108
111
  input_dict[key] = value
109
112
 
110
113
 
111
- def merge_dict(source: dict, target: dict):
114
+ def merge_dict(source: dict, target: dict, replace=False):
112
115
  """Deep merge of source mapping into target mapping
113
116
 
117
+ :param dict source: source mapping
118
+ :param dict target: target mapping
119
+ :param bool replace: if True, source mapping values will replace target mapping values; otherwise,
120
+ source mapping values will be replaced by target mapping values
121
+ :return: updated target mapping
122
+
114
123
  >>> from pyams_utils.dict import merge_dict
115
124
  >>> trg = {}
116
125
  >>> merge_dict({}, trg)
@@ -134,15 +143,26 @@ def merge_dict(source: dict, target: dict):
134
143
  'key 3': ['Value 4', 'Value 5'], 'key 4': {'Value 6'}}
135
144
  >>> sorted(merge_dict({'key 4': {'Value 7'}}, trg)['key 4'])
136
145
  ['Value 6', 'Value 7']
146
+
147
+ When replace is True, source mapping values will replace target mapping values; otherwise,
148
+ source mapping values will be replaced by target mapping values:
149
+ >>> merge_dict({'key 2': {'subkey 3': 'subvalue 4'}}, trg, replace=False)['key 2']
150
+ {'subkey 1': 'subvalue 2', 'subkey 2': 'subvalue 3', 'subkey 3': 'subvalue 4'}
151
+ >>> merge_dict({'key 2': {'subkey 3': 'subvalue 4'}}, trg, replace=True)['key 2']
152
+ {'subkey 3': 'subvalue 4'}
137
153
  """
138
154
  for key, value in source.items():
139
155
  if key in target:
140
- if isinstance(target[key], (list, tuple)):
156
+ target_value = target[key]
157
+ if isinstance(target_value, (list, tuple)):
141
158
  target[key] += source[key]
142
- elif isinstance(target[key], set):
159
+ elif isinstance(target_value, set):
143
160
  target[key] |= source[key]
144
- elif isinstance(target[key], dict):
145
- target[key].update(value)
161
+ elif isinstance(target_value, dict):
162
+ if replace:
163
+ target[key] = value
164
+ else:
165
+ target[key] = merge_dict(value, target[key], replace=replace)
146
166
  else:
147
167
  target[key] = value
148
168
  else:
@@ -215,6 +235,32 @@ def escape_dict(value, in_place=False):
215
235
  return result
216
236
 
217
237
 
238
+ def camel_dict(data):
239
+ """Convert a dictionary with snake_case keys to camelCase
240
+
241
+ >>> from pyams_utils.dict import camel_dict
242
+
243
+ >>> camel_dict({'my_snake_case_string': 'value'})
244
+ {'mySnakeCaseString': 'value'}
245
+ >>> camel_dict({'^my_snake_case_string^': 'value'})
246
+ {'my_snake_case_string': 'value'}
247
+ """
248
+ if isinstance(data, dict):
249
+ new_dict = {}
250
+ keep_snake_case = data.get('@myams/keep_snake_case', False)
251
+ for key, value in data.items():
252
+ if key.startswith('^') and key.endswith('^'):
253
+ new_key = key[1:-1]
254
+ else:
255
+ new_key = snake_to_camel(key) if (not keep_snake_case) and key and key[0] in string.ascii_letters else key
256
+ new_dict[new_key] = value if keep_snake_case else camel_dict(value)
257
+ return new_dict
258
+ elif isinstance(data, list):
259
+ return [camel_dict(item) for item in data]
260
+ else:
261
+ return data
262
+
263
+
218
264
  def boolean_dict(input_dict: dict):
219
265
  """Dict values checker
220
266
 
@@ -13,7 +13,8 @@ constructor must accept as many arguments as defined into adapter's "required" p
13
13
 
14
14
  PyAMS_utils provides a small set of commonly used adapters:
15
15
 
16
- >>> from pyramid.testing import setUp, tearDown, DummyRequest
16
+ >>> from pyramid.testing import setUp, tearDown
17
+ >>> from pyams_utils.testing import DummyRequest
17
18
  >>> config = setUp(hook_zca=True)
18
19
 
19
20
  >>> from cornice import includeme as include_cornice
@@ -6,7 +6,8 @@ PyAMS_utils cache module
6
6
  This module is used to provide a few helpers related to cache management ; the ICacheKey
7
7
  interface is used to get a cache key value for any object:
8
8
 
9
- >>> from pyramid.testing import setUp, tearDown, DummyRequest
9
+ >>> from pyramid.testing import setUp, tearDown
10
+ >>> from pyams_utils.testing import DummyRequest
10
11
  >>> config = setUp(hook_zca=True)
11
12
  >>> config.registry.settings['zodbconn.uri'] = 'memory://'
12
13
 
@@ -5,7 +5,8 @@ PyAMS utils date module
5
5
 
6
6
  Dates functions are used to convert dates from/to string representation:
7
7
 
8
- >>> from pyramid.testing import setUp, tearDown, DummyRequest
8
+ >>> from pyramid.testing import setUp, tearDown
9
+ >>> from pyams_utils.testing import DummyRequest
9
10
  >>> config = setUp(hook_zca=True)
10
11
 
11
12
  >>> from cornice import includeme as include_cornice
@@ -22,6 +22,14 @@ or to add custom "data" attributes to a given resource:
22
22
  >>> x1_img = fanstatic.ResourceWithData(library, 'a.img', data={'test-value': 'nested'}, depends=(x1_js,))
23
23
  >>> set_resource_file_existence_checking(True)
24
24
 
25
+ Fanstatic libraries registry is initialized explicitly as an empty registry; this is required
26
+ with Fanstatic < 1.7 on Python < 3.10, which fails when no installed package declares a
27
+ "fanstatic.libraries" entry point:
28
+
29
+ >>> from fanstatic.registry import LibraryRegistry
30
+ >>> previous_registry = LibraryRegistry._instance
31
+ >>> LibraryRegistry._instance = LibraryRegistry()
32
+
25
33
  Let's try to create a custom WSGI application to test this resource:
26
34
 
27
35
  >>> def app(environ, start_response):
@@ -148,4 +156,5 @@ create an HTML email message. PyAMS provides an helper function for this:
148
156
  >>> inject_resources(request, config.registry, app)
149
157
  '<html><head><link rel="stylesheet" data-test-value="nested" type="text/css" href="http://localhost/fanstatic/foo/a.css" /></head><body></body></html>'
150
158
 
159
+ >>> LibraryRegistry._instance = previous_registry
151
160
  >>> tearDown()
@@ -9,7 +9,8 @@ example, to catalog objects.
9
9
 
10
10
  >>> import pprint
11
11
 
12
- >>> from pyramid.testing import setUp, tearDown, DummyRequest
12
+ >>> from pyramid.testing import setUp, tearDown
13
+ >>> from pyams_utils.testing import DummyRequest
13
14
  >>> config = setUp(hook_zca=True)
14
15
  >>> config.registry.settings['zodbconn.uri'] = 'memory://'
15
16
 
@@ -55,6 +55,32 @@ You can also set an 'id' function applied on each element:
55
55
  ['A', 'B', '2', 4]
56
56
 
57
57
 
58
+ Getting a subset of an iterator
59
+ -------------------------------
60
+
61
+ The "subset_iter" function returns an iterator over a subset of an input iterable, starting at a given
62
+ position and returning a given number of elements. The first element of the iterable is chosen using a
63
+ condition which must be satisfied to choose the provided element as the first one. If no condition is provided,
64
+ the first element is chosen. The number of elements is given by the "limit" parameter, which defaults to None,
65
+ meaning that all elements will be returned. If the "limit" parameter is set to a positive integer, only that number
66
+ of elements will be returned.
67
+
68
+ >>> from pyams_utils.list import subset_iter
69
+
70
+ >>> mylist = [1, 2, 3, 4, 5]
71
+ >>> list(subset_iter(mylist))
72
+ [1, 2, 3, 4, 5]
73
+
74
+ >>> list(subset_iter(mylist, limit=2))
75
+ [1, 2]
76
+
77
+ >>> list(subset_iter(mylist, start_condition=lambda x: x > 2, limit=3))
78
+ [3, 4, 5]
79
+
80
+ >>> list(subset_iter(mylist, start_condition=lambda x: x > 2, limit=10))
81
+ [3, 4, 5]
82
+
83
+
58
84
  Getting last elements of unique iterator lists
59
85
  ----------------------------------------------
60
86