PyWSGIRef 1.1.18__tar.gz → 1.1.20__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.18/src/PyWSGIRef.egg-info → pywsgiref-1.1.20}/PKG-INFO +6 -2
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/README.md +5 -1
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/pyproject.toml +1 -1
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/__init__.py +25 -3
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/exceptions.py +8 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/pyhtml.py +14 -4
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/stats.py +4 -3
- {pywsgiref-1.1.18 → pywsgiref-1.1.20/src/PyWSGIRef.egg-info}/PKG-INFO +6 -2
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/LICENSE +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/setup.cfg +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/__main__.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/beta.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/commons.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/defaults.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/finished.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/loadContent.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/patterns.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/simpleServer.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef/templateDict.py +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef.egg-info/SOURCES.txt +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef.egg-info/requires.txt +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
- {pywsgiref-1.1.18 → pywsgiref-1.1.20}/tests/testMainServer.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyWSGIRef
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.20
|
|
4
4
|
Summary: easy server-setup
|
|
5
5
|
Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
@@ -96,7 +96,8 @@ html = loadFromFile('index.pyhtml')
|
|
|
96
96
|
html = loadFromWeb('https://example.com/index.pyhtml')
|
|
97
97
|
```
|
|
98
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
|
|
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.
|
|
100
101
|
### Using Templates
|
|
101
102
|
PyWSGIRef also provides a simple way to use templates in your WSGI application:
|
|
102
103
|
```python
|
|
@@ -200,5 +201,8 @@ Currently to be tested are:<br/>
|
|
|
200
201
|
- application object running time measuring<br/>
|
|
201
202
|
- application object counter of access<br/><br/>
|
|
202
203
|
|
|
204
|
+
|
|
205
|
+
Please report any bugs you find in the GitHub repository and suggest new features!<br/><br/>
|
|
206
|
+
|
|
203
207
|
Thanks a lot for helping improving PyWSGIRef!
|
|
204
208
|
### More coming soon
|
|
@@ -79,7 +79,8 @@ html = loadFromFile('index.pyhtml')
|
|
|
79
79
|
html = loadFromWeb('https://example.com/index.pyhtml')
|
|
80
80
|
```
|
|
81
81
|
This is useful for serving dynamic HTML content in your WSGI application.<br/>
|
|
82
|
-
The funcs are callable unless you set up a server
|
|
82
|
+
The funcs are callable unless you set up a server.<br/>
|
|
83
|
+
You can also add multiple PyHTML files from the web at the same time using the <code>multiWebInit</code> function.
|
|
83
84
|
### Using Templates
|
|
84
85
|
PyWSGIRef also provides a simple way to use templates in your WSGI application:
|
|
85
86
|
```python
|
|
@@ -183,5 +184,8 @@ Currently to be tested are:<br/>
|
|
|
183
184
|
- application object running time measuring<br/>
|
|
184
185
|
- application object counter of access<br/><br/>
|
|
185
186
|
|
|
187
|
+
|
|
188
|
+
Please report any bugs you find in the GitHub repository and suggest new features!<br/><br/>
|
|
189
|
+
|
|
186
190
|
Thanks a lot for helping improving PyWSGIRef!
|
|
187
191
|
### More coming soon
|
|
@@ -18,7 +18,7 @@ def about():
|
|
|
18
18
|
"""
|
|
19
19
|
Returns information about your release and other projects by Leander Kafemann
|
|
20
20
|
"""
|
|
21
|
-
return {"Version": (1, 1,
|
|
21
|
+
return {"Version": (1, 1, 20), "Author": "Leander Kafemann", "date": "26.08.2026",\
|
|
22
22
|
"recommend": ("pyimager"), "feedbackTo": "leander.kafemann+python@icloud.com"}
|
|
23
23
|
|
|
24
24
|
SCHABLONEN = TemplateDict()
|
|
@@ -33,6 +33,21 @@ def addSchablone(name: str, content: str):
|
|
|
33
33
|
raise ServerAlreadyGeneratedError()
|
|
34
34
|
SCHABLONEN[name] = PyHTML(content)
|
|
35
35
|
|
|
36
|
+
def multiWebInit(baseURL: str, templateNames: list[str], overrideException: bool = False) -> list[str]:
|
|
37
|
+
"""
|
|
38
|
+
Loads multiple templates from the web and adds them to the SCHABLONEN dictionary.
|
|
39
|
+
Returns a list of the names of the loaded templates.
|
|
40
|
+
"""
|
|
41
|
+
if finished.value and not overrideException:
|
|
42
|
+
raise ServerAlreadyGeneratedError()
|
|
43
|
+
loadedTemplates = []
|
|
44
|
+
for name in templateNames:
|
|
45
|
+
url = f"{baseURL}/{name}.pyhtml"
|
|
46
|
+
content = loadFromWeb(url, overrideException=overrideException)
|
|
47
|
+
addSchablone(name, content)
|
|
48
|
+
loadedTemplates.append(name)
|
|
49
|
+
return loadedTemplates
|
|
50
|
+
|
|
36
51
|
def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool = False, setAdvancedHeaders: bool = False,\
|
|
37
52
|
getIP: bool = False, vercelPythonHosting: bool = False, getStats: bool = False,
|
|
38
53
|
advancedStats: bool = False, customEncoding: bool = False) -> Callable:
|
|
@@ -51,6 +66,7 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
|
|
|
51
66
|
if not callable(contentGeneratingFunction):
|
|
52
67
|
raise InvalidCallableError()
|
|
53
68
|
BETA.lock()
|
|
69
|
+
|
|
54
70
|
def simpleApplication(environ, start_response) -> list:
|
|
55
71
|
"""
|
|
56
72
|
A simple WSGI application object that serves as a template.
|
|
@@ -61,8 +77,13 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
|
|
|
61
77
|
STATS.count.increase()
|
|
62
78
|
perfTime = STATS.startPerfTime("applicationCallNr"+str(STATS.count.count))
|
|
63
79
|
storage = FieldStorage(fp=environ.get("wsgi.input"), environ=environ, keep_blank_values=True)
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
try:
|
|
81
|
+
if storage.getvalue("realAccessDeviceMonitorAgent", "") not in ["PyWSGIRef/1.1", ""]:
|
|
82
|
+
raise OutdatedPyWSGIRefVersionError("Access with outdated PyWSGIRef version detected. Please update to the latest version.")
|
|
83
|
+
except TypeError:
|
|
84
|
+
pass
|
|
85
|
+
except:
|
|
86
|
+
raise InvalidEnvironError("Invalid WSGI environ and/or FieldStorage keys detected.")
|
|
66
87
|
type_ = "text/html"
|
|
67
88
|
status = "200 OK"
|
|
68
89
|
if advanced:
|
|
@@ -98,6 +119,7 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
|
|
|
98
119
|
else:
|
|
99
120
|
if customEncoding:
|
|
100
121
|
raise VercelIncompabilityError("customEncoding cannot be used with vercelPythonHosting.")
|
|
122
|
+
|
|
101
123
|
return simpleApplication
|
|
102
124
|
|
|
103
125
|
def setUpServer(application: Callable, port: int = 8000) -> WSGIServer:
|
|
@@ -100,5 +100,13 @@ class OutdatedPyWSGIRefVersionError(Exception):
|
|
|
100
100
|
Raised when the PyWSGIRef version is outdated and does not support a requested feature.
|
|
101
101
|
"""
|
|
102
102
|
def __init__(self, message="The PyWSGIRef version is outdated and does not support this feature."):
|
|
103
|
+
self.message = message
|
|
104
|
+
super().__init__(self.message)
|
|
105
|
+
|
|
106
|
+
class InvalidEnvironError(Exception):
|
|
107
|
+
"""
|
|
108
|
+
Raised when the WSGI environ is invalid or missing required keys.
|
|
109
|
+
"""
|
|
110
|
+
def __init__(self, message="Invalid WSGI environ."):
|
|
103
111
|
self.message = message
|
|
104
112
|
super().__init__(self.message)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import html
|
|
2
1
|
import re
|
|
3
2
|
from naturalsize import replStrPassage
|
|
4
3
|
|
|
@@ -62,21 +61,29 @@ class PyHTML:
|
|
|
62
61
|
"""
|
|
63
62
|
Replaces script replacement phrases with JS scripts.
|
|
64
63
|
"""
|
|
64
|
+
offset = 0
|
|
65
65
|
for match in re.finditer(SCRIPT_PATTERN, self.html, re.DOTALL):
|
|
66
66
|
idx, idxEnd = match.span()
|
|
67
|
+
idx += offset
|
|
68
|
+
idxEnd += offset
|
|
67
69
|
script_content = match.group(1).strip()
|
|
68
70
|
replacement = f"<script>{script_content}</script>"
|
|
69
71
|
self.html = self.html[:idx] + replacement + self.html[idxEnd:]
|
|
72
|
+
offset += len(replacement) - (idxEnd - idx)
|
|
70
73
|
|
|
71
74
|
def _replace_style_blocks(self):
|
|
72
75
|
"""
|
|
73
76
|
Replaces style replacement phrases with CSS styles.
|
|
74
77
|
"""
|
|
78
|
+
offset = 0
|
|
75
79
|
for match in re.finditer(STYLE_PATTERN, self.html, re.DOTALL):
|
|
76
80
|
idx, idxEnd = match.span()
|
|
81
|
+
idx += offset
|
|
82
|
+
idxEnd += offset
|
|
77
83
|
style_content = match.group(1).strip()
|
|
78
84
|
replacement = f"<style>{style_content}</style>"
|
|
79
85
|
self.html = self.html[:idx] + replacement + self.html[idxEnd:]
|
|
86
|
+
offset += len(replacement) - (idxEnd - idx)
|
|
80
87
|
|
|
81
88
|
def _replace_eval_blocks(self):
|
|
82
89
|
"""
|
|
@@ -85,23 +92,26 @@ class PyHTML:
|
|
|
85
92
|
"""
|
|
86
93
|
if self.context is None:
|
|
87
94
|
self.context = {}
|
|
95
|
+
offset = 0
|
|
88
96
|
for match in re.finditer(EVAL_BLOCK_PATTERN, self.html, re.DOTALL):
|
|
89
97
|
idx, idxEnd = match.span()
|
|
98
|
+
idx += offset
|
|
99
|
+
idxEnd += offset
|
|
90
100
|
code = match.group(1).strip()
|
|
91
101
|
try:
|
|
92
|
-
# eval f�r Ausdr�cke, exec f�r Statements
|
|
93
102
|
result = str(eval(code, {}, self.context))
|
|
94
103
|
except Exception as e:
|
|
95
104
|
result = f"<b>EvalError: {e}</b>"
|
|
96
105
|
self.html = self.html[:idx] + result + self.html[idxEnd:]
|
|
106
|
+
offset += len(result) - (idxEnd - idx)
|
|
97
107
|
|
|
98
108
|
def _replace_if_blocks(self, context=None):
|
|
99
109
|
"""
|
|
100
110
|
Replaces with html code based on the evaluation of conditions in if blocks.
|
|
101
111
|
"""
|
|
102
112
|
if context is None:
|
|
103
|
-
context = {}
|
|
104
|
-
|
|
113
|
+
context = self.context if self.context else {}
|
|
114
|
+
|
|
105
115
|
while True:
|
|
106
116
|
match = re.search(IF_BLOCK_PATTERN, self.html, re.DOTALL)
|
|
107
117
|
if not match:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import datetime
|
|
2
2
|
|
|
3
3
|
class PerformanceTime:
|
|
4
|
-
def __init__(self, title: str, data: dict =
|
|
4
|
+
def __init__(self, title: str, data: dict = None):
|
|
5
5
|
self.start = datetime.datetime.now()
|
|
6
6
|
self.title = title
|
|
7
|
-
self.data = data
|
|
7
|
+
self.data = data if data is not None else {}
|
|
8
8
|
def stop(self):
|
|
9
9
|
self.end = datetime.datetime.now()
|
|
10
10
|
|
|
@@ -56,7 +56,8 @@ class Stats:
|
|
|
56
56
|
lines.append(f" {i}. {title}: started at {start} (not stopped until now)")
|
|
57
57
|
else:
|
|
58
58
|
lines.append(f" {i}. {title}: (no time data)")
|
|
59
|
-
|
|
59
|
+
if perf.data:
|
|
60
|
+
lines[-1] = lines[-1] + " data: " + ", ".join(f"{k}={v}" for k, v in perf.data.items())
|
|
60
61
|
result = "\n".join(lines) if not html else "<br>".join(lines)
|
|
61
62
|
if filename:
|
|
62
63
|
if not filename.endswith(".pywsgirefstats"):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyWSGIRef
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.20
|
|
4
4
|
Summary: easy server-setup
|
|
5
5
|
Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
@@ -96,7 +96,8 @@ html = loadFromFile('index.pyhtml')
|
|
|
96
96
|
html = loadFromWeb('https://example.com/index.pyhtml')
|
|
97
97
|
```
|
|
98
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
|
|
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.
|
|
100
101
|
### Using Templates
|
|
101
102
|
PyWSGIRef also provides a simple way to use templates in your WSGI application:
|
|
102
103
|
```python
|
|
@@ -200,5 +201,8 @@ Currently to be tested are:<br/>
|
|
|
200
201
|
- application object running time measuring<br/>
|
|
201
202
|
- application object counter of access<br/><br/>
|
|
202
203
|
|
|
204
|
+
|
|
205
|
+
Please report any bugs you find in the GitHub repository and suggest new features!<br/><br/>
|
|
206
|
+
|
|
203
207
|
Thanks a lot for helping improving PyWSGIRef!
|
|
204
208
|
### More coming soon
|
|
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
|