PyWSGIRef 1.1.0__tar.gz → 1.1.2__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.0/src/PyWSGIRef.egg-info → pywsgiref-1.1.2}/PKG-INFO +25 -6
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/README.md +23 -5
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/pyproject.toml +2 -1
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef/__init__.py +2 -1
- pywsgiref-1.1.2/src/PyWSGIRef/beta.py +6 -0
- pywsgiref-1.1.2/src/PyWSGIRef/commons.py +14 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef/exceptions.py +16 -0
- pywsgiref-1.1.2/src/PyWSGIRef/pyhtml.py +54 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef/templateDict.py +4 -4
- {pywsgiref-1.1.0 → pywsgiref-1.1.2/src/PyWSGIRef.egg-info}/PKG-INFO +25 -6
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef.egg-info/SOURCES.txt +2 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef.egg-info/requires.txt +1 -0
- pywsgiref-1.1.0/src/PyWSGIRef/pyhtml.py +0 -16
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/LICENSE +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/setup.cfg +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef/__main__.py +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef/defaults.py +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
- {pywsgiref-1.1.0 → pywsgiref-1.1.2}/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.2
|
|
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
|
|
@@ -13,6 +13,7 @@ License-File: LICENSE
|
|
|
13
13
|
Requires-Dist: requests
|
|
14
14
|
Requires-Dist: typing
|
|
15
15
|
Requires-Dist: legacy-cgi
|
|
16
|
+
Requires-Dist: naturalsize
|
|
16
17
|
Dynamic: license-file
|
|
17
18
|
|
|
18
19
|
# PyWSGIRef
|
|
@@ -51,10 +52,10 @@ from PyWSGIRef import *
|
|
|
51
52
|
# Create a WSGI application object
|
|
52
53
|
def simple_app(path: str) -> str:
|
|
53
54
|
return f"Hello, you visited {path}!"
|
|
54
|
-
application =
|
|
55
|
+
application = makeApplicationObject(simple_app)
|
|
55
56
|
|
|
56
57
|
# Create a WSGI server
|
|
57
|
-
server =
|
|
58
|
+
server = setUpServer(application, port=8000)
|
|
58
59
|
server.serve_forever()
|
|
59
60
|
```
|
|
60
61
|
The <code>makeWSGIApp</code> function requires a callable that takes a single argument (the path) and returns a string response.<br/>
|
|
@@ -77,10 +78,10 @@ def advanced_app(path: str, form: FieldStorage) -> str, str, str:
|
|
|
77
78
|
return f"Hello, {name}, you visited {path}!", "text/html", "200 OK"
|
|
78
79
|
else:
|
|
79
80
|
return "Page not found", "text/html", "404 Not Found"
|
|
80
|
-
application =
|
|
81
|
+
application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
|
|
81
82
|
|
|
82
83
|
# Create a WSGI server
|
|
83
|
-
server =
|
|
84
|
+
server = setUpServer(application, port=8000)
|
|
84
85
|
server.serve_forever()
|
|
85
86
|
```
|
|
86
87
|
You can also use your own application object instead of the one created by <code>makeWSGIApp</code>.
|
|
@@ -135,7 +136,25 @@ or (from a commandline)
|
|
|
135
136
|
py -m PyWSGIRef
|
|
136
137
|
```
|
|
137
138
|
### Decoding PyHTML
|
|
138
|
-
coming soon...
|
|
139
|
+
(more coming soon...)<br/>
|
|
140
|
+
PyWSGIRef provides a simple way to shorten a common HTML beginning phrase in PyHTML:
|
|
141
|
+
```python
|
|
142
|
+
from PyWSGIRef import PyHTML
|
|
143
|
+
|
|
144
|
+
# Shorten HTML beginning phrase
|
|
145
|
+
pyhtml_ = """<{{evalPyHTML}}>
|
|
146
|
+
<title>My Page</title>
|
|
147
|
+
</head>
|
|
148
|
+
<body>
|
|
149
|
+
<h1>Hello, World!</h1>
|
|
150
|
+
</body>
|
|
151
|
+
</html>"""
|
|
152
|
+
pyhtml = PyHTML(pyhtml_)
|
|
153
|
+
html = pyhtml.decoded()
|
|
154
|
+
```
|
|
155
|
+
, which is actually automatically done by PyWSGIRef.<br/>
|
|
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.
|
|
139
158
|
### Others
|
|
140
159
|
Use the following to get information about your release and the author of the module:
|
|
141
160
|
```python
|
|
@@ -34,10 +34,10 @@ from PyWSGIRef import *
|
|
|
34
34
|
# Create a WSGI application object
|
|
35
35
|
def simple_app(path: str) -> str:
|
|
36
36
|
return f"Hello, you visited {path}!"
|
|
37
|
-
application =
|
|
37
|
+
application = makeApplicationObject(simple_app)
|
|
38
38
|
|
|
39
39
|
# Create a WSGI server
|
|
40
|
-
server =
|
|
40
|
+
server = setUpServer(application, port=8000)
|
|
41
41
|
server.serve_forever()
|
|
42
42
|
```
|
|
43
43
|
The <code>makeWSGIApp</code> function requires a callable that takes a single argument (the path) and returns a string response.<br/>
|
|
@@ -60,10 +60,10 @@ def advanced_app(path: str, form: FieldStorage) -> str, str, str:
|
|
|
60
60
|
return f"Hello, {name}, you visited {path}!", "text/html", "200 OK"
|
|
61
61
|
else:
|
|
62
62
|
return "Page not found", "text/html", "404 Not Found"
|
|
63
|
-
application =
|
|
63
|
+
application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
|
|
64
64
|
|
|
65
65
|
# Create a WSGI server
|
|
66
|
-
server =
|
|
66
|
+
server = setUpServer(application, port=8000)
|
|
67
67
|
server.serve_forever()
|
|
68
68
|
```
|
|
69
69
|
You can also use your own application object instead of the one created by <code>makeWSGIApp</code>.
|
|
@@ -118,7 +118,25 @@ or (from a commandline)
|
|
|
118
118
|
py -m PyWSGIRef
|
|
119
119
|
```
|
|
120
120
|
### Decoding PyHTML
|
|
121
|
-
coming soon...
|
|
121
|
+
(more coming soon...)<br/>
|
|
122
|
+
PyWSGIRef provides a simple way to shorten a common HTML beginning phrase in PyHTML:
|
|
123
|
+
```python
|
|
124
|
+
from PyWSGIRef import PyHTML
|
|
125
|
+
|
|
126
|
+
# Shorten HTML beginning phrase
|
|
127
|
+
pyhtml_ = """<{{evalPyHTML}}>
|
|
128
|
+
<title>My Page</title>
|
|
129
|
+
</head>
|
|
130
|
+
<body>
|
|
131
|
+
<h1>Hello, World!</h1>
|
|
132
|
+
</body>
|
|
133
|
+
</html>"""
|
|
134
|
+
pyhtml = PyHTML(pyhtml_)
|
|
135
|
+
html = pyhtml.decoded()
|
|
136
|
+
```
|
|
137
|
+
, which is actually automatically done by PyWSGIRef.<br/>
|
|
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.
|
|
122
140
|
### Others
|
|
123
141
|
Use the following to get information about your release and the author of the module:
|
|
124
142
|
```python
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "PyWSGIRef"
|
|
3
|
-
version = "1.1.
|
|
3
|
+
version = "1.1.2"
|
|
4
4
|
authors = [
|
|
5
5
|
{name="Leander Kafemann", email="leander@kafemann.berlin" },
|
|
6
6
|
]
|
|
@@ -16,6 +16,7 @@ dependencies = [
|
|
|
16
16
|
"requests",
|
|
17
17
|
"typing",
|
|
18
18
|
"legacy-cgi",
|
|
19
|
+
"naturalsize",
|
|
19
20
|
]
|
|
20
21
|
|
|
21
22
|
[project.urls]
|
|
@@ -10,12 +10,13 @@ from .exceptions import *
|
|
|
10
10
|
from .pyhtml import PyHTML
|
|
11
11
|
from .defaults import *
|
|
12
12
|
from .templateDict import TemplateDict, OneWayBoolean
|
|
13
|
+
from .beta import BETA
|
|
13
14
|
|
|
14
15
|
def about():
|
|
15
16
|
"""
|
|
16
17
|
Returns information about your release and other projects by LK
|
|
17
18
|
"""
|
|
18
|
-
return {"Version":(1, 1,
|
|
19
|
+
return {"Version":(1, 1, 2), "Author":"Leander Kafemann", "date":"08.06.2025",\
|
|
19
20
|
"recommend":("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
|
|
20
21
|
|
|
21
22
|
SCHABLONEN = TemplateDict()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
START_REPLACE = """<!DOCTYPE html>
|
|
2
|
+
<html lang="de-de">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8"/>
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
6
|
+
<meta name="announcement" content="This is a PyWSGIRef generated page."/>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
END_REPLACE = """
|
|
10
|
+
<p style="font-size: 7px; text-align: center;">Generated by PyWSGIRef</p>
|
|
11
|
+
</body>
|
|
12
|
+
</html>"""
|
|
13
|
+
|
|
14
|
+
MODERN_STYLING = """<link rel='stylesheet' href='https://leanderkafemann.github.io/PyWSGIRef-Backend/styling/modernStyling.css'/>"""
|
|
@@ -28,5 +28,21 @@ class AdvancedHeadersWithoutAdvancedModeError(Exception):
|
|
|
28
28
|
Raised when advanced headers are set without advanced mode being enabled.
|
|
29
29
|
"""
|
|
30
30
|
def __init__(self, message="Advanced headers cannot be set without enabling advanced mode."):
|
|
31
|
+
self.message = message
|
|
32
|
+
super().__init__(self.message)
|
|
33
|
+
|
|
34
|
+
class InvalidIncludePhraseFiletypeError(InvalidFiletypeError):
|
|
35
|
+
"""
|
|
36
|
+
Raised when an invalid file type is encountered in the include phrase of a PyHTML file.
|
|
37
|
+
"""
|
|
38
|
+
def __init__(self, message="Invalid file type in include phrase. Only .css, .js, and .json files are allowed."):
|
|
39
|
+
self.message = message
|
|
40
|
+
super().__init__(self.message)
|
|
41
|
+
|
|
42
|
+
class StaticResourceUsageOutsideHeadError(Exception):
|
|
43
|
+
"""
|
|
44
|
+
Raised when a static resource is tried to include outside the head term of a PyHTML file.
|
|
45
|
+
"""
|
|
46
|
+
def __init__(self, message="Static resource usage out of <head> term detected."):
|
|
31
47
|
self.message = message
|
|
32
48
|
super().__init__(self.message)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from naturalsize import replStr, 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
|
+
def decode(self):
|
|
12
|
+
"""
|
|
13
|
+
Decodes the HTML content.
|
|
14
|
+
"""
|
|
15
|
+
self.html = self.html.strip()
|
|
16
|
+
|
|
17
|
+
# common html beginning phrase
|
|
18
|
+
if self.html.startswith("<{{evalPyHTML}}>"):
|
|
19
|
+
self.html = START_REPLACE + self.html[16:]
|
|
20
|
+
|
|
21
|
+
# common html ending phrase
|
|
22
|
+
if self.html.endswith("<{{evalPyHTML}}>"):
|
|
23
|
+
self.html = self.html[:-16] + END_REPLACE
|
|
24
|
+
|
|
25
|
+
if BETA:
|
|
26
|
+
# static ressources
|
|
27
|
+
idx = self.html.find("<{{evalPyHTML-include: ")
|
|
28
|
+
if idx != -1:
|
|
29
|
+
idxEnd = self.html.find(" :include-}}>", idx)
|
|
30
|
+
if idxEnd > self.html.find("</head>"):
|
|
31
|
+
raise StaticResourceUsageOutsideHeadError()
|
|
32
|
+
setIn = ""
|
|
33
|
+
for i in self.html[idx:idxEnd+12].split(":")[1].strip().split(","):
|
|
34
|
+
if i.endswith(".css"):
|
|
35
|
+
setIn += "\t\t<link rel='stylesheet' href='{}'/>\n".format(i)
|
|
36
|
+
elif i.endswith(".js"):
|
|
37
|
+
setIn += "\t\t<script src='{}'></script>\n".format(i)
|
|
38
|
+
elif i.endswith(".json"):
|
|
39
|
+
setIn += "\t\t<link rel='manifest' href='{}'/>\n".format(i)
|
|
40
|
+
else:
|
|
41
|
+
raise InvalidIncludePhraseFiletypeError()
|
|
42
|
+
self.html = replStrPassage(idx, idxEnd+12, self.html, setIn)
|
|
43
|
+
|
|
44
|
+
# PyWSGIRef's styling
|
|
45
|
+
idx = self.html.find("<{{evalPyHTML-modernStyling: true}}>")
|
|
46
|
+
if idx != -1:
|
|
47
|
+
self.html = replStrPassage(idx, idx+35, self.html, MODERN_STYLING)
|
|
48
|
+
|
|
49
|
+
def decoded(self) -> str:
|
|
50
|
+
"""
|
|
51
|
+
Returns the decoded HTML content.
|
|
52
|
+
"""
|
|
53
|
+
self.decode()
|
|
54
|
+
return self.html
|
|
@@ -35,17 +35,17 @@ class TemplateDict:
|
|
|
35
35
|
|
|
36
36
|
class OneWayBoolean:
|
|
37
37
|
def __init__(self):
|
|
38
|
-
self.
|
|
38
|
+
self._value = False
|
|
39
39
|
|
|
40
40
|
@property
|
|
41
41
|
def value(self) -> bool:
|
|
42
|
-
return self.
|
|
42
|
+
return self._value
|
|
43
43
|
|
|
44
44
|
def set_true(self):
|
|
45
45
|
"""
|
|
46
46
|
Setzt den Wert auf True, wenn er False ist.
|
|
47
47
|
"""
|
|
48
|
-
if not self.
|
|
49
|
-
self.
|
|
48
|
+
if not self._value:
|
|
49
|
+
self._value = True
|
|
50
50
|
else:
|
|
51
51
|
raise ValueError("Value is already True, cannot set again.")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyWSGIRef
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
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
|
|
@@ -13,6 +13,7 @@ License-File: LICENSE
|
|
|
13
13
|
Requires-Dist: requests
|
|
14
14
|
Requires-Dist: typing
|
|
15
15
|
Requires-Dist: legacy-cgi
|
|
16
|
+
Requires-Dist: naturalsize
|
|
16
17
|
Dynamic: license-file
|
|
17
18
|
|
|
18
19
|
# PyWSGIRef
|
|
@@ -51,10 +52,10 @@ from PyWSGIRef import *
|
|
|
51
52
|
# Create a WSGI application object
|
|
52
53
|
def simple_app(path: str) -> str:
|
|
53
54
|
return f"Hello, you visited {path}!"
|
|
54
|
-
application =
|
|
55
|
+
application = makeApplicationObject(simple_app)
|
|
55
56
|
|
|
56
57
|
# Create a WSGI server
|
|
57
|
-
server =
|
|
58
|
+
server = setUpServer(application, port=8000)
|
|
58
59
|
server.serve_forever()
|
|
59
60
|
```
|
|
60
61
|
The <code>makeWSGIApp</code> function requires a callable that takes a single argument (the path) and returns a string response.<br/>
|
|
@@ -77,10 +78,10 @@ def advanced_app(path: str, form: FieldStorage) -> str, str, str:
|
|
|
77
78
|
return f"Hello, {name}, you visited {path}!", "text/html", "200 OK"
|
|
78
79
|
else:
|
|
79
80
|
return "Page not found", "text/html", "404 Not Found"
|
|
80
|
-
application =
|
|
81
|
+
application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
|
|
81
82
|
|
|
82
83
|
# Create a WSGI server
|
|
83
|
-
server =
|
|
84
|
+
server = setUpServer(application, port=8000)
|
|
84
85
|
server.serve_forever()
|
|
85
86
|
```
|
|
86
87
|
You can also use your own application object instead of the one created by <code>makeWSGIApp</code>.
|
|
@@ -135,7 +136,25 @@ or (from a commandline)
|
|
|
135
136
|
py -m PyWSGIRef
|
|
136
137
|
```
|
|
137
138
|
### Decoding PyHTML
|
|
138
|
-
coming soon...
|
|
139
|
+
(more coming soon...)<br/>
|
|
140
|
+
PyWSGIRef provides a simple way to shorten a common HTML beginning phrase in PyHTML:
|
|
141
|
+
```python
|
|
142
|
+
from PyWSGIRef import PyHTML
|
|
143
|
+
|
|
144
|
+
# Shorten HTML beginning phrase
|
|
145
|
+
pyhtml_ = """<{{evalPyHTML}}>
|
|
146
|
+
<title>My Page</title>
|
|
147
|
+
</head>
|
|
148
|
+
<body>
|
|
149
|
+
<h1>Hello, World!</h1>
|
|
150
|
+
</body>
|
|
151
|
+
</html>"""
|
|
152
|
+
pyhtml = PyHTML(pyhtml_)
|
|
153
|
+
html = pyhtml.decoded()
|
|
154
|
+
```
|
|
155
|
+
, which is actually automatically done by PyWSGIRef.<br/>
|
|
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.
|
|
139
158
|
### Others
|
|
140
159
|
Use the following to get information about your release and the author of the module:
|
|
141
160
|
```python
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from .defaults import HELLO_WORLD as DEFAULT
|
|
2
|
-
|
|
3
|
-
class PyHTML:
|
|
4
|
-
def __init__(self, html: str = DEFAULT):
|
|
5
|
-
self.html = html
|
|
6
|
-
def decode(self):
|
|
7
|
-
"""
|
|
8
|
-
Decodes the HTML content.
|
|
9
|
-
"""
|
|
10
|
-
self.html = self.html.strip()
|
|
11
|
-
def decoded(self) -> str:
|
|
12
|
-
"""
|
|
13
|
-
Returns the decoded HTML content.
|
|
14
|
-
"""
|
|
15
|
-
self.decode()
|
|
16
|
-
return self.html
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|