本文整理汇总了Python中PyQt4.QtNetwork.QNetworkCookieJar.setCookiesFromUrl方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkCookieJar.setCookiesFromUrl方法的具体用法?Python QNetworkCookieJar.setCookiesFromUrl怎么用?Python QNetworkCookieJar.setCookiesFromUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtNetwork.QNetworkCookieJar
的用法示例。
在下文中一共展示了QNetworkCookieJar.setCookiesFromUrl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_cookies
# 需要导入模块: from PyQt4.QtNetwork import QNetworkCookieJar [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkCookieJar import setCookiesFromUrl [as 别名]
def load_cookies():
'''unpickle the cookie jar'''
jar = QNetworkCookieJar()
try:
with open(join(homedir(), COOKIE_FILE)) as file:
cookies = []
for name, value in pickle.load(file):
cookies.append(QNetworkCookie(name, value))
jar.setCookiesFromUrl(cookies, QUrl(COOKIE_URL))
except IOError:
pass # no cookie file is okay
return jar
示例2: setCookiesFromUrl
# 需要导入模块: from PyQt4.QtNetwork import QNetworkCookieJar [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkCookieJar import setCookiesFromUrl [as 别名]
def setCookiesFromUrl(self, cookieList, url):
if self.__read_only:
return True
resp = QNetworkCookieJar.setCookiesFromUrl(self, cookieList, url)
if resp:
self.emit(SIGNAL('cookieJarUpdated()'))
return resp
示例3: set_cookies_from_url
# 需要导入模块: from PyQt4.QtNetwork import QNetworkCookieJar [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkCookieJar import setCookiesFromUrl [as 别名]
def set_cookies_from_url(self, cookies, url):
""" Reimplementation from base class. Prevents cookies from being set
if not from whitelisted domains.
"""
if ".".join(unicode(url.host()).split('.')[-2:]) not in self.allowed:
ret = []
else:
ret = cookies
if ret:
log(format_cookie(url, ret))
return QNetworkCookieJar.setCookiesFromUrl(self, ret, url)
示例4: setCookiesFromUrl
# 需要导入模块: from PyQt4.QtNetwork import QNetworkCookieJar [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkCookieJar import setCookiesFromUrl [as 别名]
def setCookiesFromUrl(self, cookieList, url):
"""
Public method to set cookies for a URL.
@param cookieList list of cookies to set (list of QNetworkCookie)
@param url url to set cookies for (QUrl)
@return flag indicating cookies were set (boolean)
"""
if not self.__loaded:
self.load()
globalSettings = QWebSettings.globalSettings()
if globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled):
return False
host = url.host()
eBlock = self.__isOnDomainList(self.__exceptionsBlock, host)
eAllow = not eBlock and \
self.__isOnDomainList(self.__exceptionsAllow, host)
eAllowSession = not eBlock and \
not eAllow and \
self.__isOnDomainList(self.__exceptionsAllowForSession, host)
addedCookies = False
acceptInitially = self.__acceptCookies != self.AcceptNever
if (acceptInitially and not eBlock) or \
(not acceptInitially and (eAllow or eAllowSession)):
# url domain == cookie domain
soon = QDateTime.currentDateTime()
soon = soon.addDays(90)
for cookie in cookieList:
lst = []
if not (self.__filterTrackingCookies and \
cookie.name().startsWith("__utm")):
if eAllowSession:
cookie.setExpirationDate(QDateTime())
if self.__keepCookies == self.KeepUntilTimeLimit and \
not cookie.isSessionCookie and \
cookie.expirationDate() > soon:
cookie.setExpirationDate(soon)
lst.append(cookie)
if QNetworkCookieJar.setCookiesFromUrl(self, lst, url):
addedCookies = True
elif self.__acceptCookies == self.AcceptAlways:
# force it in if wanted
cookies = self.allCookies()
for ocookie in cookies[:]:
# does the cookie exist already?
if cookie.name() == ocookie.name() and \
cookie.domain() == ocookie.domain() and \
cookie.path() == ocookie.path():
# found a match
cookies.remove(ocookie)
cookies.append(cookie)
self.setAllCookies(cookies)
addedCookies = True
if addedCookies:
self.__saveTimer.changeOccurred()
self.emit(SIGNAL("cookiesChanged()"))
return addedCookies