Initialize a new instance. Args: id: Unique identifier for the session, autogenerated if not provided. max_age: Time duration after which the session expires. user_data: Custom user data associated with the session. max_error_score: Threshold
(
self,
*,
id: str | None = None,
max_age: timedelta = timedelta(minutes=50),
user_data: Mapping[str, JsonSerializable] | None = None,
max_error_score: float = 3.0,
error_score_decrement: float = 0.5,
created_at: datetime | None = None,
usage_count: int = 0,
max_usage_count: int = 50,
error_score: float = 0.0,
cookies: SessionCookies | CookieJar | dict[str, str] | list[CookieParam] | None = None,
blocked_status_codes: list | None = None,
)
| 34 | """Default status codes that indicate a session is blocked.""" |
| 35 | |
| 36 | def __init__( |
| 37 | self, |
| 38 | *, |
| 39 | id: str | None = None, |
| 40 | max_age: timedelta = timedelta(minutes=50), |
| 41 | user_data: Mapping[str, JsonSerializable] | None = None, |
| 42 | max_error_score: float = 3.0, |
| 43 | error_score_decrement: float = 0.5, |
| 44 | created_at: datetime | None = None, |
| 45 | usage_count: int = 0, |
| 46 | max_usage_count: int = 50, |
| 47 | error_score: float = 0.0, |
| 48 | cookies: SessionCookies | CookieJar | dict[str, str] | list[CookieParam] | None = None, |
| 49 | blocked_status_codes: list | None = None, |
| 50 | ) -> None: |
| 51 | """Initialize a new instance. |
| 52 | |
| 53 | Args: |
| 54 | id: Unique identifier for the session, autogenerated if not provided. |
| 55 | max_age: Time duration after which the session expires. |
| 56 | user_data: Custom user data associated with the session. |
| 57 | max_error_score: Threshold score beyond which the session is considered blocked. |
| 58 | error_score_decrement: Value by which the error score is decremented on successful operations. |
| 59 | created_at: Timestamp when the session was created, defaults to current UTC time if not provided. |
| 60 | usage_count: Number of times the session has been used. |
| 61 | max_usage_count: Maximum allowable uses of the session before it is considered expired. |
| 62 | error_score: Current error score of the session. |
| 63 | cookies: Cookies associated with the session. |
| 64 | blocked_status_codes: HTTP status codes that indicate a session should be blocked. |
| 65 | """ |
| 66 | self._id = id or crypto_random_object_id(length=10) |
| 67 | self._max_age = max_age |
| 68 | self._user_data: MutableMapping[str, JsonSerializable] = dict(user_data) if user_data is not None else {} |
| 69 | self._max_error_score = max_error_score |
| 70 | self._error_score_decrement = error_score_decrement |
| 71 | self._created_at = created_at or datetime.now(timezone.utc) |
| 72 | self._usage_count = usage_count |
| 73 | self._max_usage_count = max_usage_count |
| 74 | self._error_score = error_score |
| 75 | self._cookies = SessionCookies(cookies) or SessionCookies() |
| 76 | self._blocked_status_codes = set(blocked_status_codes or self._DEFAULT_BLOCKED_STATUS_CODES) |
| 77 | |
| 78 | @classmethod |
| 79 | def from_model(cls, model: SessionModel) -> Session: |
nothing calls this directly
no test coverage detected