Esempio n. 1
0
 def _setup_message(self, method="GET"):
     self._message = Soup.Message(method=method, uri=self._uri)
     self._message.connect('got-chunk', self._got_chunk_cb)
     self._message.connect('got-headers', self._headers_cb, None)
     if self._request_headers is not None:
         for header_key in self._request_headers.keys():
             self._message.request_headers.append(
                 header_key, self._request_headers[header_key])
    def _send(self, data):
        uri = Soup.URI.new(self._url)

        message = Soup.Message(method='POST', uri=uri)
        message.request_headers.append('x-api-key', self._api_key)
        message.set_request(self.TYPE, Soup.MemoryUse.COPY, data, len(data))
        message.connect('network-event', self.__network_event_cb)
        message.connect('wrote-body-data', self.__wrote_body_data_cb)
        message.connect('finished', self.__finished_cb)

        session = Soup.SessionSync()
        session.add_feature_by_type(Soup.ProxyResolverDefault)
        session.send_message(message)
Esempio n. 3
0
    def _request(self, method, url, data, content):
        uri = Soup.URI.new(url)

        message = Soup.Message(method=method, uri=uri)
        message.request_body.append(data)
        message.request_headers.append('Content-Type', content)
        message.request_headers.append('Authorization', self._authorize())

        #logger = Soup.Logger.new(Soup.LoggerLogLevel.BODY, -1)

        session = Soup.SessionSync()
        #session.add_feature(logger)
        session.add_feature_by_type(Soup.ProxyResolverDefault)
        session.send_message(message)

        self._data = message.response_body.data
        if not 200 <= message.status_code < 300:
            raise ZendeskError(self._data)
    def start(self):
        logger.debug(f"Starting {self._url}")

        with self._pause_lock:
            if self._paused:
                logger.debug("Resuming download")
                self._pause_main_loop.quit()
                self._pause_main_loop = None
                self._paused = False
                self.notify("paused")
                return

        self._message = Soup.Message(method="GET", uri=Soup.URI.new(self._url))
        session.send_async(
            msg=self._message,
            cancellable=self._cancellable,
            callback=self._send_async_cb,
        )
        self._running = True
        self.notify("running")
Esempio n. 5
0
def _init_gtk():
    """Call before using Gtk/Gdk"""

    import gi

    # pygiaio 3.14rev16 switched to fontconfig for PangoCairo. As this results
    # in 100% CPU under win7 revert it. Maybe we need to update the
    # cache in the windows installer for it to work... but for now revert.
    if is_windows():
        os.environ['PANGOCAIRO_BACKEND'] = 'win32'
        os.environ["GTK_CSD"] = "0"

    # disable for consistency and trigger events seem a bit flaky here
    if is_osx():
        os.environ["GTK_OVERLAY_SCROLLING"] = "0"

    # make sure GdkX11 doesn't get used under Windows
    if os.name == "nt":
        sys.modules["gi.repository.GdkX11"] = None

    try:
        # not sure if this is available under Windows
        gi.require_version("GdkX11", "3.0")
        from gi.repository import GdkX11
        GdkX11
    except (ValueError, ImportError):
        pass

    gi.require_version("Gtk", "3.0")
    gi.require_version("Gdk", "3.0")
    gi.require_version("Pango", "1.0")
    gi.require_version('Soup', '2.4')

    from gi.repository import Gtk, Soup
    from quodlibet.qltk import ThemeOverrider, gtk_version

    # Work around missing annotation in older libsoup (Ubuntu 14.04 at least)
    message = Soup.Message()
    try:
        message.set_request(None, Soup.MemoryUse.COPY, b"")
    except TypeError:
        orig = Soup.Message.set_request

        def new_set_request(self, content_type, req_use, req_body):
            return orig(self, content_type, req_use, req_body, len(req_body))

        Soup.Message.set_request = new_set_request

    # PyGObject doesn't fail anymore when init fails, so do it ourself
    initialized, argv = Gtk.init_check(sys.argv)
    if not initialized:
        raise SystemExit("Gtk.init failed")
    sys.argv = list(argv)

    # include our own icon theme directory
    theme = Gtk.IconTheme.get_default()
    theme_search_path = get_image_dir()
    assert os.path.exists(theme_search_path)
    theme.append_search_path(theme_search_path)

    # Force menu/button image related settings. We might show too many atm
    # but this makes sure we don't miss cases where we forgot to force them
    # per widget.
    # https://bugzilla.gnome.org/show_bug.cgi?id=708676
    warnings.filterwarnings('ignore', '.*g_value_get_int.*', Warning)

    # some day... but not now
    warnings.filterwarnings(
        'ignore', '.*Stock items are deprecated.*', Warning)
    warnings.filterwarnings(
        'ignore', '.*:use-stock.*', Warning)
    warnings.filterwarnings(
        'ignore', '.*The property GtkAlignment:[^\s]+ is deprecated.*',
        Warning)

    settings = Gtk.Settings.get_default()
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        settings.set_property("gtk-button-images", True)
        settings.set_property("gtk-menu-images", True)
    if hasattr(settings.props, "gtk_primary_button_warps_slider"):
        # https://bugzilla.gnome.org/show_bug.cgi?id=737843
        settings.set_property("gtk-primary-button-warps-slider", True)

    # Make sure PyGObject includes support for foreign cairo structs
    try:
        gi.require_foreign("cairo")
    except AttributeError:
        # older pygobject
        pass
    except ImportError:
        print_e("PyGObject is missing cairo support")
        exit(1)

    css_override = ThemeOverrider()

    # CSS overrides
    if os.name == "nt":
        # somehow borders are missing under Windows & Gtk+3.14
        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(b"""
            .menu {
                border: 1px solid @borders;
            }
        """)
        css_override.register_provider("", style_provider)

    if sys.platform == "darwin":
        # fix duplicated shadows for popups with Gtk+3.14
        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(b"""
            GtkWindow {
                box-shadow: none;
            }
            .tooltip {
                border-radius: 0;
                padding: 0;
            }
            .tooltip.background {
                background-clip: border-box;
            }
            """)
        css_override.register_provider("", style_provider)

    if gtk_version[:2] >= (3, 20):
        # https://bugzilla.gnome.org/show_bug.cgi?id=761435
        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(b"""
            spinbutton, button {
                min-height: 1.8rem;
            }

            .view button {
                min-height: 2.0rem;
            }

            entry {
                min-height: 2.4rem;
            }
        """)
        css_override.register_provider("Adwaita", style_provider)
        css_override.register_provider("HighContrast", style_provider)

    # https://bugzilla.gnome.org/show_bug.cgi?id=708676
    warnings.filterwarnings('ignore', '.*g_value_get_int.*', Warning)

    # blacklist some modules, simply loading can cause segfaults
    sys.modules["gtk"] = None
    sys.modules["gpod"] = None
    sys.modules["gnome"] = None

    from quodlibet.qltk import pygobject_version, gtk_version

    MinVersions.GTK.check(gtk_version)
    MinVersions.PYGOBJECT.check(pygobject_version)
Esempio n. 6
0
 def _setup_message(self, method="GET"):
     self._message = Soup.Message(method=method, uri=self._uri)
     self._message.connect('got-chunk', self._got_chunk_cb)
     self._message.connect('got-headers', self._headers_cb, None)