PyWSGIRef 1.1.12__tar.gz → 1.1.13__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 (23) hide show
  1. {pywsgiref-1.1.12/src/PyWSGIRef.egg-info → pywsgiref-1.1.13}/PKG-INFO +1 -1
  2. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/pyproject.toml +1 -1
  3. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/__init__.py +15 -5
  4. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/exceptions.py +8 -0
  5. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/loadContent.py +9 -3
  6. {pywsgiref-1.1.12 → pywsgiref-1.1.13/src/PyWSGIRef.egg-info}/PKG-INFO +1 -1
  7. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/LICENSE +0 -0
  8. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/README.md +0 -0
  9. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/setup.cfg +0 -0
  10. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/__main__.py +0 -0
  11. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/beta.py +0 -0
  12. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/commons.py +0 -0
  13. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/defaults.py +0 -0
  14. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/finished.py +0 -0
  15. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/patterns.py +0 -0
  16. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/pyhtml.py +0 -0
  17. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/simpleServer.py +0 -0
  18. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef/templateDict.py +0 -0
  19. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef.egg-info/SOURCES.txt +0 -0
  20. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef.egg-info/dependency_links.txt +0 -0
  21. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef.egg-info/requires.txt +0 -0
  22. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/src/PyWSGIRef.egg-info/top_level.txt +0 -0
  23. {pywsgiref-1.1.12 → pywsgiref-1.1.13}/tests/testMainServer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.12
3
+ Version: 1.1.13
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyWSGIRef"
3
- version = "1.1.12"
3
+ version = "1.1.13"
4
4
  authors = [
5
5
  {name="Leander Kafemann", email="leander@kafemann.berlin" },
6
6
  ]
@@ -17,7 +17,7 @@ def about():
17
17
  """
18
18
  Returns information about your release and other projects by Leander Kafemann
19
19
  """
20
- return {"Version": (1, 1, 12), "Author": "Leander Kafemann", "date": "06.08.2025",\
20
+ return {"Version": (1, 1, 13), "Author": "Leander Kafemann", "date": "13.08.2025",\
21
21
  "recommend": ("Buero by LK", "pyimager by LK"), "feedbackTo": "update-bot@lk.kafemann.berlin"}
22
22
 
23
23
  SCHABLONEN = TemplateDict()
@@ -31,12 +31,13 @@ def addSchablone(name: str, content: str):
31
31
  raise ServerAlreadyGeneratedError()
32
32
  SCHABLONEN[name] = PyHTML(content)
33
33
 
34
- def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool = False, setAdvancedHeaders: bool = False) -> Callable:
34
+ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool = False, setAdvancedHeaders: bool = False, getIP: bool = False) -> Callable:
35
35
  """
36
36
  Returns a WSGI application object based on your contentGeneratingFunction.
37
37
  The contentGeneratingFunction should take a single argument (the path) and return the content as a string.
38
38
  If advanced is True, the contentGeneratingFunction will receive a FieldStorage object as the second argument.
39
39
  If setAdvancedHeaders is True, it will allow you to set advanced headers for the response.
40
+ If getIP is True, the contentGeneratingFunction will receive the IP address of the client as an additional argument.
40
41
  """
41
42
  if not callable(contentGeneratingFunction):
42
43
  raise InvalidCallableError()
@@ -49,13 +50,22 @@ def makeApplicationObject(contentGeneratingFunction: Callable, advanced: bool =
49
50
  if advanced:
50
51
  storage = FieldStorage(fp=environ.get("wsgi.input"), environ=environ, keep_blank_values=True)
51
52
  if setAdvancedHeaders:
52
- content, type_, status = contentGeneratingFunction(environ["PATH_INFO"], storage)
53
+ if getIP:
54
+ content, type_, status = contentGeneratingFunction(environ["PATH_INFO"], storage, environ["HTTP_X_REAL_IP"])
55
+ else:
56
+ content, type_, status = contentGeneratingFunction(environ["PATH_INFO"], storage)
53
57
  else:
54
- content = contentGeneratingFunction(environ["PATH_INFO"], storage)
58
+ if getIP:
59
+ content = contentGeneratingFunction(environ["PATH_INFO"], storage, environ["HTTP_X_REAL_IP"])
60
+ else:
61
+ content = contentGeneratingFunction(environ["PATH_INFO"], storage)
55
62
  else:
56
63
  if setAdvancedHeaders:
57
64
  raise AdvancedHeadersWithoutAdvancedModeError()
58
- content = contentGeneratingFunction(environ["PATH_INFO"])
65
+ if getIP:
66
+ content = contentGeneratingFunction(environ["PATH_INFO"], environ["HTTP_X_REAL_IP"])
67
+ else:
68
+ content = contentGeneratingFunction(environ["PATH_INFO"])
59
69
  headers = [("Content-Type", type_),
60
70
  ("Content-Length", str(len(content))),
61
71
  ('Access-Control-Allow-Origin', '*')]
@@ -60,5 +60,13 @@ class BetaAlreadyEnabledError(BooleanAlreadyTrueError):
60
60
  Raised when trying to enable beta mode that is already enabled.
61
61
  """
62
62
  def __init__(self, message="Beta mode is already enabled."):
63
+ self.message = message
64
+ super().__init__(self.message)
65
+
66
+ class AccessToTemplateForbidden(Exception):
67
+ """
68
+ Raised when trying to access a template that is not allowed.
69
+ """
70
+ def __init__(self, message="Access to this template is forbidden."):
63
71
  self.message = message
64
72
  super().__init__(self.message)
@@ -6,7 +6,7 @@ import requests
6
6
  from .exceptions import *
7
7
  from .finished import finished
8
8
 
9
- def loadFromWeb(url: str, data: dict = {}) -> str:
9
+ def loadFromWeb(url: str) -> str:
10
10
  """
11
11
  Loads content from the given URL with the given data.
12
12
  """
@@ -14,8 +14,14 @@ def loadFromWeb(url: str, data: dict = {}) -> str:
14
14
  raise ServerAlreadyGeneratedError()
15
15
  if not url.endswith(".pyhtml"):
16
16
  raise InvalidFiletypeError()
17
- rq = requests.post(url, data).content
18
- return rq.decode()
17
+
18
+ # trick GitHub Pages guardian
19
+ headers = {"User-Agent": "Mozilla/5.0", "realAccessDeviceMonitorAgent": "PyWSGIRef/1.1"}
20
+ rq = requests.get(url, headers=headers)
21
+ if rq.status_code != 200:
22
+ raise AccessToTemplateForbidden()
23
+ rq_content = rq.content
24
+ return rq_content.decode()
19
25
 
20
26
  def loadFromFile(filename: str) -> str:
21
27
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyWSGIRef
3
- Version: 1.1.12
3
+ Version: 1.1.13
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
File without changes
File without changes
File without changes