Skip to content

Commit

Permalink
feat: documentation and type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
MissterHao committed Feb 13, 2023
1 parent ec31cae commit aaea2ed
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ DYSESSION = {
| DYNAMODB_REGION | ap-northeast-1 | The region of the DynamoDB table |
| LOGGING | Dict | Configuration of Logging |
| LOGGING["TYPE"] | CONSOLE | Only accept two kinds of parameters: `CONSOLE`, `FILE`. If this set to `CONSOLE`, django-dysession will use `StreamHandler` to stream to the console. If this set to `FILE`, django-dysession will use `FileHandler` to stream to `LOGGING["FILE_PATH"]`. |
| LOGGING["FILE_PATH"] | session.log | The file path to save logs of session managements. |
| LOGGING["FILE_PATH"] | session.log | Optional. Only use this configuration when LOGGING["TYPE"] is set to `FILE`. The file path to save logs of session managements. |


## Logging
Expand Down
7 changes: 3 additions & 4 deletions dysession/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_session(self, no_load=False) -> SessionDataModel:
def key_salt(self):
return "dysession.backends." + self.__class__.__qualname__

def is_empty(self):
def is_empty(self) -> bool:
"Return True when there is no session_key and the session is empty."
try:
return not self._session_key and not self._session_cache.is_empty
Expand All @@ -69,10 +69,10 @@ def clear(self):
super().clear()
self._session_cache = SessionDataModel()

def items(self):
def items(self) -> Dict[str, Any]:
return self._session.items()

def __str__(self):
def __str__(self) -> str:
return str(self._get_session())

# Methods that subclass must implement
Expand Down Expand Up @@ -124,7 +124,6 @@ def delete(self, session_key=None):
if session_key is None:
session_key = self._session_key


try:
self.db.delete(self._get_session())
except DeleteSessionError:
Expand Down
6 changes: 3 additions & 3 deletions dysession/backends/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ def __delitem__(self, key):
def __iter__(self):
return iter(self.__variables_names)

def __is_empty(self):
def __is_empty(self) -> bool:
return len(self.__variables_names) == 0

is_empty = property(__is_empty)

def get(self, key, default=...):
def get(self, key, default=...) -> Any:
try:
return self[key]
except AttributeError:
if default is Ellipsis:
raise
return default

def pop(self, key, default=...):
def pop(self, key, default=...) -> Any:
try:
ret = self[key]
del self[key]
Expand Down
1 change: 1 addition & 0 deletions dysession/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


class LoggingType(Enum):
"""Enum of python logger type."""

PLAINTEXT_CONSOLE = auto()
COLOR_CONSOLE = auto()
Expand Down
3 changes: 2 additions & 1 deletion dysession/logger/handler/colorful_console.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from typing import Dict

from .ansi import ANSIColor

LOGLEVEL_TRANSFORM = {
LOGLEVEL_TRANSFORM: Dict[int, str] = {
logging.DEBUG: ANSIColor.DEBUG.value,
logging.INFO: ANSIColor.OKCYAN.value,
logging.WARNING: ANSIColor.WARNING.value,
Expand Down
3 changes: 3 additions & 0 deletions dysession/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def get_config() -> Dict[str, Union[str, int]]:
* TTL_ATTRIBUTE_NAME
* CACHE_PERIOD
* DYNAMODB_REGION
* LOGGING
* TYPE
* FILE_PATH
Returns:
Dict[str, Union[str, int]]
Expand Down
2 changes: 1 addition & 1 deletion dysession/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1

0 comments on commit aaea2ed

Please sign in to comment.