yhttp-mako 1.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.
- yhttp_mako-1.0.0/LICENSE +21 -0
- yhttp_mako-1.0.0/PKG-INFO +47 -0
- yhttp_mako-1.0.0/README.md +9 -0
- yhttp_mako-1.0.0/setup.cfg +4 -0
- yhttp_mako-1.0.0/setup.py +61 -0
- yhttp_mako-1.0.0/tests/test_extension.py +52 -0
- yhttp_mako-1.0.0/yhttp/ext/mako/__init__.py +4 -0
- yhttp_mako-1.0.0/yhttp/ext/mako/install.py +50 -0
- yhttp_mako-1.0.0/yhttp_mako.egg-info/PKG-INFO +47 -0
- yhttp_mako-1.0.0/yhttp_mako.egg-info/SOURCES.txt +11 -0
- yhttp_mako-1.0.0/yhttp_mako.egg-info/dependency_links.txt +1 -0
- yhttp_mako-1.0.0/yhttp_mako.egg-info/requires.txt +3 -0
- yhttp_mako-1.0.0/yhttp_mako.egg-info/top_level.txt +1 -0
yhttp_mako-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yhttp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yhttp-mako
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A very micro http framework.
|
|
5
|
+
Home-page: http://github.com/yhttp/yhttp-mako
|
|
6
|
+
Author: Vahid Mardani
|
|
7
|
+
Author-email: vahid.mardani@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: License :: Other/Proprietary License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Topic :: Software Development
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: yhttp<8,>=7.8
|
|
26
|
+
Requires-Dist: yhttp-i18n<2,>=1.2
|
|
27
|
+
Requires-Dist: babel<3,>=2.18
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# yhttp-mako
|
|
40
|
+
|
|
41
|
+
[](https://pypi.python.org/pypi/yhttp-mako)
|
|
42
|
+
[](https://github.com/yhttp/yhttp-mako/actions/workflows/build.yml)
|
|
43
|
+
[](https://coveralls.io/github/yhttp/yhttp-mako?branch=master)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
[Mako](https://www.makotemplates.org/) templates extension for
|
|
47
|
+
[yhttp](https://github.com/yhttp/yhttp).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# yhttp-mako
|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/yhttp-mako)
|
|
4
|
+
[](https://github.com/yhttp/yhttp-mako/actions/workflows/build.yml)
|
|
5
|
+
[](https://coveralls.io/github/yhttp/yhttp-mako?branch=master)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[Mako](https://www.makotemplates.org/) templates extension for
|
|
9
|
+
[yhttp](https://github.com/yhttp/yhttp).
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from setuptools import setup, find_namespace_packages
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# reading package's version (same way sqlalchemy does)
|
|
8
|
+
with open(
|
|
9
|
+
os.path.join(
|
|
10
|
+
os.path.dirname(__file__),
|
|
11
|
+
'yhttp/ext/mako/', '__init__.py'
|
|
12
|
+
)
|
|
13
|
+
) as v_file:
|
|
14
|
+
package_version = \
|
|
15
|
+
re.compile('.*__version__ = \'(.*?)\'', re.S)\
|
|
16
|
+
.match(v_file.read())\
|
|
17
|
+
.group(1)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
dependencies = [
|
|
21
|
+
'yhttp >= 7.8, < 8',
|
|
22
|
+
'yhttp-i18n >= 1.2, < 2',
|
|
23
|
+
'babel >= 2.18, < 3',
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
setup(
|
|
28
|
+
name='yhttp-mako',
|
|
29
|
+
version=package_version,
|
|
30
|
+
author='Vahid Mardani',
|
|
31
|
+
author_email='vahid.mardani@gmail.com',
|
|
32
|
+
url='http://github.com/yhttp/yhttp-mako',
|
|
33
|
+
description='A very micro http framework.',
|
|
34
|
+
long_description=open('README.md').read(),
|
|
35
|
+
long_description_content_type='text/markdown', # This is important!
|
|
36
|
+
license='MIT',
|
|
37
|
+
install_requires=dependencies,
|
|
38
|
+
packages=find_namespace_packages(
|
|
39
|
+
where='.',
|
|
40
|
+
include=[
|
|
41
|
+
'yhttp.ext.mako',
|
|
42
|
+
],
|
|
43
|
+
exclude=['tests'],
|
|
44
|
+
),
|
|
45
|
+
classifiers=[
|
|
46
|
+
'Environment :: Console',
|
|
47
|
+
'Environment :: Web Environment',
|
|
48
|
+
'Intended Audience :: Developers',
|
|
49
|
+
'Natural Language :: English',
|
|
50
|
+
'Development Status :: 5 - Production/Stable',
|
|
51
|
+
'License :: Other/Proprietary License',
|
|
52
|
+
'Operating System :: OS Independent',
|
|
53
|
+
'Programming Language :: Python :: 3.8',
|
|
54
|
+
'Topic :: Software Development',
|
|
55
|
+
'Topic :: Internet :: WWW/HTTP',
|
|
56
|
+
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
|
57
|
+
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
|
|
58
|
+
'Topic :: Software Development :: Libraries',
|
|
59
|
+
'Topic :: Software Development :: Libraries :: Python Modules',
|
|
60
|
+
]
|
|
61
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from bddrest import status, response
|
|
4
|
+
|
|
5
|
+
from yhttp.ext import mako, i18n
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_extension(httpreq, app, mockupfs):
|
|
9
|
+
tmpfs = mockupfs(**{
|
|
10
|
+
'modules': {},
|
|
11
|
+
'templates': {
|
|
12
|
+
'index.mako': '${foo}'
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
i18n.install(app)
|
|
16
|
+
mako.install(app)
|
|
17
|
+
app.settings.mako.lookup = f'{tmpfs}/templates'
|
|
18
|
+
app.settings.mako.modules = f'{tmpfs}/modules'
|
|
19
|
+
app.ready()
|
|
20
|
+
|
|
21
|
+
@app.route()
|
|
22
|
+
@app.i18n
|
|
23
|
+
@app.template('index.mako')
|
|
24
|
+
def get(req):
|
|
25
|
+
return dict(foo='Foo')
|
|
26
|
+
|
|
27
|
+
with httpreq():
|
|
28
|
+
assert status == 200
|
|
29
|
+
assert response == 'Foo'
|
|
30
|
+
|
|
31
|
+
assert os.path.exists(f'{tmpfs}/modules/index.mako.py')
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_render_error(httpreq, app, mockupfs):
|
|
35
|
+
tmpfs = mockupfs(**{
|
|
36
|
+
'modules': {},
|
|
37
|
+
'templates': {
|
|
38
|
+
'index.mako': '${notdefined}'
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
mako.install(app)
|
|
42
|
+
app.settings.mako.lookup = f'{tmpfs}/templates'
|
|
43
|
+
app.settings.mako.modules = f'{tmpfs}/modules'
|
|
44
|
+
app.ready()
|
|
45
|
+
|
|
46
|
+
@app.route()
|
|
47
|
+
@app.template('index.mako')
|
|
48
|
+
def get(req):
|
|
49
|
+
return dict(foo='Foo')
|
|
50
|
+
|
|
51
|
+
with httpreq():
|
|
52
|
+
assert status == 200
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
|
|
3
|
+
from mako.lookup import TemplateLookup, exceptions
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
DEFAULT_SETTINGS = '''
|
|
7
|
+
modules: makomodules
|
|
8
|
+
cache:
|
|
9
|
+
size: 500
|
|
10
|
+
lookup: templates
|
|
11
|
+
'''
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def decoratorfactory(template):
|
|
15
|
+
def decorator(handler):
|
|
16
|
+
@functools.wraps(handler)
|
|
17
|
+
def wrapper(req, *a, **kw):
|
|
18
|
+
data = handler(req, *a, **kw)
|
|
19
|
+
t = req.application.lookup.get_template(template)
|
|
20
|
+
req.response.type = 'text/html'
|
|
21
|
+
if hasattr(req, 'translator'):
|
|
22
|
+
data['_'] = req.translator.gettext
|
|
23
|
+
data['N_'] = req.translator.ngettext
|
|
24
|
+
data['P_'] = req.translator.pgettext
|
|
25
|
+
data['NP_'] = req.translator.pgettext
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
return t.render(**data)
|
|
29
|
+
except: # noqa: E722
|
|
30
|
+
return exceptions.html_error_template().render()
|
|
31
|
+
|
|
32
|
+
return wrapper
|
|
33
|
+
return decorator
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def install(app):
|
|
37
|
+
app.template = decoratorfactory
|
|
38
|
+
app.settings.merge('mako: {}')
|
|
39
|
+
app.settings['mako'].merge(DEFAULT_SETTINGS)
|
|
40
|
+
app.template = decoratorfactory
|
|
41
|
+
|
|
42
|
+
@app.when
|
|
43
|
+
def ready(app):
|
|
44
|
+
app.lookup = TemplateLookup(
|
|
45
|
+
directories=app.settings.mako.lookup,
|
|
46
|
+
module_directory=app.settings.mako.modules,
|
|
47
|
+
collection_size=app.settings.mako.cache.size,
|
|
48
|
+
filesystem_checks=app.settings.debug,
|
|
49
|
+
output_encoding='utf-8',
|
|
50
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yhttp-mako
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A very micro http framework.
|
|
5
|
+
Home-page: http://github.com/yhttp/yhttp-mako
|
|
6
|
+
Author: Vahid Mardani
|
|
7
|
+
Author-email: vahid.mardani@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: License :: Other/Proprietary License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Topic :: Software Development
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: yhttp<8,>=7.8
|
|
26
|
+
Requires-Dist: yhttp-i18n<2,>=1.2
|
|
27
|
+
Requires-Dist: babel<3,>=2.18
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# yhttp-mako
|
|
40
|
+
|
|
41
|
+
[](https://pypi.python.org/pypi/yhttp-mako)
|
|
42
|
+
[](https://github.com/yhttp/yhttp-mako/actions/workflows/build.yml)
|
|
43
|
+
[](https://coveralls.io/github/yhttp/yhttp-mako?branch=master)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
[Mako](https://www.makotemplates.org/) templates extension for
|
|
47
|
+
[yhttp](https://github.com/yhttp/yhttp).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
tests/test_extension.py
|
|
5
|
+
yhttp/ext/mako/__init__.py
|
|
6
|
+
yhttp/ext/mako/install.py
|
|
7
|
+
yhttp_mako.egg-info/PKG-INFO
|
|
8
|
+
yhttp_mako.egg-info/SOURCES.txt
|
|
9
|
+
yhttp_mako.egg-info/dependency_links.txt
|
|
10
|
+
yhttp_mako.egg-info/requires.txt
|
|
11
|
+
yhttp_mako.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
yhttp
|