Skip to content

Commit 6c22c14

Browse files
committed
fix: fix bugs, docstrings
1 parent 8e25c30 commit 6c22c14

File tree

7 files changed

+61
-52
lines changed

7 files changed

+61
-52
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 8e25c30dcb41d13a213c0e40904f76d0dc015bb2
2+
Author: Alexeev Bronislav <[email protected]>
3+
Date: Sat May 3 00:26:30 2025 +0700
4+
5+
fix/feat: fix codestyle, bugs, docstrings, add PrefixTree and improve routing system
6+
17
commit e244bff1db90fb0714a0c23f3ffdee3c0192a376
28
Author: Alexeev Bronislav <[email protected]>
39
Date: Sun Apr 27 00:31:31 2025 +0700

pyechonext/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def __init__(
121121
122122
Args:
123123
app_name (str): application name
124-
settings (Settings): settings of app
125-
middlewares (List[Type[BaseMiddleware]]): list of middlewares
124+
settings (Settings): settings of app middlewares (List[Type[BaseMiddleware]]): list of middlewares
126125
urls (Optional[List[URL]], optional): basic URLs list. Defaults to [].
127126
application_type (Optional[ApplicationType], optional): application type. Defaults to ApplicationType.JSON.
128127
static_files (Optional[List[StaticFile]], optional): static files list. Defaults to [].

pyechonext/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, config_type: SettingsConfigType, filename: str = None):
7777
"""
7878
self.config = None
7979
self.config_type: SettingsConfigType = config_type
80-
self.filename: Path = Path(self.filename)
80+
self.filename: Path = Path(filename)
8181

8282
if not self.filename.exists():
8383
raise FileNotFoundError(f'Config file "{self.filename}" don\'t exists.')

pyechonext/logging/logger.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def configure_logging(
4040
format.
4141
4242
Args:
43-
level (int): The logging level to set for the logger (default: logging.INFO).
44-
stream_handler (bool): Flag to indicate if output to stdout should occur (default: True).
45-
file_handler (Optional[str]): Path to a file where logs will be written (default: None).
46-
formatter (Optional[logging.Formatter]): A formatter instance for custom log message formatting (default: None).
43+
level (int): The logging level to set for the logger (default: logging.INFO).
44+
stream_handler (bool): Flag to indicate if output to stdout should occur (default: True).
45+
file_handler (Optional[str]): Path to a file where logs will be written (default: None).
46+
formatter (Optional[logging.Formatter]): A formatter instance for custom log message formatting (default: None).
4747
"""
4848
self.logger.setLevel(level)
4949
self.clear_handlers() # Clear existing handlers before adding new ones
@@ -66,7 +66,7 @@ def default_formatter(self) -> logging.Formatter:
6666
'timestamp - logger name - log level - message'.
6767
6868
Returns:
69-
logging.Formatter: The default formatter for log messages.
69+
logging.Formatter: The default formatter for log messages.
7070
"""
7171
return logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
7272

@@ -86,8 +86,8 @@ def add_handler(self, handler: logging.Handler, formatter: logging.Formatter):
8686
logger and sets its message format.
8787
8888
Args:
89-
handler (logging.Handler): The logging handler to add (e.g., StreamHandler).
90-
formatter (logging.Formatter): The formatter to set for the handler.
89+
handler (logging.Handler): The logging handler to add (e.g., StreamHandler).
90+
formatter (logging.Formatter): The formatter to set for the handler.
9191
"""
9292
handler.setFormatter(formatter)
9393
self.logger.addHandler(handler)
@@ -98,15 +98,15 @@ def set_log_level(self, level: int):
9898
This method allows dynamic adjustments to the logging level at runtime.
9999
100100
Args:
101-
level (int): The new logging level to set for the logger.
101+
level (int): The new logging level to set for the logger.
102102
"""
103103
self.logger.setLevel(level)
104104

105105
def get_logger(self) -> logging.Logger:
106106
"""Retrieves the configured logger instance.
107107
108108
Returns:
109-
logging.Logger: The logger instance configured for the library.
109+
logging.Logger: The logger instance configured for the library.
110110
"""
111111
return self.logger
112112

@@ -123,13 +123,13 @@ def create_logger(
123123
configuration, and returns the logger for further use.
124124
125125
Args:
126-
level (int): The logging level to set for the logger (default: logging.INFO).
127-
stream_handler (bool): Flag to indicate if output to stdout should occur (default: True).
128-
file_handler (Optional[str]): Path to a file where logs will be written (default: None).
129-
formatter (Optional[logging.Formatter]): A formatter instance for custom log message formatting (default: None).
126+
level (int): The logging level to set for the logger (default: logging.INFO).
127+
stream_handler (bool): Flag to indicate if output to stdout should occur (default: True).
128+
file_handler (Optional[str]): Path to a file where logs will be written (default: None).
129+
formatter (Optional[logging.Formatter]): A formatter instance for custom log message formatting (default: None).
130130
131131
Returns:
132-
logging.Logger: The configured logger instance.
132+
logging.Logger: The configured logger instance.
133133
"""
134134
logger_manager = LoggerManager()
135135
logger_manager.configure_logging(level, stream_handler, file_handler, formatter)

pyechonext/schemas/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from functools import wraps
2+
3+
4+
def field_validation(handler, cls, value):
5+
@wraps(handler)
6+
def wrapper():
7+
result = handler(cls, value)
8+
return result
9+
10+
return wrapper

pyechonext/static.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,29 @@ def caching_static_file(self):
6868
return item
6969

7070
def _load_content(self) -> str:
71-
"""
72-
Loads a content.
71+
"""Load content of static file
7372
74-
:returns: static file content
75-
:rtype: str
73+
Returns:
74+
str: content
7675
"""
7776
with open(self.abs_filename, "r") as file:
7877
return file.read().strip()
7978

8079
def get_content_type(self) -> str:
81-
"""
82-
Gets the content type.
80+
"""Get content type
8381
84-
:returns: The content type.
85-
:rtype: str
82+
Returns:
83+
str: get mimetype
8684
"""
8785
content_type, _ = mimetypes.guess_type(str(self.abs_filename))
8886

8987
return content_type or "application/octet-stream"
9088

9189
def get_file_size(self) -> int:
92-
"""
93-
Gets the file size.
90+
"""Get file size
9491
95-
:returns: The file size.
96-
:rtype: int
92+
Returns:
93+
int: file st size
9794
"""
9895
return self.abs_filename.stat().st_size
9996

@@ -104,57 +101,54 @@ class StaticFilesManager:
104101
"""
105102

106103
def __init__(self, static_files: List[StaticFile]):
107-
"""
108-
Constructs a new instance.
104+
"""Initialize manager
109105
110-
:param static_files: The static files
111-
:type static_files: List[StaticFile]
106+
Args:
107+
static_files (List[StaticFile]): list of static files.
112108
"""
113109
self.static_files = static_files
114110

115111
def get_file_type(self, url: str) -> str | None:
116-
"""
117-
Gets the file type.
112+
"""Get file content type
118113
119-
:param url: The url
120-
:type url: str
114+
Args:
115+
url (str): static file url
121116
122-
:returns: The file type.
123-
:rtype: str
117+
Returns:
118+
str | None: content type
124119
"""
125120
for static_file in self.static_files:
126121
if static_file.filename == url:
127122
return static_file.get_content_type()
128123

129124
def get_file_size(self, url: str) -> int | None:
130-
"""
131-
Gets the file size.
125+
"""Get file size
132126
133-
:param url: The url
134-
:type url: str
127+
Args:
128+
url (str): url of static page
135129
136-
:returns: The file size.
137-
:rtype: str
130+
Returns:
131+
int | None: file size
138132
"""
139133
for static_file in self.static_files:
140134
if static_file.filename == url:
141135
return static_file.get_file_size()
142136

143137
def serve_static_file(self, url: str) -> str | bool:
144-
"""
145-
Server static file by url
138+
"""Serve static files
146139
147-
:param url: The url
148-
:type url: str
140+
Args:
141+
url (str): URL for serving
149142
150-
:returns: static file content
151-
:rtype: str
143+
Returns:
144+
str | bool: static file content or False if static file not found
152145
"""
153146
url = prepare_url(url)
154147

155148
for static_file in self.static_files:
156149
if static_file.filename == url:
157150
logger.info(f"Found static file: {static_file.filename}")
151+
158152
if static_file.precache:
159153
logger.debug(f"Use preloaded value of static file {static_file}")
160154
return static_file.preloaded_value

pyechonext/utils/stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self):
1515
self._stack_items: List[Any] = []
1616

1717
@property
18-
def items(self) -> reversed[Any]:
18+
def items(self) -> Any:
1919
"""Get reversed stack items
2020
2121
Returns:

0 commit comments

Comments
 (0)