PyWSGIRef 1.1.4__tar.gz → 1.1.6__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.4/src/PyWSGIRef.egg-info → pywsgiref-1.1.6}/PKG-INFO +25 -2
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/README.md +24 -1
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/pyproject.toml +1 -1
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/__init__.py +4 -4
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/beta.py +3 -1
- pywsgiref-1.1.6/src/PyWSGIRef/defaults.py +42 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/exceptions.py +16 -0
- pywsgiref-1.1.6/src/PyWSGIRef/finished.py +24 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/loadContent.py +1 -1
- pywsgiref-1.1.6/src/PyWSGIRef/patterns.py +9 -0
- pywsgiref-1.1.6/src/PyWSGIRef/pyhtml.py +98 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/simpleServer.py +3 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/templateDict.py +2 -18
- {pywsgiref-1.1.4 → pywsgiref-1.1.6/src/PyWSGIRef.egg-info}/PKG-INFO +25 -2
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef.egg-info/SOURCES.txt +2 -0
- pywsgiref-1.1.4/src/PyWSGIRef/defaults.py +0 -28
- pywsgiref-1.1.4/src/PyWSGIRef/pyhtml.py +0 -57
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/LICENSE +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/setup.cfg +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/__main__.py +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef/commons.py +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef.egg-info/requires.txt +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
- {pywsgiref-1.1.4 → pywsgiref-1.1.6}/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.6
|
|
4
4
|
Summary: easy server-setup
|
|
5
5
|
Author-email: Leander Kafemann <leander@kafemann.berlin>
|
|
6
6
|
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
@@ -154,7 +154,24 @@ html = pyhtml.decoded()
|
|
|
154
154
|
```
|
|
155
155
|
, which is actually automatically done by PyWSGIRef.<br/>
|
|
156
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
|
|
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.
|
|
163
|
+
### Shutting down your server
|
|
164
|
+
You can shut down your server by calling the <code>shutdown</code> method on the server object:
|
|
165
|
+
```python
|
|
166
|
+
from PyWSGIRef import *
|
|
167
|
+
|
|
168
|
+
# ...
|
|
169
|
+
# Create a WSGI server
|
|
170
|
+
server = setUpServer(application, port=8000)
|
|
171
|
+
|
|
172
|
+
# Shut down the server
|
|
173
|
+
server.shutdown()
|
|
174
|
+
```
|
|
158
175
|
### Others
|
|
159
176
|
Use the following to get information about your release and the author of the module:
|
|
160
177
|
```python
|
|
@@ -171,4 +188,10 @@ from PyWSGIRef import BETA
|
|
|
171
188
|
#enable beta mode
|
|
172
189
|
BETA.enable()
|
|
173
190
|
```
|
|
191
|
+
Currently to be tested are:<br/>
|
|
192
|
+
- PyHTML style and script blocks<br/>
|
|
193
|
+
- PyHTML favicon support<br/>
|
|
194
|
+
- PyHTML include static resource blocks<br/><br/>
|
|
195
|
+
|
|
196
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
174
197
|
### More coming soon
|
|
@@ -136,7 +136,24 @@ html = pyhtml.decoded()
|
|
|
136
136
|
```
|
|
137
137
|
, which is actually automatically done by PyWSGIRef.<br/>
|
|
138
138
|
The <code><{{evalPyHTML}}></code> phrase at the beginning of the document includes a Doctype announcement,<br/>
|
|
139
|
-
a html and head block and some common meta phrases as utf-8 encoding or device-width scaling
|
|
139
|
+
a html and head block and some common meta phrases as utf-8 encoding or device-width scaling.<br/><br/>
|
|
140
|
+
PyWSGIRef also provides a simple way to end PyHTML files:<br/>
|
|
141
|
+
just use the <code><{{evalPyHTML}}></code> phrase at the end of the document and<br/>
|
|
142
|
+
PyWSGIRef will automatically add the closing html and body tags.<br/><br/>
|
|
143
|
+
You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
|
|
144
|
+
<code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.
|
|
145
|
+
### Shutting down your server
|
|
146
|
+
You can shut down your server by calling the <code>shutdown</code> method on the server object:
|
|
147
|
+
```python
|
|
148
|
+
from PyWSGIRef import *
|
|
149
|
+
|
|
150
|
+
# ...
|
|
151
|
+
# Create a WSGI server
|
|
152
|
+
server = setUpServer(application, port=8000)
|
|
153
|
+
|
|
154
|
+
# Shut down the server
|
|
155
|
+
server.shutdown()
|
|
156
|
+
```
|
|
140
157
|
### Others
|
|
141
158
|
Use the following to get information about your release and the author of the module:
|
|
142
159
|
```python
|
|
@@ -153,4 +170,10 @@ from PyWSGIRef import BETA
|
|
|
153
170
|
#enable beta mode
|
|
154
171
|
BETA.enable()
|
|
155
172
|
```
|
|
173
|
+
Currently to be tested are:<br/>
|
|
174
|
+
- PyHTML style and script blocks<br/>
|
|
175
|
+
- PyHTML favicon support<br/>
|
|
176
|
+
- PyHTML include static resource blocks<br/><br/>
|
|
177
|
+
|
|
178
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
156
179
|
### More coming soon
|
|
@@ -8,19 +8,19 @@ from cgi import FieldStorage
|
|
|
8
8
|
from .exceptions import *
|
|
9
9
|
from .pyhtml import PyHTML
|
|
10
10
|
from .defaults import *
|
|
11
|
-
from .templateDict import TemplateDict
|
|
11
|
+
from .templateDict import TemplateDict
|
|
12
12
|
from .beta import BETA
|
|
13
13
|
from .loadContent import *
|
|
14
|
+
from .finished import finished
|
|
14
15
|
|
|
15
16
|
def about():
|
|
16
17
|
"""
|
|
17
|
-
Returns information about your release and other projects by
|
|
18
|
+
Returns information about your release and other projects by Leander Kafemann
|
|
18
19
|
"""
|
|
19
|
-
return {"Version":(1, 1,
|
|
20
|
+
return {"Version":(1, 1, 6), "Author":"Leander Kafemann", "date":"12.06.2025",\
|
|
20
21
|
"recommend":("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
|
|
21
22
|
|
|
22
23
|
SCHABLONEN = TemplateDict()
|
|
23
|
-
finished = OneWayBoolean()
|
|
24
24
|
|
|
25
25
|
def addSchablone(name: str, content: str):
|
|
26
26
|
"""
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
BETA mode...
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
from .exceptions import BetaAlreadyEnabledError
|
|
6
|
+
|
|
5
7
|
class beta:
|
|
6
8
|
"""
|
|
7
9
|
BETA mode for PyWSGIRef.
|
|
@@ -18,7 +20,7 @@ class beta:
|
|
|
18
20
|
Enables BETA mode.
|
|
19
21
|
"""
|
|
20
22
|
if self._beta:
|
|
21
|
-
raise
|
|
23
|
+
raise BetaAlreadyEnabledError()
|
|
22
24
|
self._beta = True
|
|
23
25
|
|
|
24
26
|
BETA = beta()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
HELLO_WORLD = """<!DOCTYPE html>
|
|
2
|
+
<html lang"de">
|
|
3
|
+
<body>
|
|
4
|
+
<h1>Hallo Welt!</h1>
|
|
5
|
+
</body>
|
|
6
|
+
<html>"""
|
|
7
|
+
|
|
8
|
+
ERROR = """<!DOCTYPE html>
|
|
9
|
+
<html lang"de">
|
|
10
|
+
<body>
|
|
11
|
+
<h1>Fehler!</h1>
|
|
12
|
+
<p>Es ist ein Fehler aufgetreten.</p>
|
|
13
|
+
</body>
|
|
14
|
+
</html>"""
|
|
15
|
+
|
|
16
|
+
MAIN_HTML = """<!DOCTYPE html>
|
|
17
|
+
<html lang="de">
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="UTF-8" />
|
|
20
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
21
|
+
<title>PyWSGIRef Server</title>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<h1>Willkommen zum PyWSGIRef Server!</h1>
|
|
25
|
+
<p>Dies ist die Hauptseite des Servers.</p>
|
|
26
|
+
<p>Sie nutzen Version {} von PyWSGIRef.</p>
|
|
27
|
+
</body>
|
|
28
|
+
</html>"""
|
|
29
|
+
|
|
30
|
+
SHUTDOWN_HTML = """<!DOCTYPE html>
|
|
31
|
+
<html lang="de">
|
|
32
|
+
<head>
|
|
33
|
+
<meta charset="UTF-8" />
|
|
34
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
35
|
+
<title>Server Shutdown</title>
|
|
36
|
+
<body>
|
|
37
|
+
<h1>Server Shutdown</h1>
|
|
38
|
+
<p>
|
|
39
|
+
Der Server wird jetzt heruntergefahren.
|
|
40
|
+
</p>
|
|
41
|
+
</body>
|
|
42
|
+
</html>"""
|
|
@@ -44,5 +44,21 @@ class StaticResourceUsageOutsideHeadError(Exception):
|
|
|
44
44
|
Raised when a static resource is tried to include outside the head term of a PyHTML file.
|
|
45
45
|
"""
|
|
46
46
|
def __init__(self, message="Static resource usage out of <head> term detected."):
|
|
47
|
+
self.message = message
|
|
48
|
+
super().__init__(self.message)
|
|
49
|
+
|
|
50
|
+
class BooleanAlreadyTrueError(Exception):
|
|
51
|
+
"""
|
|
52
|
+
Raised when trying to set a boolean that is already True.
|
|
53
|
+
"""
|
|
54
|
+
def __init__(self, message="Boolean value is already True."):
|
|
55
|
+
self.message = message
|
|
56
|
+
super().__init__(self.message)#
|
|
57
|
+
|
|
58
|
+
class BetaAlreadyEnabledError(BooleanAlreadyTrueError):
|
|
59
|
+
"""
|
|
60
|
+
Raised when trying to enable beta mode that is already enabled.
|
|
61
|
+
"""
|
|
62
|
+
def __init__(self, message="Beta mode is already enabled."):
|
|
47
63
|
self.message = message
|
|
48
64
|
super().__init__(self.message)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Creates finished object to indicate if the server has been generated.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .exceptions import BooleanAlreadyTrueError
|
|
6
|
+
|
|
7
|
+
class OneWayBoolean:
|
|
8
|
+
def __init__(self):
|
|
9
|
+
self._value = False
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def value(self) -> bool:
|
|
13
|
+
return self._value
|
|
14
|
+
|
|
15
|
+
def set_true(self):
|
|
16
|
+
"""
|
|
17
|
+
Setzt den Wert auf True, wenn er False ist.
|
|
18
|
+
"""
|
|
19
|
+
if not self._value:
|
|
20
|
+
self._value = True
|
|
21
|
+
else:
|
|
22
|
+
raise BooleanAlreadyTrueError()
|
|
23
|
+
|
|
24
|
+
finished = OneWayBoolean()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
EVAL_PYHTML = "<{{evalPyHTML}}>"
|
|
2
|
+
|
|
3
|
+
MODERN_STYLING_PHRASE = "<{{evalPyHTML-modernStyling: true}}>"
|
|
4
|
+
|
|
5
|
+
INCLUDE_PATTERN = r"<\{\{evalPyHTML-include: (.*?) :include-\}\}\>"
|
|
6
|
+
|
|
7
|
+
SCRIPT_PATTERN = r"<\{\{evalPyHTML-script: (.*?) :script-\}\}\>"
|
|
8
|
+
|
|
9
|
+
STYLE_PATTERN = r"<\{\{evalPyHTML-style: (.*?) :style-\}\}\>"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from naturalsize import replStrPassage
|
|
3
|
+
|
|
4
|
+
from .defaults import HELLO_WORLD as DEFAULT
|
|
5
|
+
from .commons import *
|
|
6
|
+
from .exceptions import InvalidIncludePhraseFiletypeError, StaticResourceUsageOutsideHeadError
|
|
7
|
+
from .beta import BETA
|
|
8
|
+
from .patterns import *
|
|
9
|
+
|
|
10
|
+
class PyHTML:
|
|
11
|
+
def __init__(self, html: str = DEFAULT):
|
|
12
|
+
self.html = html
|
|
13
|
+
|
|
14
|
+
def _replace_eval_phrase(self):
|
|
15
|
+
"""
|
|
16
|
+
Scans the HTML for the evalPyHTML phrase and replaces it with the appropriate start and end phrases.
|
|
17
|
+
"""
|
|
18
|
+
if self.html.startswith(EVAL_PYHTML):
|
|
19
|
+
self.html = START_REPLACE + self.html[len(EVAL_PYHTML):]
|
|
20
|
+
if self.html.endswith(EVAL_PYHTML):
|
|
21
|
+
self.html = self.html[:-len(EVAL_PYHTML)] + END_REPLACE
|
|
22
|
+
|
|
23
|
+
def _replace_modern_styling(self):
|
|
24
|
+
"""
|
|
25
|
+
Scans the HTML for the modern styling phrase and replaces it with the appropriate CSS.
|
|
26
|
+
"""
|
|
27
|
+
idx = self.html.find(MODERN_STYLING_PHRASE)
|
|
28
|
+
if idx != -1:
|
|
29
|
+
head_idx = self.html.find("</head>")
|
|
30
|
+
if idx > head_idx:
|
|
31
|
+
raise StaticResourceUsageOutsideHeadError()
|
|
32
|
+
self.html = replStrPassage(idx, idx+len(MODERN_STYLING_PHRASE), self.html, MODERN_STYLING)
|
|
33
|
+
|
|
34
|
+
def _replace_includes(self):
|
|
35
|
+
"""
|
|
36
|
+
Scans the HTML for include phrases and replaces them with the appropriate resources.
|
|
37
|
+
"""
|
|
38
|
+
for match in re.finditer(INCLUDE_PATTERN, self.html):
|
|
39
|
+
idx, idxEnd = match.span()
|
|
40
|
+
head_idx = self.html.find("</head>")
|
|
41
|
+
if idx > head_idx:
|
|
42
|
+
raise StaticResourceUsageOutsideHeadError()
|
|
43
|
+
resources = match.group(1).split(",")
|
|
44
|
+
setIn = ""
|
|
45
|
+
for i in resources:
|
|
46
|
+
i = i.strip()
|
|
47
|
+
if i.endswith(".css"):
|
|
48
|
+
setIn += f"\t\t<link rel='stylesheet' href='{i}'/>\n"
|
|
49
|
+
elif i.endswith(".js"):
|
|
50
|
+
setIn += f"\t\t<script src='{i}'></script>\n"
|
|
51
|
+
elif i.endswith(".json"):
|
|
52
|
+
setIn += f"\t\t<link rel='manifest' href='{i}'/>\n"
|
|
53
|
+
elif i.endswith("favicon.ico"):
|
|
54
|
+
setIn += f"\t\t<link rel='icon' href='{i}'/>\n"
|
|
55
|
+
else:
|
|
56
|
+
raise InvalidIncludePhraseFiletypeError()
|
|
57
|
+
self.html = self.html[:idx] + setIn + self.html[idxEnd:]
|
|
58
|
+
|
|
59
|
+
def _replace_script_blocks(self):
|
|
60
|
+
"""
|
|
61
|
+
Sucht nach evalPyHTML-script Phrasen und ersetzt sie durch <script>-Bl�cke.
|
|
62
|
+
Nur im BETA-Modus aktiv.
|
|
63
|
+
"""
|
|
64
|
+
for match in re.finditer(SCRIPT_PATTERN, self.html, re.DOTALL):
|
|
65
|
+
idx, idxEnd = match.span()
|
|
66
|
+
script_content = match.group(1).strip()
|
|
67
|
+
replacement = f"<script>{script_content}</script>"
|
|
68
|
+
self.html = self.html[:idx] + replacement + self.html[idxEnd:]
|
|
69
|
+
|
|
70
|
+
def _replace_style_blocks(self):
|
|
71
|
+
"""
|
|
72
|
+
Sucht nach evalPyHTML-style Phrasen und ersetzt sie durch <style>-Bl�cke.
|
|
73
|
+
Nur im BETA-Modus aktiv.
|
|
74
|
+
"""
|
|
75
|
+
for match in re.finditer(STYLE_PATTERN, self.html, re.DOTALL):
|
|
76
|
+
idx, idxEnd = match.span()
|
|
77
|
+
style_content = match.group(1).strip()
|
|
78
|
+
replacement = f"<style>{style_content}</style>"
|
|
79
|
+
self.html = self.html[:idx] + replacement + self.html[idxEnd:]
|
|
80
|
+
|
|
81
|
+
def decode(self):
|
|
82
|
+
"""
|
|
83
|
+
Decodes the HTML content by replacing specific phrases and applying modern styling.
|
|
84
|
+
"""
|
|
85
|
+
self.html = self.html.strip()
|
|
86
|
+
self._replace_eval_phrase()
|
|
87
|
+
self._replace_modern_styling()
|
|
88
|
+
if BETA.value:
|
|
89
|
+
self._replace_includes()
|
|
90
|
+
self._replace_script_blocks()
|
|
91
|
+
self._replace_style_blocks()
|
|
92
|
+
|
|
93
|
+
def decoded(self) -> str:
|
|
94
|
+
"""
|
|
95
|
+
Returns the decoded HTML content.
|
|
96
|
+
"""
|
|
97
|
+
self.decode()
|
|
98
|
+
return self.html
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from .exceptions import ServerAlreadyGeneratedError
|
|
2
2
|
from .pyhtml import PyHTML
|
|
3
|
+
from .finished import OneWayBoolean
|
|
3
4
|
|
|
4
5
|
class TemplateDict:
|
|
5
6
|
def __init__(self):
|
|
@@ -31,21 +32,4 @@ class TemplateDict:
|
|
|
31
32
|
return list(self.dictionary.values())
|
|
32
33
|
|
|
33
34
|
def items(self) -> list:
|
|
34
|
-
return list(self.dictionary.items())
|
|
35
|
-
|
|
36
|
-
class OneWayBoolean:
|
|
37
|
-
def __init__(self):
|
|
38
|
-
self._value = False
|
|
39
|
-
|
|
40
|
-
@property
|
|
41
|
-
def value(self) -> bool:
|
|
42
|
-
return self._value
|
|
43
|
-
|
|
44
|
-
def set_true(self):
|
|
45
|
-
"""
|
|
46
|
-
Setzt den Wert auf True, wenn er False ist.
|
|
47
|
-
"""
|
|
48
|
-
if not self._value:
|
|
49
|
-
self._value = True
|
|
50
|
-
else:
|
|
51
|
-
raise ValueError("Value is already True, cannot set again.")
|
|
35
|
+
return list(self.dictionary.items())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyWSGIRef
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: easy server-setup
|
|
5
5
|
Author-email: Leander Kafemann <leander@kafemann.berlin>
|
|
6
6
|
Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
|
|
@@ -154,7 +154,24 @@ html = pyhtml.decoded()
|
|
|
154
154
|
```
|
|
155
155
|
, which is actually automatically done by PyWSGIRef.<br/>
|
|
156
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
|
|
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.
|
|
163
|
+
### Shutting down your server
|
|
164
|
+
You can shut down your server by calling the <code>shutdown</code> method on the server object:
|
|
165
|
+
```python
|
|
166
|
+
from PyWSGIRef import *
|
|
167
|
+
|
|
168
|
+
# ...
|
|
169
|
+
# Create a WSGI server
|
|
170
|
+
server = setUpServer(application, port=8000)
|
|
171
|
+
|
|
172
|
+
# Shut down the server
|
|
173
|
+
server.shutdown()
|
|
174
|
+
```
|
|
158
175
|
### Others
|
|
159
176
|
Use the following to get information about your release and the author of the module:
|
|
160
177
|
```python
|
|
@@ -171,4 +188,10 @@ from PyWSGIRef import BETA
|
|
|
171
188
|
#enable beta mode
|
|
172
189
|
BETA.enable()
|
|
173
190
|
```
|
|
191
|
+
Currently to be tested are:<br/>
|
|
192
|
+
- PyHTML style and script blocks<br/>
|
|
193
|
+
- PyHTML favicon support<br/>
|
|
194
|
+
- PyHTML include static resource blocks<br/><br/>
|
|
195
|
+
|
|
196
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
174
197
|
### More coming soon
|
|
@@ -7,7 +7,9 @@ src/PyWSGIRef/beta.py
|
|
|
7
7
|
src/PyWSGIRef/commons.py
|
|
8
8
|
src/PyWSGIRef/defaults.py
|
|
9
9
|
src/PyWSGIRef/exceptions.py
|
|
10
|
+
src/PyWSGIRef/finished.py
|
|
10
11
|
src/PyWSGIRef/loadContent.py
|
|
12
|
+
src/PyWSGIRef/patterns.py
|
|
11
13
|
src/PyWSGIRef/pyhtml.py
|
|
12
14
|
src/PyWSGIRef/simpleServer.py
|
|
13
15
|
src/PyWSGIRef/templateDict.py
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
HELLO_WORLD = """<!DOCTYPE html>
|
|
2
|
-
<html lang"de">
|
|
3
|
-
<body>
|
|
4
|
-
<h1>Hallo Welt!</h1>
|
|
5
|
-
</body>
|
|
6
|
-
<html>"""
|
|
7
|
-
|
|
8
|
-
ERROR = """<!DOCTYPE html>
|
|
9
|
-
<html lang"de">
|
|
10
|
-
<body>
|
|
11
|
-
<h1>Fehler!</h1>
|
|
12
|
-
<p>Es ist ein Fehler aufgetreten.</p>
|
|
13
|
-
</body>
|
|
14
|
-
</html>"""
|
|
15
|
-
|
|
16
|
-
MAIN_HTML = """<!DOCTYPE html>
|
|
17
|
-
<html lang="de">
|
|
18
|
-
<head>
|
|
19
|
-
<meta charset="UTF-8">
|
|
20
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
21
|
-
<title>PyWSGIRef Server</title>
|
|
22
|
-
</head>
|
|
23
|
-
<body>
|
|
24
|
-
<h1>Willkommen zum PyWSGIRef Server!</h1>
|
|
25
|
-
<p>Dies ist die Hauptseite des Servers.</p>
|
|
26
|
-
<p>Sie nutzen Version {} von PyWSGIRef.</p>
|
|
27
|
-
</body>
|
|
28
|
-
</html>"""
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from naturalsize import replStrPassage
|
|
2
|
-
|
|
3
|
-
from .defaults import HELLO_WORLD as DEFAULT
|
|
4
|
-
from .commons import *
|
|
5
|
-
from .exceptions import InvalidIncludePhraseFiletypeError, StaticResourceUsageOutsideHeadError
|
|
6
|
-
from .beta import BETA
|
|
7
|
-
|
|
8
|
-
class PyHTML:
|
|
9
|
-
def __init__(self, html: str = DEFAULT):
|
|
10
|
-
self.html = html
|
|
11
|
-
|
|
12
|
-
def decode(self):
|
|
13
|
-
"""
|
|
14
|
-
Decodes the HTML content.
|
|
15
|
-
"""
|
|
16
|
-
self.html = self.html.strip()
|
|
17
|
-
|
|
18
|
-
# common html beginning phrase
|
|
19
|
-
if self.html.startswith("<{{evalPyHTML}}>"):
|
|
20
|
-
self.html = START_REPLACE + self.html[16:]
|
|
21
|
-
|
|
22
|
-
# common html ending phrase
|
|
23
|
-
if self.html.endswith("<{{evalPyHTML}}>"):
|
|
24
|
-
self.html = self.html[:-16] + END_REPLACE
|
|
25
|
-
|
|
26
|
-
if BETA.value:
|
|
27
|
-
# static ressources
|
|
28
|
-
idx = self.html.find("<{{evalPyHTML-include: ")
|
|
29
|
-
if idx != -1:
|
|
30
|
-
idxEnd = self.html.find(" :include-}}>", idx)
|
|
31
|
-
if idxEnd > self.html.find("</head>"):
|
|
32
|
-
raise StaticResourceUsageOutsideHeadError()
|
|
33
|
-
setIn = ""
|
|
34
|
-
for i in self.html[idx:idxEnd+12].split(":")[1].strip().split(","):
|
|
35
|
-
if i.endswith(".css"):
|
|
36
|
-
setIn += "\t\t<link rel='stylesheet' href='{}'/>\n".format(i)
|
|
37
|
-
elif i.endswith(".js"):
|
|
38
|
-
setIn += "\t\t<script src='{}'></script>\n".format(i)
|
|
39
|
-
elif i.endswith(".json"):
|
|
40
|
-
setIn += "\t\t<link rel='manifest' href='{}'/>\n".format(i)
|
|
41
|
-
else:
|
|
42
|
-
raise InvalidIncludePhraseFiletypeError()
|
|
43
|
-
self.html = replStrPassage(idx, idxEnd+12, self.html, setIn)
|
|
44
|
-
|
|
45
|
-
# PyWSGIRef's styling
|
|
46
|
-
idx = self.html.find("<{{evalPyHTML-modernStyling: true}}>")
|
|
47
|
-
if idx != -1:
|
|
48
|
-
if idx > self.html.find("</head>"):
|
|
49
|
-
raise StaticResourceUsageOutsideHeadError()
|
|
50
|
-
self.html = replStrPassage(idx, idx+35, self.html, MODERN_STYLING)
|
|
51
|
-
|
|
52
|
-
def decoded(self) -> str:
|
|
53
|
-
"""
|
|
54
|
-
Returns the decoded HTML content.
|
|
55
|
-
"""
|
|
56
|
-
self.decode()
|
|
57
|
-
return self.html
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|