Exemplo n.º 1
0
 def __init__(self, network_manager, splash_proxy_factory, render_options, verbosity):
     self.tab = BrowserTab(
         network_manager=network_manager,
         splash_proxy_factory=splash_proxy_factory,
         verbosity=verbosity,
         render_options=render_options,
     )
     self.render_options = render_options
     self.verbosity = verbosity
     self.deferred = self.tab.deferred
Exemplo n.º 2
0
    def open_tab(self, meta=None):
        if meta is None:
            meta = {}
        manager = PortiaNetworkManager(request_middlewares=[],
                                       response_middlewares=[],
                                       verbosity=defaults.VERBOSITY)
        manager.setCache(None)

        data = {}
        data['uid'] = id(data)

        self.factory[self].tab = BrowserTab(
            network_manager=manager,
            splash_proxy_factory=None,
            verbosity=0,
            render_options=RenderOptions(data, defaults.MAX_TIMEOUT),
            visible=True,
        )
        manager.tab = self.tab
        main_frame = self.tab.web_page.mainFrame()
        cookiejar = PortiaCookieJar(self.tab.web_page, self)
        manager.cookiejar = cookiejar
        manager.setCookieJar(cookiejar)
        if meta.get('cookies'):
            cookiejar.put_client_cookies(meta['cookies'])

        main_frame.loadStarted.connect(self._on_load_started)
        self.js_api = PortiaJSApi(self)
        main_frame.javaScriptWindowObjectCleared.connect(
            self.populate_window_object)

        self.tab.set_images_enabled(True)
        self.tab.set_viewport(meta.get('viewport') or _DEFAULT_VIEWPORT)
        self.tab.set_user_agent(meta.get('user_agent') or _DEFAULT_USER_AGENT)
        self.tab.loaded = False
Exemplo n.º 3
0
 def __init__(self, network_manager, splash_proxy_factory, render_options, verbosity):
     self.tab = BrowserTab(
         network_manager=network_manager,
         splash_proxy_factory=splash_proxy_factory,
         verbosity=verbosity,
         render_options=render_options,
     )
     self.render_options = render_options
     self.verbosity = verbosity
     self.deferred = self.tab.deferred
Exemplo n.º 4
0
def init_browser(network_manager_factory):
    # TODO: support the same command-line options as HTTP server.

    # from splash.server import start_logging
    # class opts(object):
    #    logfile = "./kernel.log"
    # start_logging(opts)

    proxy_factory = None  # TODO

    data = {}
    data['uid'] = id(data)

    tab = BrowserTab(
        network_manager=network_manager_factory(),
        splash_proxy_factory=proxy_factory,
        verbosity=2,  # TODO
        render_options=RenderOptions(data, defaults.MAX_TIMEOUT),  # TODO: timeout
        visible=True,
    )
    return tab
Exemplo n.º 5
0
class RenderScript(object):
    """
    Interface that all render scripts must implement.
    """
    __metaclass__ = abc.ABCMeta

    default_min_log_level = 2

    def __init__(self, network_manager, splash_proxy_factory, render_options,
                 verbosity):
        self.tab = BrowserTab(
            network_manager=network_manager,
            splash_proxy_factory=splash_proxy_factory,
            verbosity=verbosity,
            render_options=render_options,
        )
        self.render_options = render_options
        self.verbosity = verbosity
        self.deferred = self.tab.deferred

    @abc.abstractmethod
    def start(self, **kwargs):
        """ This method is called by Pool when script should begin """
        pass

    def log(self, text, min_level=None):
        if min_level is None:
            min_level = self.default_min_log_level
        self.tab.logger.log(text, min_level=min_level)

    def return_result(self, result):
        self.tab.return_result(result)

    def return_error(self, error=None):
        self.tab.return_error(error)

    def close(self):
        """
        This method is called by a Pool after the rendering is done and
        the RenderScript object is no longer needed.
        """
        self.tab.close()
Exemplo n.º 6
0
class RenderScript(object):
    """
    Interface that all render scripts must implement.
    """
    __metaclass__ = abc.ABCMeta

    default_min_log_level = 2

    def __init__(self, network_manager, splash_proxy_factory, render_options, verbosity):
        self.tab = BrowserTab(
            network_manager=network_manager,
            splash_proxy_factory=splash_proxy_factory,
            verbosity=verbosity,
            render_options=render_options,
        )
        self.render_options = render_options
        self.verbosity = verbosity
        self.deferred = self.tab.deferred

    @abc.abstractmethod
    def start(self, **kwargs):
        """ This method is called by Pool when script should begin """
        pass

    def log(self, text, min_level=None):
        if min_level is None:
            min_level = self.default_min_log_level
        self.tab.logger.log(text, min_level=min_level)

    def return_result(self, result):
        self.tab.return_result(result)

    def return_error(self, error=None):
        self.tab.return_error(error)

    def close(self):
        """
        This method is called by a Pool after the rendering is done and
        the RenderScript object is no longer needed.
        """
        self.tab.close()