本文整理汇总了Python中PyQt4.QtNetwork.QNetworkCookieJar类的典型用法代码示例。如果您正苦于以下问题:Python QNetworkCookieJar类的具体用法?Python QNetworkCookieJar怎么用?Python QNetworkCookieJar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkCookieJar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _import_cookie_jar
def _import_cookie_jar(self,http_cookie_jar,default_domain):
cj = QNetworkCookieJar()
cookie_attrs = http_cookie_jar.http_header_attrs(self.urllib_request)
cookies = self._parse_cookie_attribs_into_QtCookies_list(cookie_attrs, default_domain)
cj.setAllCookies(cookies)
return cj
示例2: ShoutCastForm
class ShoutCastForm(PluginBase.PluginBase):
'''Grab Shoutcast streams and save them as "bookmarks" - and play them on
the currently selected server.
General shoutcast information is not preserved between runs. Also, the
shoutcast server/API is pretty lame so timeouts actually occur quite
frequently.
'''
moduleName = '&Shoutcast'
moduleIcon = "network-workgroup"
def load(self):
pass
def event(self, event):
if event.type() == QEvent.Paint:
if not hasattr(self, 'webView'):
self._load()
self.event = super(ShoutCastForm, self).event
return False
def _load(self):
self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
self.cookie.setDomain('.shoutcast.com')
self.cookie.setExpirationDate(QDateTime())
self.cookie.setPath('/')
self.webView = QWebView(self)
self.webPage = self.webView.page()
self.cookiejar = QNetworkCookieJar()
self.cookiejar.setAllCookies([self.cookie])
self.webPage.networkAccessManager().setCookieJar(self.cookiejar)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.webView)
self.webView.load(QUrl(HOMEURL))
self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)
def _processLink(self, url):
if url.host() == TUNEIN:
self._playStation(unicode(url.toString()))
else:
self.webView.load(url)
self.webView.show()
def _playStation(self, url):
try:
streamList = streamTools.getStreamList(url)
except streamTools.ParseError:
return
if streamList:
self.modelManager.playQueue.extend(streamList)
示例3: load_cookies
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
示例4: __init__
def __init__(self, parent = None):
"""
Constructor
@param parent reference to the parent object (QObject)
"""
QNetworkCookieJar.__init__(self, parent)
self.__loaded = False
self.__acceptCookies = self.AcceptOnlyFromSitesNavigatedTo
self.__saveTimer = AutoSaver(self, self.save)
self.__cookiesFile = os.path.join(Utilities.getConfigDir(),
"browser", "cookies.ini")
示例5: load_cookies
def load_cookies(self, url, cookie_strings):
p = urlparse(url)
cookies = list()
for c in cookie_strings:
n = c.find('=')
name, value = c[:n], c[n+1:]
cookie = QNetworkCookie(name, value)
cookie.setDomain(p.netloc)
cookies.append(cookie)
cookiejar = QNetworkCookieJar()
cookiejar.setAllCookies(cookies)
self.networkAccessManager().setCookieJar(cookiejar)
示例6: _createCookieJarfromInjectedResponse
def _createCookieJarfromInjectedResponse(self, default_domain):
#ugly, but works around bugs in parseCookies
cookies = []
for cookie_header in self._getCookieHeaders():
tmp_cookieList = QNetworkCookie.parseCookies(cookie_header)
tmp_cookie = tmp_cookieList[0]
if not tmp_cookie.domain():
tmp_cookie.setDomain(QString(default_domain))
cookies = cookies + tmp_cookieList
cj = QNetworkCookieJar()
cj.setAllCookies(cookies)
return cj
示例7: setCookiesFromUrl
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
示例8: __init__
def __init__(self, user_agent=default_user_agent, wait_timeout=8,
wait_callback=None, log_level=logging.WARNING, display=False,
viewport_size=(800, 600), cache_dir='/tmp/ghost.py'):
self.http_resources = []
self.user_agent = user_agent
self.wait_timeout = wait_timeout
self.wait_callback = wait_callback
self.loaded = True
if not sys.platform.startswith('win') and not 'DISPLAY' in os.environ\
and not hasattr(Ghost, 'xvfb'):
try:
os.environ['DISPLAY'] = ':99'
Ghost.xvfb = subprocess.Popen(['Xvfb', ':99'])
except OSError:
raise Exception('Xvfb is required to a ghost run oustside ' +\
'an X instance')
self.display = display
if not Ghost._app:
Ghost._app = QApplication.instance() or QApplication(['ghost'])
self.page = GhostWebPage(Ghost._app)
QtWebKit.QWebSettings.setMaximumPagesInCache(0)
QtWebKit.QWebSettings.setObjectCacheCapacities(0, 0, 0)
self.set_viewport_size(*viewport_size)
self.page.loadFinished.connect(self._page_loaded)
self.page.loadStarted.connect(self._page_load_started)
self.manager = self.page.networkAccessManager()
self.manager.finished.connect(self._request_ended)
# Cache
self.cache = QNetworkDiskCache()
self.cache.setCacheDirectory(cache_dir)
self.manager.setCache(self.cache)
# Cookie jar
self.cookie_jar = QNetworkCookieJar()
self.manager.setCookieJar(self.cookie_jar)
# User Agent
self.page.setUserAgent(self.user_agent)
self.page.networkAccessManager().authenticationRequired\
.connect(self._authenticate)
self.page.networkAccessManager().proxyAuthenticationRequired\
.connect(self._authenticate)
self.main_frame = self.page.mainFrame()
logger.setLevel(log_level)
if self.display:
self.webview = QtWebKit.QWebView()
self.webview.setPage(self.page)
self.webview.show()
示例9: set_cookies_from_url
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)
示例10: _MozillaCookieJar_to_QnetworkCookieJar
def _MozillaCookieJar_to_QnetworkCookieJar(cookie_file):
def line2qcookie(line):
domain,initial_dot,path,isSecure,expires,name,value=line.split()
isSecure=(isSecure=="TRUE")
dt=QDateTime()
dt.setTime_t(int(expires))
expires=dt
c=QNetworkCookie()
c.setDomain(domain)
c.setPath(path)
c.setSecure(isSecure)
c.setExpirationDate(expires)
c.setName(name)
c.setValue(value)
return c
cj=QNetworkCookieJar()
if os.path.exists(cookie_file):
cj.setAllCookies([line2qcookie(line) for line in open(cookie_file) if not line.startswith("#") and line and not line.isspace()])
#~ print cj.allCookies()
else:
raise IOError("File not found: %s"%cookie_file)
return cj
示例11: cookiesForUrl
def cookiesForUrl(self, url):
"""
Public method to get the cookies for a URL.
@param url URL to get cookies for (QUrl)
@return list of cookies (list of QNetworkCookie)
"""
if not self.__loaded:
self.load()
globalSettings = QWebSettings.globalSettings()
if globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled):
return []
return QNetworkCookieJar.cookiesForUrl(self, url)
示例12: __init__
def __init__(self, user_agent=default_user_agent, wait_timeout=8,
wait_callback=None, log_level=logging.WARNING, display=False,
viewport_size=(800,600)):
self.http_resources = []
self.user_agent = user_agent
self.wait_timeout = wait_timeout
self.wait_callback = wait_callback
self.loaded = True
if not 'DISPLAY' in os.environ and not hasattr(Ghost, 'xvfb'):
try:
os.environ['DISPLAY'] = ':99'
Ghost.xvfb = subprocess.Popen(['Xvfb', ':99'])
except OSError:
raise Exception('Xvfb is required to a ghost run oustside ' +\
'an X instance')
self.display = display
self.app = QApplication(['ghost'])
self.page = GhostWebPage(self.app)
QtWebKit.QWebSettings.setMaximumPagesInCache(0)
QtWebKit.QWebSettings.setObjectCacheCapacities(0, 0, 0);
self.set_viewport_size(*viewport_size)
self.page.loadFinished.connect(self._page_loaded)
self.page.loadStarted.connect(self._page_load_started)
self.manager = self.page.networkAccessManager()
self.manager.finished.connect(self._request_ended)
self.cookie_jar = QNetworkCookieJar()
self.manager.setCookieJar(self.cookie_jar)
self.main_frame = self.page.mainFrame()
logger.setLevel(log_level)
if self.display:
self.webview = QtWebKit.QWebView()
self.webview.setPage(self.page)
self.webview.show()
示例13: _load
def _load(self):
self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
self.cookie.setDomain('.shoutcast.com')
self.cookie.setExpirationDate(QDateTime())
self.cookie.setPath('/')
self.webView = QWebView(self)
self.webPage = self.webView.page()
self.cookiejar = QNetworkCookieJar()
self.cookiejar.setAllCookies([self.cookie])
self.webPage.networkAccessManager().setCookieJar(self.cookiejar)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.webView)
self.webView.load(QUrl(HOMEURL))
self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)
示例14: __init__
def __init__(self, gui=False):
if not Kit._app:
Kit._app = QApplication([])
manager = KitNetworkAccessManager()
manager.finished.connect(self.network_reply_handler)
self.cookie_jar = QNetworkCookieJar()
manager.setCookieJar(self.cookie_jar)
self.page = KitPage()
self.page.setNetworkAccessManager(manager)
self.view = KitWebView()
self.view.setPage(self.page)
self.view.setApplication(Kit._app)
if gui:
self.view.show()
示例15: __init__
def __init__(self, gui=False, traffic_rules=None):
if not WKitScope.app:
raise InternalError('You should use Browser instance'
' inside `with WKitScope():` block')
self.app = WKitScope.app
self.manager = WKitNetworkAccessManager(traffic_rules=traffic_rules)
self.manager.finished.connect(self.handle_finished_network_reply)
self.cookie_jar = QNetworkCookieJar()
self.manager.setCookieJar(self.cookie_jar)
self.page = WKitWebPage()
self.page.setNetworkAccessManager(self.manager)
self.page.loadFinished.connect(self.handle_page_load_finished)
self.view = WKitWebView()
self.view.setPage(self.page)
self.view.setApplication(self.app)
self._response = None
self.gui = gui
if gui:
self.view.show()