def manualCookie(SN, cookn, cookv): """ This is a convenience method for setting a cookie manually. Parameters:screenName,cookieName,cookieValue """ if SN and cookn and cookv: cname = cookn.strip() cvalue = cookv.strip() if not cvalue.endswith(";"): cvalue = cvalue + ";" cook = cname + "=" + cvalue cooky = Cookie() cready = 1 try: cooky.load(cook) except: __showMessage( "Invalid cookie: Cookie is corrupted or cannot be read properly" ) cready = 0 if cready: try: __cookieJar[SN] = str(cooky.data[cname].OutputString()) __showMessage("Cookie successfully set.") except: __showMessage( "Error setting cookie: Could not set cookie properly.\nAny OLD cookies for this name MAY have been erased in the process." ) cready = 0 return cready
def __collectCookies(hdrs, next_url, userName=None): global __cookieJar nURL = next_url cooky = Cookie() if hdrs: for i in hdrs: hd = string.split(i, ": ") hd_name = hd[0].lower().strip() hd_value = hd[1].replace("\r", "") hd_value = hd_value.replace("\n", "").strip() if hd_name == "set-cookie": try: cooky.load(hd_value) except: pass #print "Cookie problem" if hd_name == "location": nURL = hd_value if len(cooky) and userName: #print "COOKIES: "+str(cooky) if not __cookieJar.has_key(userName): __cookieJar[userName] = "" for cname in cooky.keys(): if not cname.lower().strip() == "path": try: cval = cooky.data[cname] __cookieJar[userName] = str(__cookieJar[userName]) + str( cval.OutputString()) except: pass #print "cookie error" #print "nURL : "+nURL return nURL