|
| 1 | +## Cookie Class Documentation |
| 2 | + |
| 3 | +### Class: `Cookie` |
| 4 | + |
| 5 | +#### Constructor: `__init__(self, key, value, expires=None, path=None, domain=None, secure=False, httponly=False)` |
| 6 | + |
| 7 | +- **Parameters:** |
| 8 | + - `key` (str): The key of the cookie. |
| 9 | + - `value` (str): The value of the cookie. |
| 10 | + - `expires` (str, optional): The expiration date and time of the cookie in string format. Defaults to `None`. |
| 11 | + - `path` (str, optional): The path to which the cookie is applicable. Defaults to `None`. |
| 12 | + - `domain` (str, optional): The domain to which the cookie is applicable. Defaults to `None`. |
| 13 | + - `secure` (bool, optional): Indicates if the cookie should only be sent over secure connections. Defaults to `False`. |
| 14 | + - `httponly` (bool, optional): Indicates if the cookie is accessible only through HTTP requests and not through JavaScript. Defaults to `False`. |
| 15 | + |
| 16 | +#### Method: `__str__(self)` |
| 17 | + |
| 18 | +- **Returns:** |
| 19 | + - `str`: A string representation of the cookie suitable for HTTP headers. |
| 20 | + |
| 21 | +#### Method: `__repr__(self)` |
| 22 | + |
| 23 | +- **Returns:** |
| 24 | + - `str`: A string representation of the cookie, equivalent to calling `str(self)`. |
| 25 | + |
| 26 | +#### Method: `__eq__(self, other)` |
| 27 | + |
| 28 | +- **Parameters:** |
| 29 | + - `other` (Cookie): Another cookie object to compare with. |
| 30 | + |
| 31 | +- **Returns:** |
| 32 | + - `bool`: `True` if both cookies have the same key and value, `False` otherwise. |
| 33 | + |
| 34 | +#### Method: `__hash__(self)` |
| 35 | + |
| 36 | +- **Returns:** |
| 37 | + - `int`: Hash value of the cookie based on its key. |
| 38 | + |
| 39 | +#### Method: `__setattr__(self, key, value)` |
| 40 | + |
| 41 | +- **Parameters:** |
| 42 | + - `key` (str): The attribute key. |
| 43 | + - `value` (various): The value to be set. |
| 44 | + |
| 45 | +- **Raises:** |
| 46 | + - `TypeError`: If the provided value is not of the expected type for the corresponding attribute. |
| 47 | + |
| 48 | +#### Method: `__getattr__(self, key)` |
| 49 | + |
| 50 | +- **Parameters:** |
| 51 | + - `key` (str): The attribute key. |
| 52 | + |
| 53 | +- **Returns:** |
| 54 | + - Various: The value of the requested attribute. |
| 55 | + |
| 56 | +- **Raises:** |
| 57 | + - `AttributeError`: If the requested attribute is not available. |
| 58 | + |
| 59 | +#### Method: `__delattr__(self, key)` |
| 60 | + |
| 61 | +- **Parameters:** |
| 62 | + - `key` (str): The attribute key. |
| 63 | + |
| 64 | +- **Raises:** |
| 65 | + - `AttributeError`: If the requested attribute is not deletable. |
| 66 | + |
| 67 | +#### Method: `__contains__(self, key)` |
| 68 | + |
| 69 | +- **Parameters:** |
| 70 | + - `key` (str): The attribute key. |
| 71 | + |
| 72 | +- **Returns:** |
| 73 | + - `bool`: `True` if the key exists as an attribute, `False` otherwise. |
| 74 | + |
| 75 | +### Class: `CookieJar` |
| 76 | + |
| 77 | +#### Constructor: `__init__(self)` |
| 78 | + |
| 79 | +- **Attributes:** |
| 80 | + - `cookies` (list): A list to store `Cookie` objects. |
| 81 | + |
| 82 | +#### Method: `add_cookie(self, cookie)` |
| 83 | + |
| 84 | +- **Parameters:** |
| 85 | + - `cookie` (Cookie): The `Cookie` object to add to the jar. |
| 86 | + |
| 87 | +#### Method: `__str__(self)` |
| 88 | + |
| 89 | +- **Returns:** |
| 90 | + - `str`: A string representation of all cookies in the jar. |
| 91 | + |
| 92 | +#### Method: `get_cookie(self, key)` |
| 93 | + |
| 94 | +- **Parameters:** |
| 95 | + - `key` (str): The key of the cookie to retrieve. |
| 96 | + |
| 97 | +- **Returns:** |
| 98 | + - `Cookie` or `None`: The cookie object if found, otherwise `None`. |
| 99 | + |
| 100 | +#### Method: `get_cookies(self)` |
| 101 | + |
| 102 | +- **Returns:** |
| 103 | + - `list`: A list of all cookies in the jar. |
| 104 | + |
| 105 | +#### Method: `get_cookie_string(self)` |
| 106 | + |
| 107 | +- **Returns:** |
| 108 | + - `str`: A string representation of all cookies in the jar suitable for HTTP headers. |
| 109 | + |
| 110 | +#### Method: `delete_cookie(self, key)` |
| 111 | + |
| 112 | +- **Parameters:** |
| 113 | + - `key` (str): The key of the cookie to delete. |
| 114 | + |
| 115 | +- **Returns:** |
| 116 | + - `bool`: `True` if the cookie was deleted, `False` otherwise. |
| 117 | + |
| 118 | +#### Method: `delete_cookies(self)` |
| 119 | + |
| 120 | +- **Description:** |
| 121 | + - Clears all cookies from the jar. |
| 122 | + |
| 123 | +#### Method: `update_cookie(self, cookie)` |
| 124 | + |
| 125 | +- **Parameters:** |
| 126 | + - `cookie` (Cookie): The updated `Cookie` object. |
| 127 | + |
| 128 | +- **Returns:** |
| 129 | + - `bool`: `True` if the cookie was updated, `False` otherwise. |
| 130 | + |
| 131 | +#### Method: `set_cookie(self, key, value, expires=None, path=None, domain=None, secure=False, httponly=False)` |
| 132 | + |
| 133 | +- **Parameters:** |
| 134 | + - Same as the `Cookie` constructor. |
| 135 | + |
| 136 | +- **Description:** |
| 137 | + - Creates a new `Cookie` object and updates it in the jar. |
| 138 | + |
| 139 | +#### Method: `set_cookies(self, cookies)` |
| 140 | + |
| 141 | +- **Parameters:** |
| 142 | + - `cookies` (list): A list of `Cookie` objects to update in the jar. |
| 143 | + |
| 144 | +#### Method: `get_cookie_header(self)` |
| 145 | + |
| 146 | +- **Returns:** |
| 147 | + - `str`: A string representation of all cookies in the jar suitable for HTTP headers. |
| 148 | + |
| 149 | +#### Method: `get_cookie_dict(self)` |
| 150 | + |
| 151 | +- **Returns:** |
| 152 | + - `dict`: A dictionary mapping cookie keys to their values. |
0 commit comments