PyWSGIRef 1.1.8__tar.gz → 1.1.10__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.
Files changed (24) hide show
  1. {pywsgiref-1.1.8/src/PyWSGIRef.egg-info → pywsgiref-1.1.10}/PKG-INFO +5 -3
  2. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/README.md +4 -2
  3. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/pyproject.toml +1 -1
  4. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/__init__.py +3 -3
  5. pywsgiref-1.1.10/src/PyWSGIRef/patterns.py +13 -0
  6. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/pyhtml.py +52 -1
  7. {pywsgiref-1.1.8 → pywsgiref-1.1.10/src/PyWSGIRef.egg-info}/PKG-INFO +5 -3
  8. pywsgiref-1.1.8/src/PyWSGIRef/patterns.py +0 -9
  9. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/LICENSE +0 -0
  10. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/setup.cfg +0 -0
  11. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/__main__.py +0 -0
  12. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/beta.py +0 -0
  13. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/commons.py +0 -0
  14. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/defaults.py +0 -0
  15. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/exceptions.py +0 -0
  16. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/finished.py +0 -0
  17. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/loadContent.py +0 -0
  18. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/simpleServer.py +0 -0
  19. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef/templateDict.py +0 -0
  20. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef.egg-info/SOURCES.txt +0 -0
  21. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
  22. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef.egg-info/requires.txt +0 -0
  23. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
  24. {pywsgiref-1.1.8 → pywsgiref-1.1.10}/tests/testMainServer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.8
3
+ Version: 1.1.10
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
@@ -161,6 +161,8 @@ You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
161
161
  <code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.<br/><br/>
162
162
  With the <code><{{evalPyHTML-script: alert('Hello, World!'); :script-}}></code> phrase,<br/>
163
163
  you can add a script block anywhere inside your PyHTML file.<br/>
164
+ Using pretty much the same syntax, you can also add a style block using
165
+ <code><{{evalPyHTML-style: body { background-color: lightblue; } :style-}}></code>.
164
166
  ### Shutting down your server
165
167
  You can shut down your server by calling the <code>shutdown</code> method on the server object:
166
168
  ```python
@@ -190,8 +192,8 @@ from PyWSGIRef import BETA
190
192
  BETA.enable()
191
193
  ```
192
194
  Currently to be tested are:<br/>
193
- - PyHTML style blocks<br/>
194
- - PyHTML favicon support<br/>
195
+ - PyHTML python script blocks<br/>
196
+ - PyHTML python if clause blocks<br/>
195
197
  - PyHTML include static resource blocks<br/><br/>
196
198
 
197
199
  Thanks a lot for helping improving PyWSGIRef!
@@ -144,6 +144,8 @@ You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
144
144
  <code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.<br/><br/>
145
145
  With the <code><{{evalPyHTML-script: alert('Hello, World!'); :script-}}></code> phrase,<br/>
146
146
  you can add a script block anywhere inside your PyHTML file.<br/>
147
+ Using pretty much the same syntax, you can also add a style block using
148
+ <code><{{evalPyHTML-style: body { background-color: lightblue; } :style-}}></code>.
147
149
  ### Shutting down your server
148
150
  You can shut down your server by calling the <code>shutdown</code> method on the server object:
149
151
  ```python
@@ -173,8 +175,8 @@ from PyWSGIRef import BETA
173
175
  BETA.enable()
174
176
  ```
175
177
  Currently to be tested are:<br/>
176
- - PyHTML style blocks<br/>
177
- - PyHTML favicon support<br/>
178
+ - PyHTML python script blocks<br/>
179
+ - PyHTML python if clause blocks<br/>
178
180
  - PyHTML include static resource blocks<br/><br/>
179
181
 
180
182
  Thanks a lot for helping improving PyWSGIRef!
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.8"
3
+ version = "1.1.10"
4
4
  authors = [
5
5
  {name="Leander Kafemann", email="leander@kafemann.berlin" },
6
6
  ]
@@ -17,8 +17,8 @@ def about():
17
17
  """
18
18
  Returns information about your release and other projects by Leander Kafemann
19
19
  """
20
- return {"Version": (1, 1, 8), "Author": "Leander Kafemann", "date": "13.06.2025",\
21
- "recommend": ("Büro by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
20
+ return {"Version": (1, 1, 10), "Author": "Leander Kafemann", "date": "24.06.2025",\
21
+ "recommend": ("Buero by LK", "pyimager by LK"), "feedbackTo": "leander@kafemann.berlin"}
22
22
 
23
23
  SCHABLONEN = TemplateDict()
24
24
 
@@ -69,5 +69,5 @@ def setUpServer(application: Callable, port: int = 8000) -> WSGIServer:
69
69
  No additional Schablonen can be loaded from the web.
70
70
  """
71
71
  finished.set_true()
72
- server = make_server('', 8000, application)
72
+ server = make_server('', port, application)
73
73
  return server
@@ -0,0 +1,13 @@
1
+ EVAL_PYHTML = "<{{evalPyHTML}}>"
2
+
3
+ MODERN_STYLING_PHRASE = "<{{evalPyHTML-modernStyling: true}}>"
4
+
5
+ INCLUDE_PATTERN = r"<\{\{evalPyHTML-include: (.*?) :include-\}\}\>"
6
+
7
+ SCRIPT_PATTERN = r"<\{\{evalPyHTML-script: (.*?) :script-\}\}\>"
8
+
9
+ STYLE_PATTERN = r"<\{\{evalPyHTML-style: (.*?) :style-\}\}\>"
10
+
11
+ EVAL_BLOCK_PATTERN = r"<\{\{evalPyHTML-eval: (.*?) :eval-\}\}\>"
12
+
13
+ IF_BLOCK_PATTERN = r"<\{\{evalPyHTML-if: (.*?)\}\}\>(.*?)((<\{\{evalPyHTML-else\}\}\>(.*?))?)<\{\{evalPyHTML-endif\}\}\>"
@@ -10,6 +10,7 @@ from .patterns import *
10
10
  class PyHTML:
11
11
  def __init__(self, html: str = DEFAULT):
12
12
  self.html = html
13
+ self.context = None
13
14
 
14
15
  def _replace_eval_phrase(self):
15
16
  """
@@ -76,6 +77,46 @@ class PyHTML:
76
77
  replacement = f"<style>{style_content}</style>"
77
78
  self.html = self.html[:idx] + replacement + self.html[idxEnd:]
78
79
 
80
+ def _replace_eval_blocks(self):
81
+ """
82
+ Replaces eval replacement phrases with evaluated Python expressions.
83
+ WARNING: This method uses eval, which can execute arbitrary code.
84
+ """
85
+ if self.context is None:
86
+ self.context = {}
87
+ for match in re.finditer(EVAL_BLOCK_PATTERN, self.html, re.DOTALL):
88
+ idx, idxEnd = match.span()
89
+ code = match.group(1).strip()
90
+ try:
91
+ # eval f�r Ausdr�cke, exec f�r Statements
92
+ result = str(eval(code, {}, self.context))
93
+ except Exception as e:
94
+ result = f"<b>EvalError: {e}</b>"
95
+ self.html = self.html[:idx] + result + self.html[idxEnd:]
96
+
97
+ def _replace_if_blocks(self, context=None):
98
+ """
99
+ Replaces with html code based on the evaluation of conditions in if blocks.
100
+ """
101
+ if context is None:
102
+ context = {}
103
+ # re.DOTALL f�r mehrzeilige Bl�cke
104
+ while True:
105
+ match = re.search(IF_BLOCK_PATTERN, self.html, re.DOTALL)
106
+ if not match:
107
+ break
108
+ condition = match.group(1).strip()
109
+ if_content = match.group(2)
110
+ else_content = match.group(5) if match.group(5) is not None else ""
111
+ try:
112
+ if eval(condition, {}, context):
113
+ replacement = if_content
114
+ else:
115
+ replacement = else_content
116
+ except Exception as e:
117
+ replacement = f"<b>IfEvalError: {e}</b>"
118
+ self.html = self.html[:match.start()] + replacement + self.html[match.end():]
119
+
79
120
  def decode(self):
80
121
  """
81
122
  Decodes the HTML content by replacing specific phrases and applying modern styling.
@@ -84,13 +125,23 @@ class PyHTML:
84
125
  self._replace_eval_phrase()
85
126
  self._replace_modern_styling()
86
127
  self._replace_script_blocks()
128
+ self._replace_style_blocks()
87
129
  if BETA.value:
88
130
  self._replace_includes()
89
- self._replace_style_blocks()
131
+ self._replace_eval_blocks()
132
+ self._replace_if_blocks()
90
133
 
91
134
  def decoded(self) -> str:
92
135
  """
93
136
  Returns the decoded HTML content.
94
137
  """
95
138
  self.decode()
139
+ return self.html
140
+
141
+ def decodedContext(self, context: dict) -> str:
142
+ """
143
+ Returns the decoded HTML content with the provided context.
144
+ """
145
+ self.context = context
146
+ self.decode()
96
147
  return self.html
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.8
3
+ Version: 1.1.10
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
@@ -161,6 +161,8 @@ You can also add PyWSGIRef's own, featured modern stylesheet using:<br/>
161
161
  <code><{{evalPyHTML-modernStyling: true}}></code> inside the head block of your PyHTML file.<br/><br/>
162
162
  With the <code><{{evalPyHTML-script: alert('Hello, World!'); :script-}}></code> phrase,<br/>
163
163
  you can add a script block anywhere inside your PyHTML file.<br/>
164
+ Using pretty much the same syntax, you can also add a style block using
165
+ <code><{{evalPyHTML-style: body { background-color: lightblue; } :style-}}></code>.
164
166
  ### Shutting down your server
165
167
  You can shut down your server by calling the <code>shutdown</code> method on the server object:
166
168
  ```python
@@ -190,8 +192,8 @@ from PyWSGIRef import BETA
190
192
  BETA.enable()
191
193
  ```
192
194
  Currently to be tested are:<br/>
193
- - PyHTML style blocks<br/>
194
- - PyHTML favicon support<br/>
195
+ - PyHTML python script blocks<br/>
196
+ - PyHTML python if clause blocks<br/>
195
197
  - PyHTML include static resource blocks<br/><br/>
196
198
 
197
199
  Thanks a lot for helping improving PyWSGIRef!
@@ -1,9 +0,0 @@
1
- EVAL_PYHTML = "<{{evalPyHTML}}>"
2
-
3
- MODERN_STYLING_PHRASE = "<{{evalPyHTML-modernStyling: true}}>"
4
-
5
- INCLUDE_PATTERN = r"<\{\{evalPyHTML-include: (.*?) :include-\}\}\>"
6
-
7
- SCRIPT_PATTERN = r"<\{\{evalPyHTML-script: (.*?) :script-\}\}\>"
8
-
9
- STYLE_PATTERN = r"<\{\{evalPyHTML-style: (.*?) :style-\}\}\>"
File without changes
File without changes