smdb-web-server 2.0.2__tar.gz → 2.0.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.
Files changed (24) hide show
  1. {smdb_web_server-2.0.2/smdb_web_server.egg-info → smdb_web_server-2.0.4}/PKG-INFO +4 -4
  2. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/README.md +3 -3
  3. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/setup.cfg +1 -1
  4. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/HTMLServer.py +14 -3
  5. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/HTTPRequestHandler.py +6 -0
  6. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/__init__.py +2 -2
  7. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/Constants.py +3 -2
  8. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4/smdb_web_server.egg-info}/PKG-INFO +4 -4
  9. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/LICENSE +0 -0
  10. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/pyproject.toml +0 -0
  11. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/Base.py +0 -0
  12. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/Protocol.py +0 -0
  13. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/ResponseCode.py +0 -0
  14. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/Timer.py +0 -0
  15. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/UrlData.py +0 -0
  16. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/__init__.py +0 -0
  17. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/data/wrappers.py +0 -0
  18. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/errors/CloseException.py +0 -0
  19. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/errors/KnownError.py +0 -0
  20. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/errors/RequestException.py +0 -0
  21. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server/errors/__init__.py +0 -0
  22. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server.egg-info/SOURCES.txt +0 -0
  23. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server.egg-info/dependency_links.txt +0 -0
  24. {smdb_web_server-2.0.2 → smdb_web_server-2.0.4}/smdb_web_server.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smdb_web_server
3
- Version: 2.0.2
3
+ Version: 2.0.4
4
4
  Summary: A really basic, not so safe web server.
5
5
  Home-page: https://github.com/NightKey/smdb-server
6
6
  Author: Janthó Dávid
@@ -93,7 +93,7 @@ To do this with the whole application, set the same flag to true, when instantia
93
93
 
94
94
  ## GET handler
95
95
 
96
- This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre setup dictionary.
96
+ This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre-setup dictionary.
97
97
 
98
98
  ```python
99
99
  def index_handler(url_data: UrlData) -> str:
@@ -123,7 +123,7 @@ This list will be sent as a `plaintext` response.
123
123
 
124
124
  ## Put Handler
125
125
 
126
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
126
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
127
127
  ```python
128
128
  from smdb_web_server import Protocol
129
129
 
@@ -137,7 +137,7 @@ server.add_url_rule("/put", put_handler, Protocol.Put)
137
137
 
138
138
  ## Post Handler
139
139
 
140
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
140
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
141
141
  ```python
142
142
  rom smdb_web_server import Protocol
143
143
 
@@ -76,7 +76,7 @@ To do this with the whole application, set the same flag to true, when instantia
76
76
 
77
77
  ## GET handler
78
78
 
79
- This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre setup dictionary.
79
+ This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre-setup dictionary.
80
80
 
81
81
  ```python
82
82
  def index_handler(url_data: UrlData) -> str:
@@ -106,7 +106,7 @@ This list will be sent as a `plaintext` response.
106
106
 
107
107
  ## Put Handler
108
108
 
109
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
109
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
110
110
  ```python
111
111
  from smdb_web_server import Protocol
112
112
 
@@ -120,7 +120,7 @@ server.add_url_rule("/put", put_handler, Protocol.Put)
120
120
 
121
121
  ## Post Handler
122
122
 
123
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
123
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
124
124
  ```python
125
125
  rom smdb_web_server import Protocol
126
126
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = smdb_web_server
3
- version = 2.0.2
3
+ version = 2.0.4
4
4
  author = Janthó Dávid
5
5
  author_email = davidjantho@gmail.com
6
6
  description = A really basic, not so safe web server.
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  from threading import Event, Thread
3
- from typing import Callable, Dict, Optional, Any, List, Coroutine, Union
3
+ from typing import Callable, Dict, Optional, Any, List, Coroutine, Union, Literal, overload
4
4
  from os import path
5
5
 
6
6
  from smdb_logger import Logger, LEVEL
@@ -8,6 +8,8 @@ from smdb_logger import Logger, LEVEL
8
8
  from smdb_web_server import HTTPRequestHandler, Protocol, UrlData, TEMPLATES, get_rules, put_rules, post_rules, STATIC, \
9
9
  async_wrapped, Base, wrapped, show_open_calls
10
10
 
11
+ CallbackHandler = Union[Callable[[UrlData], Union[str, None]], Callable[[UrlData], Coroutine[Any, Any, Union[str, None]]]]
12
+ GetCallbackHandler = Union[Callable[[UrlData], str], Callable[[UrlData], Coroutine[Any, Any, str]]]
11
13
 
12
14
  class HTMLServer(Base):
13
15
  def __init__(
@@ -68,8 +70,17 @@ class HTMLServer(Base):
68
70
  def render_static_file(self, name: str) -> Union[str, bytes, None]:
69
71
  return self._render_static_file(name=name, STATIC=STATIC)
70
72
 
73
+ @overload
71
74
  @staticmethod
72
- def add_url_rule(rule: str, callback: Union[Callable[[UrlData], str], Callable[[UrlData], Coroutine[Any, Any, str]]], protocol: Protocol = Protocol.Get, disable_cache: bool = False) -> None:
75
+ def add_url_rule(rule: str, callback: GetCallbackHandler, protocol: Literal[Protocol.Get] = Protocol.Get, disable_cache: bool = False) -> None:...
76
+ @overload
77
+ @staticmethod
78
+ def add_url_rule(rule: str, callback: CallbackHandler, protocol: Literal[Protocol.Put, Protocol.Post], disable_cache: bool = False) -> None:...
79
+ @overload
80
+ @staticmethod
81
+ def add_url_rule(rule: str, callback: CallbackHandler, protocol: Protocol = Protocol.Get, disable_cache: bool = False) -> None:...
82
+ @staticmethod
83
+ def add_url_rule(rule: str, callback: CallbackHandler, protocol: Protocol = Protocol.Get, disable_cache: bool = False) -> None:
73
84
  if protocol == Protocol.Get:
74
85
  get_rules[rule] = (callback, disable_cache)
75
86
  elif protocol == Protocol.Put:
@@ -79,7 +90,7 @@ class HTMLServer(Base):
79
90
 
80
91
  @classmethod
81
92
  def as_url_rule(cls, rule: Optional[str] = None, protocol: Protocol = Protocol.Get, disable_cache: bool = False) -> Any:
82
- def decorator(callback: Union[Callable[[...], str], Callable[[...], Coroutine[Any, Any, str]]]):
93
+ def decorator(callback: CallbackHandler):
83
94
  cls.add_url_rule(rule or callback.__name__, callback, protocol, disable_cache)
84
95
  return decorator
85
96
 
@@ -224,6 +224,9 @@ class HTTPRequestHandler(Base):
224
224
  result = await callback(self.data)
225
225
  else:
226
226
  result = callback(self.data)
227
+ if result is None:
228
+ message_return = Constants.OkNoResponse
229
+ result = ""
227
230
  self.disable_cache = put_rules[self.path][1] or self.disable_cache
228
231
  except KnownError as ke:
229
232
  message_return = ke.response
@@ -259,6 +262,9 @@ class HTTPRequestHandler(Base):
259
262
  result = await callback(self.data)
260
263
  else:
261
264
  result = callback(self.data)
265
+ if result is None:
266
+ message_return = Constants.OkNoResponse
267
+ result = ""
262
268
  message_return = Constants.Ok
263
269
  self.disable_cache = post_rules[self.path][1] or self.disable_cache
264
270
  except KnownError as ke:
@@ -4,8 +4,8 @@ from .data import *
4
4
  from .errors import *
5
5
 
6
6
  get_rules: Dict[str, Tuple[Union[Callable[[UrlData], str], Callable[[UrlData], Coroutine[Any, Any, str]]], bool]] = {}
7
- put_rules: Dict[str, Tuple[Union[Callable[[UrlData], str], Callable[[UrlData], Coroutine[Any, Any, str]]], bool]] = {}
8
- post_rules: Dict[str, Tuple[Union[Callable[[UrlData], str], Callable[[UrlData], Coroutine[Any, Any, str]]], bool]] = {}
7
+ put_rules: Dict[str, Tuple[Union[Callable[[UrlData], Union[str, None]], Callable[[UrlData], Coroutine[Any, Any, Union[str, None]]]], bool]] = {}
8
+ post_rules: Dict[str, Tuple[Union[Callable[[UrlData], Union[str, None]], Callable[[UrlData], Coroutine[Any, Any, Union[str, None]]]], bool]] = {}
9
9
  TEMPLATES: Dict[str, str] = {}
10
10
  STATIC: Dict[str, str] = {}
11
11
 
@@ -1,9 +1,10 @@
1
1
  from smdb_web_server.data.ResponseCode import ResponseCode
2
2
 
3
3
  class Constants:
4
+ Ok = ResponseCode(200, "Ok")
5
+ OkNoResponse = ResponseCode(204, "No Content")
4
6
  NotFound = ResponseCode(404, "Not Found")
5
7
  Forbidden = ResponseCode(403, "Forbidden")
6
- Ok = ResponseCode(200, "Ok")
7
- InternalServerError = ResponseCode(500, "Internal Server Error")
8
8
  BadRequest = ResponseCode(400, "Bad Request")
9
9
  TPot = ResponseCode(418, "I'm a teapot")
10
+ InternalServerError = ResponseCode(500, "Internal Server Error")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smdb_web_server
3
- Version: 2.0.2
3
+ Version: 2.0.4
4
4
  Summary: A really basic, not so safe web server.
5
5
  Home-page: https://github.com/NightKey/smdb-server
6
6
  Author: Janthó Dávid
@@ -93,7 +93,7 @@ To do this with the whole application, set the same flag to true, when instantia
93
93
 
94
94
  ## GET handler
95
95
 
96
- This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre setup dictionary.
96
+ This handler can return any string, but it's useful, if it returns an HTML file as string. This can be a hardcoded HTML code, or a static or dynamic file. For rendering HTML template files, the server has a helper function called `render_template_file`. This can render an HTML file from a pre-setup dictionary.
97
97
 
98
98
  ```python
99
99
  def index_handler(url_data: UrlData) -> str:
@@ -123,7 +123,7 @@ This list will be sent as a `plaintext` response.
123
123
 
124
124
  ## Put Handler
125
125
 
126
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
126
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
127
127
  ```python
128
128
  from smdb_web_server import Protocol
129
129
 
@@ -137,7 +137,7 @@ server.add_url_rule("/put", put_handler, Protocol.Put)
137
137
 
138
138
  ## Post Handler
139
139
 
140
- This handler can return a simple string. The incoming data will be a bytearray of the body of the request.
140
+ This handler can return a simple string or None. The incoming data will be the [UrlData](#urldata) of the request.
141
141
  ```python
142
142
  rom smdb_web_server import Protocol
143
143
 
File without changes