Make a cookie from underspecified parameters. By default, the pair of `name` and `value` will be set for the domain '' and sent on every request (this is sometimes called a "supercookie").
(name: str, value: str, **kwargs: Any)
| 492 | |
| 493 | |
| 494 | def create_cookie(name: str, value: str, **kwargs: Any) -> Cookie: |
| 495 | """Make a cookie from underspecified parameters. |
| 496 | |
| 497 | By default, the pair of `name` and `value` will be set for the domain '' |
| 498 | and sent on every request (this is sometimes called a "supercookie"). |
| 499 | """ |
| 500 | result: dict[str, Any] = { |
| 501 | "version": 0, |
| 502 | "name": name, |
| 503 | "value": value, |
| 504 | "port": None, |
| 505 | "domain": "", |
| 506 | "path": "/", |
| 507 | "secure": False, |
| 508 | "expires": None, |
| 509 | "discard": True, |
| 510 | "comment": None, |
| 511 | "comment_url": None, |
| 512 | "rest": {"HttpOnly": None}, |
| 513 | "rfc2109": False, |
| 514 | } |
| 515 | |
| 516 | badargs = set(kwargs) - set(result) |
| 517 | if badargs: |
| 518 | raise TypeError( |
| 519 | f"create_cookie() got unexpected keyword arguments: {list(badargs)}" |
| 520 | ) |
| 521 | |
| 522 | result.update(kwargs) |
| 523 | result["port_specified"] = bool(result["port"]) |
| 524 | result["domain_specified"] = bool(result["domain"]) |
| 525 | result["domain_initial_dot"] = result["domain"].startswith(".") |
| 526 | result["path_specified"] = bool(result["path"]) |
| 527 | |
| 528 | return cookielib.Cookie(**result) |
| 529 | |
| 530 | |
| 531 | def morsel_to_cookie(morsel: Morsel[Any]) -> Cookie: |
no test coverage detected