PyWSGIRef 1.1.3__tar.gz → 1.1.5__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.3/src/PyWSGIRef.egg-info → pywsgiref-1.1.5}/PKG-INFO +6 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/README.md +5 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/pyproject.toml +1 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/__init__.py +5 -61
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/__main__.py +1 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/beta.py +3 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/exceptions.py +16 -0
- pywsgiref-1.1.5/src/PyWSGIRef/finished.py +24 -0
- pywsgiref-1.1.5/src/PyWSGIRef/loadContent.py +30 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/pyhtml.py +5 -2
- pywsgiref-1.1.5/src/PyWSGIRef/simpleServer.py +38 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/templateDict.py +2 -18
- {pywsgiref-1.1.3 → pywsgiref-1.1.5/src/PyWSGIRef.egg-info}/PKG-INFO +6 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef.egg-info/SOURCES.txt +3 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/LICENSE +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/setup.cfg +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/commons.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef/defaults.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef.egg-info/requires.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.5}/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.5
|
|
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
|
|
@@ -171,4 +171,9 @@ from PyWSGIRef import BETA
|
|
|
171
171
|
#enable beta mode
|
|
172
172
|
BETA.enable()
|
|
173
173
|
```
|
|
174
|
+
Currently to be tested are:<br/>
|
|
175
|
+
- PyHTML include static resource blocks<br/>
|
|
176
|
+
- PyHTML include default modern styling block<br/><br/>
|
|
177
|
+
|
|
178
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
174
179
|
### More coming soon
|
|
@@ -153,4 +153,9 @@ from PyWSGIRef import BETA
|
|
|
153
153
|
#enable beta mode
|
|
154
154
|
BETA.enable()
|
|
155
155
|
```
|
|
156
|
+
Currently to be tested are:<br/>
|
|
157
|
+
- PyHTML include static resource blocks<br/>
|
|
158
|
+
- PyHTML include default modern styling block<br/><br/>
|
|
159
|
+
|
|
160
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
156
161
|
### More coming soon
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
PYWSGIREF
|
|
3
3
|
"""
|
|
4
4
|
from typing import Callable
|
|
5
|
-
import requests
|
|
6
5
|
from wsgiref.simple_server import make_server, WSGIServer
|
|
7
6
|
from cgi import FieldStorage
|
|
8
7
|
|
|
@@ -11,39 +10,17 @@ from .pyhtml import PyHTML
|
|
|
11
10
|
from .defaults import *
|
|
12
11
|
from .templateDict import TemplateDict, OneWayBoolean
|
|
13
12
|
from .beta import BETA
|
|
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, 5), "Author":"Leander Kafemann", "date":"10.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
|
-
|
|
25
|
-
def loadFromWeb(url: str, data: dict = {}) -> str:
|
|
26
|
-
"""
|
|
27
|
-
Loads content from the given URL with the given data.
|
|
28
|
-
"""
|
|
29
|
-
if finished.value:
|
|
30
|
-
raise ServerAlreadyGeneratedError()
|
|
31
|
-
if not url.endswith(".pyhtml"):
|
|
32
|
-
raise InvalidFiletypeError()
|
|
33
|
-
rq = requests.post(url, data).content
|
|
34
|
-
return rq.decode()
|
|
35
|
-
|
|
36
|
-
def loadFromFile(filename: str) -> str:
|
|
37
|
-
"""
|
|
38
|
-
Loads a file from the given filename.
|
|
39
|
-
"""
|
|
40
|
-
if finished.value:
|
|
41
|
-
raise ServerAlreadyGeneratedError()
|
|
42
|
-
if not filename.endswith(".pyhtml"):
|
|
43
|
-
raise InvalidFiletypeError()
|
|
44
|
-
with open(filename, "r", encoding="utf-8") as f:
|
|
45
|
-
content = f.read()
|
|
46
|
-
return content
|
|
47
24
|
|
|
48
25
|
def addSchablone(name: str, content: str):
|
|
49
26
|
"""
|
|
@@ -93,37 +70,4 @@ def setUpServer(application: Callable, port: int = 8000) -> WSGIServer:
|
|
|
93
70
|
"""
|
|
94
71
|
finished.set_true()
|
|
95
72
|
server = make_server('', 8000, application)
|
|
96
|
-
return server
|
|
97
|
-
|
|
98
|
-
def main():
|
|
99
|
-
"""
|
|
100
|
-
Main function to set up and run the PyWSGIRef server.
|
|
101
|
-
"""
|
|
102
|
-
# add Schablone 'Hallo Welt' as main
|
|
103
|
-
addSchablone("main", MAIN_HTML)
|
|
104
|
-
|
|
105
|
-
# set up application object
|
|
106
|
-
def contentGenerator(path: str) -> str:
|
|
107
|
-
"""
|
|
108
|
-
Serves as the main WSGI application.
|
|
109
|
-
"""
|
|
110
|
-
match path:
|
|
111
|
-
case "/":
|
|
112
|
-
content = SCHABLONEN["main"].decoded().format(about()["Version"])
|
|
113
|
-
case "/hello":
|
|
114
|
-
content = HELLO_WORLD
|
|
115
|
-
case _:
|
|
116
|
-
content = ERROR
|
|
117
|
-
return content
|
|
118
|
-
|
|
119
|
-
# make the application object
|
|
120
|
-
application = makeApplicationObject(contentGenerator)
|
|
121
|
-
|
|
122
|
-
# set up server
|
|
123
|
-
server = setUpServer(application)
|
|
124
|
-
|
|
125
|
-
# Note: This code is intended to be run as a script, not as a module.
|
|
126
|
-
print("Successfully started WSGI server on port 8000.")
|
|
127
|
-
|
|
128
|
-
# start serving
|
|
129
|
-
server.serve_forever()
|
|
73
|
+
return server
|
|
@@ -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()
|
|
@@ -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,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Content loading helper.
|
|
3
|
+
"""
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
from .exceptions import *
|
|
7
|
+
from .finished import finished
|
|
8
|
+
|
|
9
|
+
def loadFromWeb(url: str, data: dict = {}) -> str:
|
|
10
|
+
"""
|
|
11
|
+
Loads content from the given URL with the given data.
|
|
12
|
+
"""
|
|
13
|
+
if finished.value:
|
|
14
|
+
raise ServerAlreadyGeneratedError()
|
|
15
|
+
if not url.endswith(".pyhtml"):
|
|
16
|
+
raise InvalidFiletypeError()
|
|
17
|
+
rq = requests.post(url, data).content
|
|
18
|
+
return rq.decode()
|
|
19
|
+
|
|
20
|
+
def loadFromFile(filename: str) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Loads a file from the given filename.
|
|
23
|
+
"""
|
|
24
|
+
if finished.value:
|
|
25
|
+
raise ServerAlreadyGeneratedError()
|
|
26
|
+
if not filename.endswith(".pyhtml"):
|
|
27
|
+
raise InvalidFiletypeError()
|
|
28
|
+
with open(filename, "r", encoding="utf-8") as f:
|
|
29
|
+
content = f.read()
|
|
30
|
+
return content
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from naturalsize import
|
|
1
|
+
from naturalsize import replStrPassage
|
|
2
2
|
|
|
3
3
|
from .defaults import HELLO_WORLD as DEFAULT
|
|
4
4
|
from .commons import *
|
|
@@ -8,6 +8,7 @@ from .beta import BETA
|
|
|
8
8
|
class PyHTML:
|
|
9
9
|
def __init__(self, html: str = DEFAULT):
|
|
10
10
|
self.html = html
|
|
11
|
+
|
|
11
12
|
def decode(self):
|
|
12
13
|
"""
|
|
13
14
|
Decodes the HTML content.
|
|
@@ -22,7 +23,7 @@ class PyHTML:
|
|
|
22
23
|
if self.html.endswith("<{{evalPyHTML}}>"):
|
|
23
24
|
self.html = self.html[:-16] + END_REPLACE
|
|
24
25
|
|
|
25
|
-
if BETA.value
|
|
26
|
+
if BETA.value:
|
|
26
27
|
# static ressources
|
|
27
28
|
idx = self.html.find("<{{evalPyHTML-include: ")
|
|
28
29
|
if idx != -1:
|
|
@@ -44,6 +45,8 @@ class PyHTML:
|
|
|
44
45
|
# PyWSGIRef's styling
|
|
45
46
|
idx = self.html.find("<{{evalPyHTML-modernStyling: true}}>")
|
|
46
47
|
if idx != -1:
|
|
48
|
+
if idx > self.html.find("</head>"):
|
|
49
|
+
raise StaticResourceUsageOutsideHeadError()
|
|
47
50
|
self.html = replStrPassage(idx, idx+35, self.html, MODERN_STYLING)
|
|
48
51
|
|
|
49
52
|
def decoded(self) -> str:
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main method creating simple server example...
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from PyWSGIRef import *
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
"""
|
|
9
|
+
Main function to set up and run the PyWSGIRef server.
|
|
10
|
+
"""
|
|
11
|
+
# add Schablone 'Hallo Welt' as main
|
|
12
|
+
addSchablone("main", MAIN_HTML)
|
|
13
|
+
|
|
14
|
+
# set up application object
|
|
15
|
+
def contentGenerator(path: str) -> str:
|
|
16
|
+
"""
|
|
17
|
+
Serves as the main WSGI application.
|
|
18
|
+
"""
|
|
19
|
+
match path:
|
|
20
|
+
case "/":
|
|
21
|
+
content = SCHABLONEN["main"].decoded().format(about()["Version"])
|
|
22
|
+
case "/hello":
|
|
23
|
+
content = HELLO_WORLD
|
|
24
|
+
case _:
|
|
25
|
+
content = ERROR
|
|
26
|
+
return content
|
|
27
|
+
|
|
28
|
+
# make the application object
|
|
29
|
+
application = makeApplicationObject(contentGenerator)
|
|
30
|
+
|
|
31
|
+
# set up server
|
|
32
|
+
server = setUpServer(application)
|
|
33
|
+
|
|
34
|
+
# Note: This code is intended to be run as a script, not as a module.
|
|
35
|
+
print("Successfully started WSGI server on port 8000.")
|
|
36
|
+
|
|
37
|
+
# start serving
|
|
38
|
+
server.serve_forever()
|
|
@@ -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.5
|
|
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
|
|
@@ -171,4 +171,9 @@ from PyWSGIRef import BETA
|
|
|
171
171
|
#enable beta mode
|
|
172
172
|
BETA.enable()
|
|
173
173
|
```
|
|
174
|
+
Currently to be tested are:<br/>
|
|
175
|
+
- PyHTML include static resource blocks<br/>
|
|
176
|
+
- PyHTML include default modern styling block<br/><br/>
|
|
177
|
+
|
|
178
|
+
Thanks a lot for helping improving PyWSGIRef!
|
|
174
179
|
### More coming soon
|
|
@@ -7,7 +7,10 @@ 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
|
|
11
|
+
src/PyWSGIRef/loadContent.py
|
|
10
12
|
src/PyWSGIRef/pyhtml.py
|
|
13
|
+
src/PyWSGIRef/simpleServer.py
|
|
11
14
|
src/PyWSGIRef/templateDict.py
|
|
12
15
|
src/PyWSGIRef.egg-info/PKG-INFO
|
|
13
16
|
src/PyWSGIRef.egg-info/SOURCES.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|