MCPcopy
hub / github.com/psf/requests / morsel_to_cookie

Function morsel_to_cookie

src/requests/cookies.py:531–557  ·  view source on GitHub ↗

Convert a Morsel object into a Cookie containing the one k/v pair.

(morsel: Morsel[Any])

Source from the content-addressed store, hash-verified

529
530
531def morsel_to_cookie(morsel: Morsel[Any]) -> Cookie:
532 """Convert a Morsel object into a Cookie containing the one k/v pair."""
533
534 expires: int | None = None
535 if morsel["max-age"]:
536 try:
537 expires = int(time.time() + int(morsel["max-age"]))
538 except ValueError:
539 raise TypeError(f"max-age: {morsel['max-age']} must be integer")
540 elif morsel["expires"]:
541 time_template = "%a, %d-%b-%Y %H:%M:%S GMT"
542 expires = calendar.timegm(time.strptime(morsel["expires"], time_template))
543 return create_cookie(
544 comment=morsel["comment"],
545 comment_url=bool(morsel["comment"]),
546 discard=False,
547 domain=morsel["domain"],
548 expires=expires,
549 name=morsel.key,
550 path=morsel["path"],
551 port=None,
552 rest={"HttpOnly": morsel["httponly"]},
553 rfc2109=False,
554 secure=bool(morsel["secure"]),
555 value=morsel.value,
556 version=morsel["version"] or 0,
557 )
558
559
560_CookieJarT = TypeVar("_CookieJarT", bound=CookieJar)

Callers 6

test_expires_noneMethod · 0.90
setMethod · 0.85

Calls 1

create_cookieFunction · 0.85

Tested by 5

test_expires_noneMethod · 0.72