PyWSGIRef 1.1.5__tar.gz → 1.1.7__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 (25) hide show
  1. {pywsgiref-1.1.5/src/PyWSGIRef.egg-info → pywsgiref-1.1.7}/PKG-INFO +22 -4
  2. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/README.md +21 -3
  3. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/pyproject.toml +1 -1
  4. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/__init__.py +3 -3
  5. pywsgiref-1.1.7/src/PyWSGIRef/defaults.py +42 -0
  6. pywsgiref-1.1.7/src/PyWSGIRef/patterns.py +9 -0
  7. pywsgiref-1.1.7/src/PyWSGIRef/pyhtml.py +96 -0
  8. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/simpleServer.py +3 -0
  9. {pywsgiref-1.1.5 → pywsgiref-1.1.7/src/PyWSGIRef.egg-info}/PKG-INFO +22 -4
  10. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef.egg-info/SOURCES.txt +1 -0
  11. pywsgiref-1.1.5/src/PyWSGIRef/defaults.py +0 -28
  12. pywsgiref-1.1.5/src/PyWSGIRef/pyhtml.py +0 -57
  13. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/LICENSE +0 -0
  14. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/setup.cfg +0 -0
  15. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/__main__.py +0 -0
  16. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/beta.py +0 -0
  17. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/commons.py +0 -0
  18. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/exceptions.py +0 -0
  19. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/finished.py +0 -0
  20. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/loadContent.py +0 -0
  21. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef/templateDict.py +0 -0
  22. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
  23. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef.egg-info/requires.txt +0 -0
  24. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
  25. {pywsgiref-1.1.5 → pywsgiref-1.1.7}/tests/testMainServer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.5
3
+ Version: 1.1.7
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
@@ -172,8 +189,9 @@ from PyWSGIRef import BETA
172
189
  BETA.enable()
173
190
  ```
174
191
  Currently to be tested are:<br/>
175
- - PyHTML include static resource blocks<br/>
176
- - PyHTML include default modern styling block<br/><br/>
192
+ - PyHTML style and script blocks<br/>
193
+ - PyHTML favicon support<br/>
194
+ - PyHTML include static resource blocks<br/><br/>
177
195
 
178
196
  Thanks a lot for helping improving PyWSGIRef!
179
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
@@ -154,8 +171,9 @@ from PyWSGIRef import BETA
154
171
  BETA.enable()
155
172
  ```
156
173
  Currently to be tested are:<br/>
157
- - PyHTML include static resource blocks<br/>
158
- - PyHTML include default modern styling block<br/><br/>
174
+ - PyHTML style and script blocks<br/>
175
+ - PyHTML favicon support<br/>
176
+ - PyHTML include static resource blocks<br/><br/>
159
177
 
160
178
  Thanks a lot for helping improving PyWSGIRef!
161
179
  ### More coming soon
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.5"
3
+ version = "1.1.7"
4
4
  authors = [
5
5
  {name="Leander Kafemann", email="leander@kafemann.berlin" },
6
6
  ]
@@ -8,7 +8,7 @@ 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, OneWayBoolean
11
+ from .templateDict import TemplateDict
12
12
  from .beta import BETA
13
13
  from .loadContent import *
14
14
  from .finished import finished
@@ -17,8 +17,8 @@ def about():
17
17
  """
18
18
  Returns information about your release and other projects by Leander Kafemann
19
19
  """
20
- return {"Version":(1, 1, 5), "Author":"Leander Kafemann", "date":"10.06.2025",\
21
- "recommend":("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
20
+ return {"Version": (1, 1, 7), "Author": "Leander Kafemann", "date": "12.06.2025",\
21
+ "recommend": ("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
22
22
 
23
23
  SCHABLONEN = TemplateDict()
24
24
 
@@ -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>"""
@@ -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,96 @@
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
+ Replaces script replacement phrases with JS scripts.
62
+ """
63
+ for match in re.finditer(SCRIPT_PATTERN, self.html, re.DOTALL):
64
+ idx, idxEnd = match.span()
65
+ script_content = match.group(1).strip()
66
+ replacement = f"<script>{script_content}</script>"
67
+ self.html = self.html[:idx] + replacement + self.html[idxEnd:]
68
+
69
+ def _replace_style_blocks(self):
70
+ """
71
+ Replaces style replacement phrases with CSS styles.
72
+ """
73
+ for match in re.finditer(STYLE_PATTERN, self.html, re.DOTALL):
74
+ idx, idxEnd = match.span()
75
+ style_content = match.group(1).strip()
76
+ replacement = f"<style>{style_content}</style>"
77
+ self.html = self.html[:idx] + replacement + self.html[idxEnd:]
78
+
79
+ def decode(self):
80
+ """
81
+ Decodes the HTML content by replacing specific phrases and applying modern styling.
82
+ """
83
+ self.html = self.html.strip()
84
+ self._replace_eval_phrase()
85
+ self._replace_modern_styling()
86
+ if BETA.value:
87
+ self._replace_includes()
88
+ self._replace_script_blocks()
89
+ self._replace_style_blocks()
90
+
91
+ def decoded(self) -> str:
92
+ """
93
+ Returns the decoded HTML content.
94
+ """
95
+ self.decode()
96
+ return self.html
@@ -21,6 +21,9 @@ def main():
21
21
  content = SCHABLONEN["main"].decoded().format(about()["Version"])
22
22
  case "/hello":
23
23
  content = HELLO_WORLD
24
+ case "/shutdown":
25
+ content = SHUTDOWN_HTML
26
+ server.shutdown()
24
27
  case _:
25
28
  content = ERROR
26
29
  return content
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.5
3
+ Version: 1.1.7
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
@@ -172,8 +189,9 @@ from PyWSGIRef import BETA
172
189
  BETA.enable()
173
190
  ```
174
191
  Currently to be tested are:<br/>
175
- - PyHTML include static resource blocks<br/>
176
- - PyHTML include default modern styling block<br/><br/>
192
+ - PyHTML style and script blocks<br/>
193
+ - PyHTML favicon support<br/>
194
+ - PyHTML include static resource blocks<br/><br/>
177
195
 
178
196
  Thanks a lot for helping improving PyWSGIRef!
179
197
  ### More coming soon
@@ -9,6 +9,7 @@ src/PyWSGIRef/defaults.py
9
9
  src/PyWSGIRef/exceptions.py
10
10
  src/PyWSGIRef/finished.py
11
11
  src/PyWSGIRef/loadContent.py
12
+ src/PyWSGIRef/patterns.py
12
13
  src/PyWSGIRef/pyhtml.py
13
14
  src/PyWSGIRef/simpleServer.py
14
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