PyWSGIRef 1.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.2
3
+ Version: 1.1.4
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
@@ -162,4 +162,13 @@ from PyWSGIRef import about
162
162
 
163
163
  about()
164
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
+ ```
165
174
  ### More coming soon
@@ -144,4 +144,13 @@ from PyWSGIRef import about
144
144
 
145
145
  about()
146
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
+ ```
147
156
  ### More coming soon
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.2"
3
+ version = "1.1.4"
4
4
  authors = [
5
5
  {name="Leander Kafemann", email="leander@kafemann.berlin" },
6
6
  ]
@@ -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, 2), "Author":"Leander Kafemann", "date":"08.06.2025",\
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
@@ -1,7 +1,7 @@
1
1
  """
2
2
  Set up and run the PyWSGIRef server with a simple HTML response.
3
3
  """
4
- from PyWSGIRef import main
4
+ from PyWSGIRef.simpleServer import main
5
5
 
6
6
  if __name__ == "__main__":
7
7
  main()
@@ -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,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 replStr, replStrPassage
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:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.2
3
+ Version: 1.1.4
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
@@ -162,4 +162,13 @@ from PyWSGIRef import about
162
162
 
163
163
  about()
164
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
+ ```
165
174
  ### More coming soon
@@ -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
@@ -1,6 +0,0 @@
1
- """
2
- Home of the BETA boolean.
3
- Set BETA to true to beta-test...
4
- """
5
-
6
- BETA = False
File without changes
File without changes