PyWSGIRef 1.1.14__tar.gz → 1.1.16__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 (25) hide show
  1. {pywsgiref-1.1.14/src/PyWSGIRef.egg-info → pywsgiref-1.1.16}/PKG-INFO +3 -2
  2. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/README.md +2 -1
  3. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/pyproject.toml +1 -1
  4. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/__init__.py +7 -7
  5. pywsgiref-1.1.16/src/PyWSGIRef/stats.py +63 -0
  6. {pywsgiref-1.1.14 → pywsgiref-1.1.16/src/PyWSGIRef.egg-info}/PKG-INFO +3 -2
  7. pywsgiref-1.1.14/src/PyWSGIRef/stats.py +0 -18
  8. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/LICENSE +0 -0
  9. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/setup.cfg +0 -0
  10. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/__main__.py +0 -0
  11. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/beta.py +0 -0
  12. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/commons.py +0 -0
  13. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/defaults.py +0 -0
  14. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/exceptions.py +0 -0
  15. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/finished.py +0 -0
  16. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/loadContent.py +0 -0
  17. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/patterns.py +0 -0
  18. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/pyhtml.py +0 -0
  19. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/simpleServer.py +0 -0
  20. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef/templateDict.py +0 -0
  21. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef.egg-info/SOURCES.txt +0 -0
  22. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
  23. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef.egg-info/requires.txt +0 -0
  24. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
  25. {pywsgiref-1.1.14 → pywsgiref-1.1.16}/tests/testMainServer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.14
3
+ Version: 1.1.16
4
4
  Summary: easy server-setup
5
5
  Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
6
6
  Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
@@ -197,7 +197,8 @@ BETA.enable()
197
197
  Currently to be tested are:<br/>
198
198
  - PyHTML python script blocks<br/>
199
199
  - PyHTML python if clause blocks<br/>
200
- - stats for the application object<br/><br/>
200
+ - application object running time measuring<br/>
201
+ - application object counter of access<br/><br/>
201
202
 
202
203
  Thanks a lot for helping improving PyWSGIRef!
203
204
  ### More coming soon
@@ -180,7 +180,8 @@ BETA.enable()
180
180
  Currently to be tested are:<br/>
181
181
  - PyHTML python script blocks<br/>
182
182
  - PyHTML python if clause blocks<br/>
183
- - stats for the application object<br/><br/>
183
+ - application object running time measuring<br/>
184
+ - application object counter of access<br/><br/>
184
185
 
185
186
  Thanks a lot for helping improving PyWSGIRef!
186
187
  ### More coming soon
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.14"
3
+ version = "1.1.16"
4
4
  authors = [
5
5
  {name="Leander Kafemann", email="leander.kafemann+python@icloud.com" },
6
6
  ]
@@ -18,12 +18,11 @@ def about():
18
18
  """
19
19
  Returns information about your release and other projects by Leander Kafemann
20
20
  """
21
- return {"Version": (1, 1, 14), "Author": "Leander Kafemann", "date": "05.09.2025",\
21
+ return {"Version": (1, 1, 16), "Author": "Leander Kafemann", "date": "05.09.2025",\
22
22
  "recommend": ("pyimager"), "feedbackTo": "leander.kafemann+python@icloud.com"}
23
23
 
24
24
  SCHABLONEN = TemplateDict()
25
25
  STATS = Stats()
26
- COUNT = 0
27
26
 
28
27
  def addSchablone(name: str, content: str):
29
28
  """
@@ -35,7 +34,7 @@ def addSchablone(name: str, content: str):
35
34
  SCHABLONEN[name] = PyHTML(content)
36
35
 
37
36
  def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool = False, setAdvancedHeaders: bool = False,\
38
- getIP: bool = False, vercelPythonHosting: bool = False, getStats: bool = True) -> Callable:
37
+ getIP: bool = False, vercelPythonHosting: bool = False, getStats: bool = False) -> Callable:
39
38
  """
40
39
  Returns a WSGI application object based on your contentGeneratingFunction.
41
40
  The contentGeneratingFunction should take a single argument (the path) and return the content as a string.
@@ -43,7 +42,7 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
43
42
  If setAdvancedHeaders is True, it will allow you to set advanced headers for the response.
44
43
  If getIP is True, the contentGeneratingFunction will receive the IP address of the client as an additional argument.
45
44
  If vercelPythonHosting is True, your application object will be optimized for Vercel's unusual WSGI methods.
46
- If getStats is True, stats are saved in the STATS object.
45
+ If getStats is True, stats are saved in the STATS object (BETA).
47
46
  Locks BETA mode.
48
47
  """
49
48
  if not callable(contentGeneratingFunction):
@@ -56,8 +55,8 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
56
55
  if getStats:
57
56
  if not BETA.value:
58
57
  raise BetaNotEnabledError()
59
- COUNT += 1
60
- perfTime = STATS.startPerfTime("applicationCallNr"+str(COUNT))
58
+ STATS.count.increase()
59
+ perfTime = STATS.startPerfTime("applicationCallNr"+str(STATS.count.count))
61
60
  type_ = "text/html"
62
61
  status = "200 OK"
63
62
  if advanced:
@@ -83,7 +82,8 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
83
82
  ("Content-Length", str(len(content))),
84
83
  ('Access-Control-Allow-Origin', '*')]
85
84
  start_response(status, headers)
86
- STATS.stopPerfTime(perfTime)
85
+ if getStats:
86
+ STATS.stopPerfTime(perfTime)
87
87
  if not vercelPythonHosting:
88
88
  return [content.encode("utf-8")]
89
89
  return simpleApplication
@@ -0,0 +1,63 @@
1
+ import datetime
2
+
3
+ class PerformanceTime:
4
+ def __init__(self, title: str):
5
+ self.start = datetime.datetime.now()
6
+ self.title = title
7
+ def stop(self):
8
+ self.end = datetime.datetime.now()
9
+
10
+ class RestrictedAccessCounter:
11
+ def __init__(self):
12
+ self._count = 0
13
+
14
+ @property
15
+ def count(self) -> int:
16
+ return self._count
17
+
18
+ def increase(self):
19
+ self._count += 1
20
+
21
+ class Stats:
22
+ def __init__(self):
23
+ self.performanceTimes = []
24
+ self.count = RestrictedAccessCounter()
25
+
26
+ def startPerfTime(self, title: str = "perfTime") -> PerformanceTime:
27
+ return PerformanceTime(title)
28
+ def stopPerfTime(self, perfTime: PerformanceTime):
29
+ perfTime.stop()
30
+ self.performanceTimes.append(perfTime)
31
+
32
+ def export_stats(self, filename: str = None) -> str:
33
+ """
34
+ Exports all current stats as a formatted string.
35
+ If filename is given, it will also save the stats to that file.
36
+ """
37
+ lines = []
38
+ lines.append("PyWSGIRef Statistic-Export")
39
+ lines.append("=" * 30)
40
+ lines.append(f"access counter: {self.count.count}")
41
+ lines.append("")
42
+ lines.append("Performance times:")
43
+ if not self.performanceTimes:
44
+ lines.append(" (no entrys)")
45
+ else:
46
+ for i, perf in enumerate(self.performanceTimes, 1):
47
+ start = getattr(perf, "start", None)
48
+ end = getattr(perf, "end", None)
49
+ title = getattr(perf, "title", "unnamed")
50
+ if start and end:
51
+ duration = (end - start).total_seconds()
52
+ lines.append(f" {i}. {title}: {start} - {end} (duration: {duration:.3f}s)")
53
+ elif start:
54
+ lines.append(f" {i}. {title}: started at {start} (not stopped until now)")
55
+ else:
56
+ lines.append(f" {i}. {title}: (no time data)")
57
+ result = "\n".join(lines)
58
+ if filename:
59
+ if not filename.endswith(".pywsgirefstats"):
60
+ filename += ".pywsgirefstats"
61
+ with open(filename, "w", encoding="utf-8") as f:
62
+ f.write(result)
63
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.14
3
+ Version: 1.1.16
4
4
  Summary: easy server-setup
5
5
  Author-email: Leander Kafemann <leander.kafemann+python@icloud.com>
6
6
  Project-URL: Homepage, https://github.com/LeanderKafemann/PyWSGIRef
@@ -197,7 +197,8 @@ BETA.enable()
197
197
  Currently to be tested are:<br/>
198
198
  - PyHTML python script blocks<br/>
199
199
  - PyHTML python if clause blocks<br/>
200
- - stats for the application object<br/><br/>
200
+ - application object running time measuring<br/>
201
+ - application object counter of access<br/><br/>
201
202
 
202
203
  Thanks a lot for helping improving PyWSGIRef!
203
204
  ### More coming soon
@@ -1,18 +0,0 @@
1
- import datetime
2
-
3
- class PerformanceTime:
4
- def __init__(self, title: str):
5
- self.start = datetime.datetime.now()
6
- self.title = title
7
- def stop(self):
8
- self.end = datetime.datetime.now()
9
-
10
- class Stats:
11
- def __init__(self):
12
- self.performanceTimes = []
13
-
14
- def startPerfTime(self, title: str = "perfTime") -> PerformanceTime:
15
- return PerformanceTime(title)
16
- def stopPerfTime(self, perfTime: PerformanceTime):
17
- perfTime.stop()
18
- self.performanceTimes.append(perfTime)
File without changes
File without changes