本文整理汇总了Python中gi.repository.WebKit.get_default_session方法的典型用法代码示例。如果您正苦于以下问题:Python WebKit.get_default_session方法的具体用法?Python WebKit.get_default_session怎么用?Python WebKit.get_default_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.WebKit
的用法示例。
在下文中一共展示了WebKit.get_default_session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: global_webkit_init
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def global_webkit_init():
""" this sets the defaults for webkit, its important that this gets
run if you want a secure webkit session
"""
session = WebKit.get_default_session()
# add security by default (see bugzilla #666280 and #666276)
# enable certificates validation in webkit views unless specified otherwise
if not "SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK" in os.environ:
session = webkit.get_default_session()
session.set_property(
"ssl-ca-file", "/etc/ssl/certs/ca-certificates.crt")
else:
# WARN the user!! Do not remove this
LOG.warning("SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK " +
"has been specified, all purchase transactions " +
"are now INSECURE and UNENCRYPTED!!")
# cookies by default
fname = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "cookies.txt")
# clear cookies again in a new session, see #1018347 comment #4
# there is no "logout" support right now on any of the USC pages
try:
os.remove(fname)
except OSError:
pass
cookie_jar = Soup.CookieJarText.new(fname, False)
session.add_feature(cookie_jar)
# optional session debugging
if "SOFTWARE_CENTER_DEBUG_WEBKIT" in os.environ:
# alternatively you can use HEADERS, BODY here
logger = Soup.Logger.new(Soup.LoggerLogLevel.BODY, -1)
logger.attach(session)
示例2: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self):
GObject.GObject.__init__(self)
self.window = window = Gtk.Window()
self.inspectorWindow = Gtk.Window()
self.session = WebKit.get_default_session()
self.zcbrowser = MBCZeroconfBrowser()
self.services = {}
self.zcbrowser.connect('service-up', self.on_new_service)
self.zcbrowser.connect('service-down', self.on_service_removed)
self.webView = webView = WebKit.WebView()
window.add(webView)
window.set_decorated(False)
window.set_title('MBC - Vineyard')
self.init_settings()
self.add_inspector()
self.add_cookie_jar()
webView.connect ("navigation-policy-decision-requested", self.decide_policy_cb)
webView.connect ("close-web-view", lambda app: Gtk.main_quit())
webView.connect ("load-error", self.load_error_cb)
webView.connect ("document-load-finished", self.load_finished_cb)
webView.connect ("window-object-cleared", self.window_object_cleared_cb)
webView.set_property ("view-mode", WebKit.WebViewViewMode.FULLSCREEN)
window.connect ("destroy", lambda app: Gtk.main_quit())
window.show_all ()
window.fullscreen ()
webView.grab_focus()
# replace this with magic.
webView.load_uri('http://localhost:3000/')
示例3: setup_webkit_session
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def setup_webkit_session(self):
session = WebKit.get_default_session()
cache = get_or_create_directory(op.join(
GLib.get_user_cache_dir(), 'fogger', self.app.uuid))
cookie_jar = Soup.CookieJarText.new(op.join(cache, 'WebkitSession'), False)
session.add_feature(cookie_jar)
session.props.max_conns_per_host = 8
示例4: test_have_cookie_jar
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def test_have_cookie_jar(self):
# ensure we have a cookie jar available
session = WebKit.get_default_session()
cookie_jars = [feature
for feature in session.get_features(Soup.SessionFeature)
if isinstance(feature, Soup.CookieJar)]
self.assertEqual(len(cookie_jars), 1)
示例5: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self, *args, **kwargs):
super(Messenger, self).__init__(*args, **kwargs)
self.connect("destroy", Gtk.main_quit)
self.connect("key-press-event", self.key_pressed)
self.set_size_request(800, 600)
self.set_icon_from_file("/opt/messenger/messenger.svg")
if not os.path.exists(os.path.expanduser("~/.messenger")) or not os.path.isdir(os.path.expanduser("~/.messenger")):
os.makedirs(os.path.expanduser("~/.messenger"))
open(os.path.expanduser("~/.messenger/cookies.txt"), "a").close()
cookiejar = Soup.CookieJarText.new(os.path.expanduser("~/.messenger/cookies.txt"), False)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
session = WebKit.get_default_session()
session.add_feature(cookiejar)
self.webview = WebKit.WebView()
self.webview.get_settings().set_property("enable-smooth-scrolling", True)
self.webview.get_settings().set_property("enable-default-context-menu", False)
self.webview.connect("title-changed", self.title_changed)
self.webview.connect("load-finished", self.load_finished)
self.webview.connect("new-window-policy-decision-requested", self.link_clicked)
self.scrolled_window = Gtk.ScrolledWindow()
self.webview.load_uri("https://messenger.com/login")
self.scrolled_window.add(self.webview)
self.add(self.scrolled_window)
self.show_all()
示例6: webkit_set_proxy_uri
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def webkit_set_proxy_uri(scheme = None, host = None, port = None, user = None, passwd = None):
try:
session = WebKit.get_default_session()
if looseVersion(Soup._version) < looseVersion('2.4'):
session.set_property("max-conns", 3)
session.set_property("max-conns-per-host", 1)
else:
session.set_property("max-conns", 10)
session.set_property("max-conns-per-host", 5)
session.set_property("timeout", 10)
if scheme == None:
return True
elif ":" in scheme:
proxy_uri = Soup.URI.new(str(scheme))
elif host:
proxy_uri = Soup.URI.new("http://127.0.0.1")
proxy_uri.set_scheme(str(scheme))
proxy_uri.set_host(str(host))
if port:
proxy_uri.set_port(int(port))
if user:
proxy_uri.set_user(str(user))
if passwd:
proxy_uri.set_password(str(passwd))
session.set_property("proxy-uri", proxy_uri)
return True
except:
exctype, value = sys.exc_info()[:2]
print 'error: webkit_set_proxy_uri: (%s, %s)' % (exctype,value)
return False
示例7: config_soup
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def config_soup(self):
"""Load config values to a soup session"""
soup_session = WebKit.get_default_session()
cid = soup_session.connect("request_queued",
self.on_soup_request_queued)
soup_session.request_queued_cid = cid
sec = SOUP_SECTION
for k in SOUP_PROPERTY_TYPE [int]:
if k in ["cache-size"]:
continue
val = self.config.getint(sec, k)
soup_session.set_property(k, val)
for k in SOUP_PROPERTY_TYPE [bool]:
val = self.config.getboolean(sec, k)
if k == "enable-disk-cache":
if val:
self.load_soup_cache(soup_session)
else:
self.unload_soup_cache(soup_session)
elif k == "enable-persistent-cookie":
if val:
self.load_soup_cookiejar(soup_session)
else:
self.unload_soup_cookiejar(soup_session)
elif k in ["enable-do-not-track"]:
pass
else:
soup_session.set_property(k, val)
示例8: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self, activity, window_xid):
self.parent_window_xid = window_xid
url, title = get_help_url_and_title(activity)
has_local_help = url is not None
self._mode = _MODE_HELP if has_local_help else _MODE_SOCIAL_HELP
Gtk.Window.__init__(self)
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.VERTICAL)
self.add(box)
box.show()
self.set_decorated(False)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_border_width(style.LINE_WIDTH)
self.set_has_resize_grip(False)
width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2
height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2
self.set_size_request(width, height)
self.connect('realize', self.__realize_cb)
self.connect('hide', self.__hide_cb)
self.connect('key-press-event', self.__key_press_event_cb)
toolbar = Toolbar(title, has_local_help)
box.pack_start(toolbar, False, False, 0)
toolbar.show()
toolbar.connect('stop-clicked', self.__stop_clicked_cb)
toolbar.connect('mode-changed', self.__mode_changed_cb)
session = WebKit.get_default_session()
cookie_jar = SoupGNOME.CookieJarSqlite(
filename=os.path.join(env.get_profile_path(),
'social-help.cookies'),
read_only=False)
session.add_feature(cookie_jar)
self._webview = WebKit.WebView()
self._webview.set_full_content_zoom(True)
self._webview.connect('resource-request-starting',
self._resource_request_starting_cb)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.add(self._webview)
scrolled_window.show()
box.pack_start(scrolled_window, True, True, 0)
self._webview.show()
language = self._get_current_language()
if has_local_help:
self._help_url = 'file://' + self._get_help_file(language, url)
self._social_help_url = '{}/goto/{}'.format(
get_social_help_server(), activity.get_bundle_id())
self._webview.connect(
'notify::load-status', self.__load_status_changed_cb)
self._load_mode(self._mode)
示例9: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self):
Gtk.Dialog.__init__(self, _("vk.com authorization"), None, Gtk.DialogFlags.MODAL, ())
ChildTopWindow.__init__(self)
self.set_size_request(550, -1)
self.auth_url = "http://oauth.vk.com/oauth/authorize?" + \
"redirect_uri=http://oauth.vk.com/blank.html&response_type=token&" + \
"client_id=%s&scope=%s" % (self.CLIENT_ID, ",".join(self.SCOPE))
self.web_view = WebKit.WebView()
self.vbox.pack_start(self.web_view, False, False, 0)
self.web_view.connect('resource-load-finished', self.on_load)
session = WebKit.get_default_session()
if FC().proxy_enable and FC().proxy_url:
if FC().proxy_user and FC().proxy_password:
proxy_url = "http://%s:%[email protected]%s" % (FC().proxy_user, FC().proxy_password, FC().proxy_url)
else:
proxy_url = "http://%s" % FC().proxy_url
soup_url = Soup.URI.new(proxy_url)
session.set_property("proxy-uri", soup_url)
else:
session.set_property("proxy-uri", None)
cookiejar = Soup.CookieJarText.new(cookiefile, False)
session.add_feature(cookiejar)
self.access_token = None
self.user_id = None
self.on_load_method_finished = False
示例10: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self, cookie_path="~/.netflix.cookie",
*args, **kwargs):
Gtk.Window.__init__(self, title=sys.argv[1])
icontheme = Gtk.IconTheme.get_default()
self.set_icon_from_file(sys.argv[3])
super(NetflixWindow, self).__init__(*args, **kwargs)
cookiejar = Soup.CookieJarText.new(
os.path.expanduser(cookie_path), False)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
session = WebKit.get_default_session()
session.add_feature(cookiejar)
self.width = int(sys.argv[4])
self.height = int(sys.argv[5])
self.set_default_size(self.width, self.height)
self.connect('destroy', Gtk.main_quit)
self.connect('delete-event', Gtk.main_quit)
self.scroll = Gtk.ScrolledWindow()
self.web = WebKit.WebView()
self.add(self.scroll)
self.scroll.add(self.web)
self.show_all()
self.web.open(sys.argv[2])
示例11: loadSession
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def loadSession(self):
if not os.path.exists(self.pidir):
os.mkdir(self.pidir)
if not os.path.exists(self.sessiondir):
os.mkdir(self.sessiondir)
session = WebKit.get_default_session()
cookiepath = self.sessiondir + "/" + "cookies"
cookiejar = Soup.CookieJarText(filename=cookiepath, read_only=False)
session.add_feature(cookiejar)
示例12: global_webkit_init
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def global_webkit_init():
session = WebKit.get_default_session()
fname = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "cookies.txt")
# clear cookies again in a new session, see #1018347 comment #4
# there is no "logout" support right now on any of the USC pages
try:
os.remove(fname)
except OSError:
pass
cookie_jar = Soup.CookieJarText.new(fname, False)
session.add_feature(cookie_jar)
示例13: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self):
# Create GTK window
self.window = Gtk.Window()
self.window.set_title('Slacker')
self.window.connect('destroy', Gtk.main_quit) # Quit cleanly
self.window.set_default_size(1200,720)
# Create persistent cookie storage
cookiejar = Soup.CookieJarText.new(self.cookie_path, False)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
session = WebKit.get_default_session()
session.add_feature(cookiejar)
示例14: setup_features
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def setup_features(self):
try:
session = WebKit.get_default_session()
cookie = Soup.CookieJarText(filename=os.path.join(CONFIG_ROOT, 'cookies'))
session.add_feature(cookie)
self._cache = Soup.Cache(cache_dir=os.path.join(CONFIG_ROOT, 'cache'),
cache_type=Soup.CacheType.SHARED)
session.add_feature(self._cache)
self._cache.set_max_size(10 * 1024 * 1024)
self._cache.load()
except Exception, e:
log.error("setup_features failed with %s" % e)
示例15: __init__
# 需要导入模块: from gi.repository import WebKit [as 别名]
# 或者: from gi.repository.WebKit import get_default_session [as 别名]
def __init__(self, com_dict: object):
""" Initialize the process.
"""
from gi.repository import Soup as libsoup
from gi.repository import WebKit as libwebkit
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GLib as glib
self._icon_db = libwebkit.get_favicon_database()
cookiejar = libsoup.CookieJar()
cookiejar.set_accept_policy(libsoup.CookieJarAcceptPolicy.NO_THIRD_PARTY)
session = libwebkit.get_default_session()
print("SESSION: ", session)
session.add_feature(cookiejar)
session.set_property('ssl-use-system-ca-file', True)
session.set_property('ssl-strict', True)
print("SESSION PROP", session.get_property('tls-database'))
# session.connect('connection-created', self._soup_connection)
# proxy_uri = libsoup.URI.new(os.getenv('http_proxy'))
# session.set_property('proxy-uri', proxy_uri)
self._libsoup = libsoup
self._gtk = gtk
self._gdk = gdk
self._glib = glib
self._libwebkit = libwebkit
self._dict = com_dict
self._coms = []
self._pid = multiprocessing.current_process().pid
self._windows = []
for socket_id, com_pipe in self._dict.items():
print("CREATING: ", socket_id, com_pipe)
try:
com_pipe.send(('pid', self._pid))
except BrokenPipeError as err:
print("BROKEN PIPE: ", err, ' on PIPE ', com_pipe)
continue
self._windows.append(self._create_window(socket_id, com_pipe))