Skip to content

Commit 30e5b5b

Browse files
more stats work
1 parent 322dfbf commit 30e5b5b

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ BETA.enable()
180180
Currently to be tested are:<br/>
181181
- PyHTML python script blocks<br/>
182182
- 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/>
184185

185186
Thanks a lot for helping improving PyWSGIRef!
186187
### More coming soon

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "PyWSGIRef"
3-
version = "1.1.14"
3+
version = "1.1.15"
44
authors = [
55
{name="Leander Kafemann", email="[email protected]" },
66
]

src/PyWSGIRef/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ def about():
1818
"""
1919
Returns information about your release and other projects by Leander Kafemann
2020
"""
21-
return {"Version": (1, 1, 14), "Author": "Leander Kafemann", "date": "05.09.2025",\
21+
return {"Version": (1, 1, 15), "Author": "Leander Kafemann", "date": "05.09.2025",\
2222
"recommend": ("pyimager"), "feedbackTo": "[email protected]"}
2323

2424
SCHABLONEN = TemplateDict()
2525
STATS = Stats()
26-
COUNT = 0
2726

2827
def addSchablone(name: str, content: str):
2928
"""
@@ -35,15 +34,15 @@ def addSchablone(name: str, content: str):
3534
SCHABLONEN[name] = PyHTML(content)
3635

3736
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:
3938
"""
4039
Returns a WSGI application object based on your contentGeneratingFunction.
4140
The contentGeneratingFunction should take a single argument (the path) and return the content as a string.
4241
If advanced is True, the contentGeneratingFunction will receive a FieldStorage object as the second argument.
4342
If setAdvancedHeaders is True, it will allow you to set advanced headers for the response.
4443
If getIP is True, the contentGeneratingFunction will receive the IP address of the client as an additional argument.
4544
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).
4746
Locks BETA mode.
4847
"""
4948
if not callable(contentGeneratingFunction):
@@ -56,8 +55,8 @@ def simpleApplication(environ, start_response) -> list:
5655
if getStats:
5756
if not BETA.value:
5857
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))
6160
type_ = "text/html"
6261
status = "200 OK"
6362
if advanced:

src/PyWSGIRef/stats.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ def __init__(self, title: str):
77
def stop(self):
88
self.end = datetime.datetime.now()
99

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+
1021
class Stats:
1122
def __init__(self):
1223
self.performanceTimes = []
24+
self.count = RestrictedAccessCounter()
1325

1426
def startPerfTime(self, title: str = "perfTime") -> PerformanceTime:
1527
return PerformanceTime(title)

0 commit comments

Comments
 (0)