Index: cookielib.py =================================================================== --- cookielib.py (revision 74229) +++ cookielib.py (working copy) @@ -1482,7 +1482,8 @@ if domain is Absent: req_host, erhn = eff_request_host(request) domain = erhn - elif not domain.startswith("."): + # Dot on all domains is RFC required and helps self.clear() + if not domain.startswith("."): domain = "."+domain # set default port @@ -1641,6 +1642,27 @@ finally: self._cookies_lock.release() + def add_cookie(self, req, name, value, attr={}): + """Make a RFC2109 valid cookie and add it to the jar""" + self._cookies_lock.acquire() + try: + self._now = int(time.time()) + attr_set = [(name,value) ] + attr_set.extend([(n,v) for n,v in attr.items()]) + + cookies = self._cookies_from_attrs_set([attr_set], req) + self._process_rfc2109_cookies(cookies) + + if len(cookies) == 1: + cookie = cookies[0] + try: + self.clear(cookie.domain, cookie.path, cookie.name) + except KeyError: + pass + self.set_cookie(cookies[0]) + finally: + self._cookies_lock.release() + def clear(self, domain=None, path=None, name=None): """Clear some cookies. Index: _LWPCookieJar.py =================================================================== --- _LWPCookieJar.py (revision 74229) +++ _LWPCookieJar.py (working copy) @@ -42,7 +42,7 @@ for k in keys: h.append((k, str(cookie._rest[k]))) - h.append(("version", str(cookie.version))) + if cookie.version is not None: h.append(("version", str(cookie.version))) return join_header_words([h])