PyWSGIRef 1.1.3__tar.gz → 1.1.4__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.4}/PKG-INFO +1 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/pyproject.toml +1 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/__init__.py +3 -59
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/__main__.py +1 -1
- pywsgiref-1.1.4/src/PyWSGIRef/loadContent.py +30 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/pyhtml.py +5 -2
- pywsgiref-1.1.4/src/PyWSGIRef/simpleServer.py +38 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4/src/PyWSGIRef.egg-info}/PKG-INFO +1 -1
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef.egg-info/SOURCES.txt +2 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/LICENSE +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/README.md +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/setup.cfg +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/beta.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/commons.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/defaults.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/exceptions.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef/templateDict.py +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef.egg-info/requires.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
- {pywsgiref-1.1.3 → pywsgiref-1.1.4}/tests/testMainServer.py +0 -0
|
@@ -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,40 +10,18 @@ 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
14
|
|
|
15
15
|
def about():
|
|
16
16
|
"""
|
|
17
17
|
Returns information about your release and other projects by LK
|
|
18
18
|
"""
|
|
19
|
-
return {"Version":(1, 1,
|
|
19
|
+
return {"Version":(1, 1, 4), "Author":"Leander Kafemann", "date":"10.06.2025",\
|
|
20
20
|
"recommend":("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
|
|
21
21
|
|
|
22
22
|
SCHABLONEN = TemplateDict()
|
|
23
23
|
finished = OneWayBoolean()
|
|
24
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
|
-
|
|
48
25
|
def addSchablone(name: str, content: str):
|
|
49
26
|
"""
|
|
50
27
|
Adds a template to the SCHABLONEN dictionary.
|
|
@@ -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
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Content loading helper.
|
|
3
|
+
"""
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
from .exceptions import *
|
|
7
|
+
from PyWSGIRef 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()
|
|
@@ -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/loadContent.py
|
|
10
11
|
src/PyWSGIRef/pyhtml.py
|
|
12
|
+
src/PyWSGIRef/simpleServer.py
|
|
11
13
|
src/PyWSGIRef/templateDict.py
|
|
12
14
|
src/PyWSGIRef.egg-info/PKG-INFO
|
|
13
15
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|