PyWSGIRef 1.1.1__tar.gz → 1.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.1
3
+ Version: 1.1.3
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 = makeWSGIApp(simple_app)
55
+ application = makeApplicationObject(simple_app)
55
56
 
56
57
  # Create a WSGI server
57
- server = makeWSGIServer(application, port=8000)
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 = makeWSGIApp(advanced_app, advanced=True, setAdvancedHeaders=True)
81
+ application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
81
82
 
82
83
  # Create a WSGI server
83
- server = makeWSGIServer(application, port=8000)
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>.
@@ -151,7 +152,9 @@ pyhtml_ = """<{{evalPyHTML}}>
151
152
  pyhtml = PyHTML(pyhtml_)
152
153
  html = pyhtml.decoded()
153
154
  ```
154
- , which is actually automatically done by PyWSGIRef.
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.
155
158
  ### Others
156
159
  Use the following to get information about your release and the author of the module:
157
160
  ```python
@@ -159,4 +162,13 @@ from PyWSGIRef import about
159
162
 
160
163
  about()
161
164
  ```
165
+ ### Curious?
166
+ Join the <b>BETA</b> group to get new features even earlier!<br/>
167
+ Note that BETA features may not be tested when using them.
168
+ ```python
169
+ from PyWSGIRef import BETA
170
+
171
+ #enable beta mode
172
+ BETA.enable()
173
+ ```
162
174
  ### More coming soon
@@ -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 = makeWSGIApp(simple_app)
37
+ application = makeApplicationObject(simple_app)
38
38
 
39
39
  # Create a WSGI server
40
- server = makeWSGIServer(application, port=8000)
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 = makeWSGIApp(advanced_app, advanced=True, setAdvancedHeaders=True)
63
+ application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
64
64
 
65
65
  # Create a WSGI server
66
- server = makeWSGIServer(application, port=8000)
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>.
@@ -134,7 +134,9 @@ pyhtml_ = """<{{evalPyHTML}}>
134
134
  pyhtml = PyHTML(pyhtml_)
135
135
  html = pyhtml.decoded()
136
136
  ```
137
- , which is actually automatically done by PyWSGIRef.
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.
138
140
  ### Others
139
141
  Use the following to get information about your release and the author of the module:
140
142
  ```python
@@ -142,4 +144,13 @@ from PyWSGIRef import about
142
144
 
143
145
  about()
144
146
  ```
147
+ ### Curious?
148
+ Join the <b>BETA</b> group to get new features even earlier!<br/>
149
+ Note that BETA features may not be tested when using them.
150
+ ```python
151
+ from PyWSGIRef import BETA
152
+
153
+ #enable beta mode
154
+ BETA.enable()
155
+ ```
145
156
  ### More coming soon
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.1"
3
+ version = "1.1.3"
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, 1), "Author":"Leander Kafemann", "date":"08.06.2025",\
19
+ return {"Version":(1, 1, 3), "Author":"Leander Kafemann", "date":"10.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,31 @@
1
+ """
2
+ BETA mode...
3
+ """
4
+
5
+ class beta:
6
+ """
7
+ BETA mode for PyWSGIRef.
8
+ """
9
+ def __init__(self):
10
+ self._beta = False
11
+
12
+ @property
13
+ def value(self) -> bool:
14
+ return self._beta
15
+
16
+ def enable(self):
17
+ """
18
+ Enables BETA mode.
19
+ """
20
+ if self._beta:
21
+ raise ValueError("BETA mode is already enabled.")
22
+ self._beta = True
23
+
24
+ BETA = beta()
25
+
26
+ def enableBetaMode():
27
+ """
28
+ Enables BETA mode.
29
+ """
30
+ BETA.enable()
31
+ print("BETA mode enabled.")
@@ -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.value():
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.1
3
+ Version: 1.1.3
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 = makeWSGIApp(simple_app)
55
+ application = makeApplicationObject(simple_app)
55
56
 
56
57
  # Create a WSGI server
57
- server = makeWSGIServer(application, port=8000)
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 = makeWSGIApp(advanced_app, advanced=True, setAdvancedHeaders=True)
81
+ application = makeApplicationObject(advanced_app, advanced=True, setAdvancedHeaders=True)
81
82
 
82
83
  # Create a WSGI server
83
- server = makeWSGIServer(application, port=8000)
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>.
@@ -151,7 +152,9 @@ pyhtml_ = """<{{evalPyHTML}}>
151
152
  pyhtml = PyHTML(pyhtml_)
152
153
  html = pyhtml.decoded()
153
154
  ```
154
- , which is actually automatically done by PyWSGIRef.
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.
155
158
  ### Others
156
159
  Use the following to get information about your release and the author of the module:
157
160
  ```python
@@ -159,4 +162,13 @@ from PyWSGIRef import about
159
162
 
160
163
  about()
161
164
  ```
165
+ ### Curious?
166
+ Join the <b>BETA</b> group to get new features even earlier!<br/>
167
+ Note that BETA features may not be tested when using them.
168
+ ```python
169
+ from PyWSGIRef import BETA
170
+
171
+ #enable beta mode
172
+ BETA.enable()
173
+ ```
162
174
  ### More coming soon
@@ -3,6 +3,7 @@ README.md
3
3
  pyproject.toml
4
4
  src/PyWSGIRef/__init__.py
5
5
  src/PyWSGIRef/__main__.py
6
+ src/PyWSGIRef/beta.py
6
7
  src/PyWSGIRef/commons.py
7
8
  src/PyWSGIRef/defaults.py
8
9
  src/PyWSGIRef/exceptions.py
@@ -1,3 +1,4 @@
1
1
  requests
2
2
  typing
3
3
  legacy-cgi
4
+ naturalsize
@@ -1,6 +0,0 @@
1
- START_REPLACE = """<!DOCTYPE html>
2
- <html lang="de">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- """
@@ -1,20 +0,0 @@
1
- from .defaults import HELLO_WORLD as DEFAULT
2
- from .commons import *
3
-
4
- class PyHTML:
5
- def __init__(self, html: str = DEFAULT):
6
- self.html = html
7
- def decode(self):
8
- """
9
- Decodes the HTML content.
10
- """
11
- self.html = self.html.strip()
12
- if self.html.startswith("<{{evalPyHTML}}>"):
13
- self.html = START_REPLACE + self.html[16:]
14
-
15
- def decoded(self) -> str:
16
- """
17
- Returns the decoded HTML content.
18
- """
19
- self.decode()
20
- return self.html
File without changes
File without changes