PyWSGIRef 1.1.20__tar.gz → 1.1.22__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.
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/LICENSE +21 -21
- {pywsgiref-1.1.20/src/PyWSGIRef.egg-info → pywsgiref-1.1.22}/PKG-INFO +214 -208
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/README.md +196 -190
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/pyproject.toml +21 -21
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/setup.cfg +4 -4
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/__init__.py +22 -11
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/beta.py +44 -43
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/finished.py +23 -23
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/loadContent.py +38 -36
- pywsgiref-1.1.22/src/PyWSGIRef/macro.py +38 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/patterns.py +14 -13
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/pyhtml.py +20 -6
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/simpleServer.py +40 -40
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/stats.py +69 -66
- {pywsgiref-1.1.20 → pywsgiref-1.1.22/src/PyWSGIRef.egg-info}/PKG-INFO +214 -208
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef.egg-info/SOURCES.txt +1 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/tests/testMainServer.py +2 -2
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/__main__.py +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/commons.py +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/defaults.py +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/exceptions.py +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef/templateDict.py +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef.egg-info/requires.txt +0 -0
- {pywsgiref-1.1.20 → pywsgiref-1.1.22}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Leander Kafemann
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Leander Kafemann
|
|
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.
|
|
@@ -1,208 +1,214 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: PyWSGIRef
|
|
3
|
-
Version: 1.1.
|
|
4
|
-
Summary: easy server-setup
|
|
5
|
-
Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.11
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE
|
|
13
|
-
Requires-Dist: requests
|
|
14
|
-
Requires-Dist: legacy-cgi
|
|
15
|
-
Requires-Dist: naturalsize
|
|
16
|
-
Dynamic: license-file
|
|
17
|
-
|
|
18
|
-
# PyWSGIRef
|
|
19
|
-
easy server-setup
|
|
20
|
-
## Advantage
|
|
21
|
-
Many web services offer simple ways to set up a WSGI webserver.<br/>
|
|
22
|
-
The built-in WSGI server in Python is, however, not very easy to use.<br/>
|
|
23
|
-
PyWSGIRef provides a simple way to set up a WSGI server with minimal code.<br/><br/>
|
|
24
|
-
Also, a problem with many of those web services is that they aren't able to make web requests<br/>
|
|
25
|
-
and it's very slow to read files once the server is running.<br/>
|
|
26
|
-
PyWSGIRef solves this problem by providing a simple way to load PyHTML files from the web or from the local filesystem<br/>
|
|
27
|
-
before the server is running.<br/><br/>
|
|
28
|
-
PyHTML files are HTML files that can contain {}-s for Python formatting or<br/>
|
|
29
|
-
(upcoming) code blocks or shortened HTML, which can be used to create dynamic HTML content.<br/>
|
|
30
|
-
PyWSGIRef also provides a simple way to decode these.
|
|
31
|
-
## Installation
|
|
32
|
-
### Using *pip*
|
|
33
|
-
You can install PyWSGIRef via pip using
|
|
34
|
-
<li>in a commandline:</li><br/>
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
py -m pip install PyWSGIRef
|
|
38
|
-
```
|
|
39
|
-
<br/>
|
|
40
|
-
<li>in a python script:</li><br/>
|
|
41
|
-
|
|
42
|
-
```python
|
|
43
|
-
import os
|
|
44
|
-
os.system('py -m pip install PyWSGIRef')
|
|
45
|
-
```
|
|
46
|
-
## Usage
|
|
47
|
-
### Setting up the WSGI server
|
|
48
|
-
```python
|
|
49
|
-
from PyWSGIRef import *
|
|
50
|
-
|
|
51
|
-
# Create a WSGI application object
|
|
52
|
-
def simple_app(path: str) -> str:
|
|
53
|
-
return f"Hello, you visited {path}!"
|
|
54
|
-
application = makeApplicationObject(simple_app)
|
|
55
|
-
|
|
56
|
-
# Create a WSGI server
|
|
57
|
-
server = setUpServer(application, port=8000)
|
|
58
|
-
server.serve_forever()
|
|
59
|
-
```
|
|
60
|
-
The <code>makeWSGIApp</code> function requires a callable that takes a single argument (the path) and returns a string response.<br/>
|
|
61
|
-
The <code>makeWSGIServer</code> function creates a WSGI server that listens on the specified port (default is 8000)<br/>
|
|
62
|
-
and calls the application object with the environ.<br/>
|
|
63
|
-
You may also specify advanced options in <code>makeWSGIApp</code>:<br/>
|
|
64
|
-
- you can set the <code>advanced</code> parameter to <code>True</code>, so that your application method also gets an FieldStorage type object<br/>
|
|
65
|
-
- you can set the <code>setAdvancedHeaders</code> parameter to <code>True</code>, so that the application method is also able to set status codes and types in the response headers,<br/>
|
|
66
|
-
which is only possible if the <code>advanced</code> parameter is set to <code>True</code><br/>
|
|
67
|
-
Example:
|
|
68
|
-
```python
|
|
69
|
-
from PyWSGIRef import *
|
|
70
|
-
|
|
71
|
-
# Create a WSGI application object with advanced options
|
|
72
|
-
def advanced_app(path: str, form: FieldStorage) -> str, str, str:
|
|
73
|
-
# You can access form data here
|
|
74
|
-
name = str(form.getvalue('name'))
|
|
75
|
-
|
|
76
|
-
if path == "/hello":
|
|
77
|
-
return f"Hello, {name}, you visited {path}!", "text/html", "200 OK"
|
|
78
|
-
else:
|
|
79
|
-
return "Page not found", "text/html", "404 Not Found"
|
|
80
|
-
application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
|
|
81
|
-
|
|
82
|
-
# Create a WSGI server
|
|
83
|
-
server = setUpServer(application, port=8000)
|
|
84
|
-
server.serve_forever()
|
|
85
|
-
```
|
|
86
|
-
You can also use your own application object instead of the one created by <code>makeWSGIApp</code>.
|
|
87
|
-
### Loading PyHTML
|
|
88
|
-
PyWSGIRef also provides a simple way to load PyHTML files:
|
|
89
|
-
```python
|
|
90
|
-
from PyWSGIRef import *
|
|
91
|
-
|
|
92
|
-
# load from file
|
|
93
|
-
html = loadFromFile('index.pyhtml')
|
|
94
|
-
|
|
95
|
-
# load from web
|
|
96
|
-
html = loadFromWeb('https://example.com/index.pyhtml')
|
|
97
|
-
```
|
|
98
|
-
This is useful for serving dynamic HTML content in your WSGI application.<br/>
|
|
99
|
-
The funcs are callable unless you set up a server.<br/>
|
|
100
|
-
You can also add multiple PyHTML files from the web at the same time using the <code>multiWebInit</code> function.
|
|
101
|
-
### Using Templates
|
|
102
|
-
PyWSGIRef also provides a simple way to use templates in your WSGI application:
|
|
103
|
-
```python
|
|
104
|
-
from PyWSGIRef import *
|
|
105
|
-
|
|
106
|
-
# add template to template dictionary
|
|
107
|
-
# -> saves as PyHTML object
|
|
108
|
-
addSchablone("index", loadedPyHTMLFile)
|
|
109
|
-
|
|
110
|
-
# load template from dictionary
|
|
111
|
-
# get HTML code from PyHTML object
|
|
112
|
-
html = SCHABLONEN["index"].decoded()
|
|
113
|
-
# use Python formatting
|
|
114
|
-
serverPageContent = html.format("Hello, World!")
|
|
115
|
-
```
|
|
116
|
-
Note that you may only use the <code>addSchablone</code> function before you set up a server.
|
|
117
|
-
### Default HTML templates
|
|
118
|
-
PyWSGIRef comes with some default HTML templates that you can use in your WSGI application.<br/>
|
|
119
|
-
You can access them via the <code>PyWSGIRef.defaults</code>:
|
|
120
|
-
```python
|
|
121
|
-
from PyWSGIRef import *
|
|
122
|
-
|
|
123
|
-
# load default HTML template
|
|
124
|
-
addSchablone("hello", HELLO_WORLD)
|
|
125
|
-
addSchablone("error", ERROR)
|
|
126
|
-
```
|
|
127
|
-
### __main__ script
|
|
128
|
-
You may produce a simple WSGI server by using either:<br/>
|
|
129
|
-
```python
|
|
130
|
-
from PyWSGIRef import main
|
|
131
|
-
|
|
132
|
-
main()
|
|
133
|
-
```
|
|
134
|
-
or (from a commandline)
|
|
135
|
-
```bash
|
|
136
|
-
py -m PyWSGIRef
|
|
137
|
-
```
|
|
138
|
-
### Decoding PyHTML
|
|
139
|
-
(more coming soon...)<br/>
|
|
140
|
-
PyWSGIRef provides a simple way to shorten a common HTML beginning phrase in PyHTML:
|
|
141
|
-
```python
|
|
142
|
-
from PyWSGIRef import PyHTML
|
|
143
|
-
|
|
144
|
-
# Shorten HTML beginning phrase
|
|
145
|
-
pyhtml_ = """<{{evalPyHTML}}>
|
|
146
|
-
<title>My Page</title>
|
|
147
|
-
</head>
|
|
148
|
-
<body>
|
|
149
|
-
<h1>Hello, World!</h1>
|
|
150
|
-
</body>
|
|
151
|
-
</html>"""
|
|
152
|
-
pyhtml = PyHTML(pyhtml_)
|
|
153
|
-
html = pyhtml.decoded()
|
|
154
|
-
```
|
|
155
|
-
, which is actually automatically done by PyWSGIRef.<br/>
|
|
156
|
-
The <code><{{evalPyHTML}}></code> phrase at the beginning of the document includes a Doctype announcement,<br/>
|
|
157
|
-
a html and head block and some common meta phrases as utf-8 encoding or device-width scaling.<br/><br/>
|
|
158
|
-
PyWSGIRef also provides a simple way to end PyHTML files:<br/>
|
|
159
|
-
just use the <code><{{evalPyHTML}}></code> phrase at the end of the document and<br/>
|
|
160
|
-
PyWSGIRef will automatically add the closing html and body tags.<br/><br/>
|
|
161
|
-
You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
|
|
162
|
-
<code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.<br/><br/>
|
|
163
|
-
You may add your own static resources like CSS or JavaScript files using the <code><{{evalPyHTML-include: ... :include-}}></code> phrase.<br/>
|
|
164
|
-
Different static resources can be included by separating them with a comma.<br/>
|
|
165
|
-
You may include CSS, JS, JSON and ICO files.<br/><br/>
|
|
166
|
-
With the <code><{{evalPyHTML-script: alert('Hello, World!'); :script-}}></code> phrase,<br/>
|
|
167
|
-
you can add a script block anywhere inside your PyHTML file.<br/>
|
|
168
|
-
Using pretty much the same syntax, you can also add a style block using
|
|
169
|
-
<code><{{evalPyHTML-style: body { background-color: lightblue; } :style-}}></code>.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
server
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
###
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyWSGIRef
|
|
3
|
+
Version: 1.1.22
|
|
4
|
+
Summary: easy server-setup
|
|
5
|
+
Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: legacy-cgi
|
|
15
|
+
Requires-Dist: naturalsize
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# PyWSGIRef
|
|
19
|
+
easy server-setup
|
|
20
|
+
## Advantage
|
|
21
|
+
Many web services offer simple ways to set up a WSGI webserver.<br/>
|
|
22
|
+
The built-in WSGI server in Python is, however, not very easy to use.<br/>
|
|
23
|
+
PyWSGIRef provides a simple way to set up a WSGI server with minimal code.<br/><br/>
|
|
24
|
+
Also, a problem with many of those web services is that they aren't able to make web requests<br/>
|
|
25
|
+
and it's very slow to read files once the server is running.<br/>
|
|
26
|
+
PyWSGIRef solves this problem by providing a simple way to load PyHTML files from the web or from the local filesystem<br/>
|
|
27
|
+
before the server is running.<br/><br/>
|
|
28
|
+
PyHTML files are HTML files that can contain {}-s for Python formatting or<br/>
|
|
29
|
+
(upcoming) code blocks or shortened HTML, which can be used to create dynamic HTML content.<br/>
|
|
30
|
+
PyWSGIRef also provides a simple way to decode these.
|
|
31
|
+
## Installation
|
|
32
|
+
### Using *pip*
|
|
33
|
+
You can install PyWSGIRef via pip using
|
|
34
|
+
<li>in a commandline:</li><br/>
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
py -m pip install PyWSGIRef
|
|
38
|
+
```
|
|
39
|
+
<br/>
|
|
40
|
+
<li>in a python script:</li><br/>
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import os
|
|
44
|
+
os.system('py -m pip install PyWSGIRef')
|
|
45
|
+
```
|
|
46
|
+
## Usage
|
|
47
|
+
### Setting up the WSGI server
|
|
48
|
+
```python
|
|
49
|
+
from PyWSGIRef import *
|
|
50
|
+
|
|
51
|
+
# Create a WSGI application object
|
|
52
|
+
def simple_app(path: str) -> str:
|
|
53
|
+
return f"Hello, you visited {path}!"
|
|
54
|
+
application = makeApplicationObject(simple_app)
|
|
55
|
+
|
|
56
|
+
# Create a WSGI server
|
|
57
|
+
server = setUpServer(application, port=8000)
|
|
58
|
+
server.serve_forever()
|
|
59
|
+
```
|
|
60
|
+
The <code>makeWSGIApp</code> function requires a callable that takes a single argument (the path) and returns a string response.<br/>
|
|
61
|
+
The <code>makeWSGIServer</code> function creates a WSGI server that listens on the specified port (default is 8000)<br/>
|
|
62
|
+
and calls the application object with the environ.<br/>
|
|
63
|
+
You may also specify advanced options in <code>makeWSGIApp</code>:<br/>
|
|
64
|
+
- you can set the <code>advanced</code> parameter to <code>True</code>, so that your application method also gets an FieldStorage type object<br/>
|
|
65
|
+
- you can set the <code>setAdvancedHeaders</code> parameter to <code>True</code>, so that the application method is also able to set status codes and types in the response headers,<br/>
|
|
66
|
+
which is only possible if the <code>advanced</code> parameter is set to <code>True</code><br/>
|
|
67
|
+
Example:
|
|
68
|
+
```python
|
|
69
|
+
from PyWSGIRef import *
|
|
70
|
+
|
|
71
|
+
# Create a WSGI application object with advanced options
|
|
72
|
+
def advanced_app(path: str, form: FieldStorage) -> str, str, str:
|
|
73
|
+
# You can access form data here
|
|
74
|
+
name = str(form.getvalue('name'))
|
|
75
|
+
|
|
76
|
+
if path == "/hello":
|
|
77
|
+
return f"Hello, {name}, you visited {path}!", "text/html", "200 OK"
|
|
78
|
+
else:
|
|
79
|
+
return "Page not found", "text/html", "404 Not Found"
|
|
80
|
+
application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
|
|
81
|
+
|
|
82
|
+
# Create a WSGI server
|
|
83
|
+
server = setUpServer(application, port=8000)
|
|
84
|
+
server.serve_forever()
|
|
85
|
+
```
|
|
86
|
+
You can also use your own application object instead of the one created by <code>makeWSGIApp</code>.
|
|
87
|
+
### Loading PyHTML
|
|
88
|
+
PyWSGIRef also provides a simple way to load PyHTML files:
|
|
89
|
+
```python
|
|
90
|
+
from PyWSGIRef import *
|
|
91
|
+
|
|
92
|
+
# load from file
|
|
93
|
+
html = loadFromFile('index.pyhtml')
|
|
94
|
+
|
|
95
|
+
# load from web
|
|
96
|
+
html = loadFromWeb('https://example.com/index.pyhtml')
|
|
97
|
+
```
|
|
98
|
+
This is useful for serving dynamic HTML content in your WSGI application.<br/>
|
|
99
|
+
The funcs are callable unless you set up a server.<br/>
|
|
100
|
+
You can also add multiple PyHTML files from the web at the same time using the <code>multiWebInit</code> function.
|
|
101
|
+
### Using Templates
|
|
102
|
+
PyWSGIRef also provides a simple way to use templates in your WSGI application:
|
|
103
|
+
```python
|
|
104
|
+
from PyWSGIRef import *
|
|
105
|
+
|
|
106
|
+
# add template to template dictionary
|
|
107
|
+
# -> saves as PyHTML object
|
|
108
|
+
addSchablone("index", loadedPyHTMLFile)
|
|
109
|
+
|
|
110
|
+
# load template from dictionary
|
|
111
|
+
# get HTML code from PyHTML object
|
|
112
|
+
html = SCHABLONEN["index"].decoded()
|
|
113
|
+
# use Python formatting
|
|
114
|
+
serverPageContent = html.format("Hello, World!")
|
|
115
|
+
```
|
|
116
|
+
Note that you may only use the <code>addSchablone</code> function before you set up a server.
|
|
117
|
+
### Default HTML templates
|
|
118
|
+
PyWSGIRef comes with some default HTML templates that you can use in your WSGI application.<br/>
|
|
119
|
+
You can access them via the <code>PyWSGIRef.defaults</code>:
|
|
120
|
+
```python
|
|
121
|
+
from PyWSGIRef import *
|
|
122
|
+
|
|
123
|
+
# load default HTML template
|
|
124
|
+
addSchablone("hello", HELLO_WORLD)
|
|
125
|
+
addSchablone("error", ERROR)
|
|
126
|
+
```
|
|
127
|
+
### __main__ script
|
|
128
|
+
You may produce a simple WSGI server by using either:<br/>
|
|
129
|
+
```python
|
|
130
|
+
from PyWSGIRef import main
|
|
131
|
+
|
|
132
|
+
main()
|
|
133
|
+
```
|
|
134
|
+
or (from a commandline)
|
|
135
|
+
```bash
|
|
136
|
+
py -m PyWSGIRef
|
|
137
|
+
```
|
|
138
|
+
### Decoding PyHTML
|
|
139
|
+
(more coming soon...)<br/>
|
|
140
|
+
PyWSGIRef provides a simple way to shorten a common HTML beginning phrase in PyHTML:
|
|
141
|
+
```python
|
|
142
|
+
from PyWSGIRef import PyHTML
|
|
143
|
+
|
|
144
|
+
# Shorten HTML beginning phrase
|
|
145
|
+
pyhtml_ = """<{{evalPyHTML}}>
|
|
146
|
+
<title>My Page</title>
|
|
147
|
+
</head>
|
|
148
|
+
<body>
|
|
149
|
+
<h1>Hello, World!</h1>
|
|
150
|
+
</body>
|
|
151
|
+
</html>"""
|
|
152
|
+
pyhtml = PyHTML(pyhtml_)
|
|
153
|
+
html = pyhtml.decoded()
|
|
154
|
+
```
|
|
155
|
+
, which is actually automatically done by PyWSGIRef.<br/>
|
|
156
|
+
The <code><{{evalPyHTML}}></code> phrase at the beginning of the document includes a Doctype announcement,<br/>
|
|
157
|
+
a html and head block and some common meta phrases as utf-8 encoding or device-width scaling.<br/><br/>
|
|
158
|
+
PyWSGIRef also provides a simple way to end PyHTML files:<br/>
|
|
159
|
+
just use the <code><{{evalPyHTML}}></code> phrase at the end of the document and<br/>
|
|
160
|
+
PyWSGIRef will automatically add the closing html and body tags.<br/><br/>
|
|
161
|
+
You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
|
|
162
|
+
<code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.<br/><br/>
|
|
163
|
+
You may add your own static resources like CSS or JavaScript files using the <code><{{evalPyHTML-include: ... :include-}}></code> phrase.<br/>
|
|
164
|
+
Different static resources can be included by separating them with a comma.<br/>
|
|
165
|
+
You may include CSS, JS, JSON and ICO files.<br/><br/>
|
|
166
|
+
With the <code><{{evalPyHTML-script: alert('Hello, World!'); :script-}}></code> phrase,<br/>
|
|
167
|
+
you can add a script block anywhere inside your PyHTML file.<br/>
|
|
168
|
+
Using pretty much the same syntax, you can also add a style block using
|
|
169
|
+
<code><{{evalPyHTML-style: body { background-color: lightblue; } :style-}}></code>.
|
|
170
|
+
|
|
171
|
+
### Stats
|
|
172
|
+
Some stats are saved into the <code>STATS</code> object.<br/>
|
|
173
|
+
You may access them using the object itself or <code>STATS.export_stats()</code>.<br/>
|
|
174
|
+
The performance times of your application are collected there too.<br/>
|
|
175
|
+
|
|
176
|
+
### Shutting down your server
|
|
177
|
+
You can shut down your server by calling the <code>shutdown</code> method on the server object:
|
|
178
|
+
```python
|
|
179
|
+
from PyWSGIRef import *
|
|
180
|
+
|
|
181
|
+
# ...
|
|
182
|
+
# Create a WSGI server
|
|
183
|
+
server = setUpServer(application, port=8000)
|
|
184
|
+
|
|
185
|
+
# Shut down the server
|
|
186
|
+
server.shutdown()
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Others
|
|
190
|
+
Use the following to get information about your release and the author of the module:
|
|
191
|
+
```python
|
|
192
|
+
from PyWSGIRef import about
|
|
193
|
+
|
|
194
|
+
about()
|
|
195
|
+
```
|
|
196
|
+
### Curious?
|
|
197
|
+
Join the <b>BETA</b> group to get new features even earlier!<br/>
|
|
198
|
+
Note that BETA features may not be tested when using them.
|
|
199
|
+
```python
|
|
200
|
+
from PyWSGIRef import BETA
|
|
201
|
+
|
|
202
|
+
#enable beta mode
|
|
203
|
+
BETA.enable()
|
|
204
|
+
```
|
|
205
|
+
Currently to be tested are:<br/>
|
|
206
|
+
- PyHTML python script blocks<br/>
|
|
207
|
+
- PyHTML python if clause blocks<br/>
|
|
208
|
+
- PyHTML macros<br/><br/>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
Please report any bugs you find in the GitHub repository and suggest new features!<br/><br/>
|
|
212
|
+
|
|
213
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
214
|
+
### More coming soon
|