Example #1
0
    def __init__(self,
                 filters_path=None,
                 verbosity=None,
                 allowed_schemes=None):
        verbosity = defaults.VERBOSITY if verbosity is None else verbosity
        self.verbosity = verbosity
        self.request_middlewares = []
        self.response_middlewares = []
        self.adblock_rules = None

        # Initialize request and response middlewares
        allowed_schemes = (defaults.ALLOWED_SCHEMES if allowed_schemes is None
                           else allowed_schemes.split(','))
        if allowed_schemes:
            self.request_middlewares.append(
                AllowedSchemesMiddleware(allowed_schemes, verbosity=verbosity))

        if self.verbosity >= 2:
            self.request_middlewares.append(RequestLoggingMiddleware())

        self.request_middlewares.append(
            AllowedDomainsMiddleware(verbosity=verbosity))
        self.request_middlewares.append(ResourceTimeoutMiddleware())
        self.request_middlewares.append(ResponseBodyTrackingMiddleware())

        if filters_path is not None:
            self.adblock_rules = AdblockRulesRegistry(filters_path,
                                                      verbosity=verbosity)
            self.request_middlewares.append(
                AdblockMiddleware(self.adblock_rules, verbosity=verbosity))

        self.response_middlewares.append(ContentTypeMiddleware(self.verbosity))
Example #2
0
    def __init__(self, filters_path, allowed_schemes, verbosity):
        super(SplashQNetworkAccessManager, self).__init__(verbosity=verbosity)

        self.request_middlewares = []
        if self.verbosity >= 2:
            self.request_middlewares.append(RequestLoggingMiddleware())

        if allowed_schemes:
            self.request_middlewares.append(
                AllowedSchemesMiddleware(allowed_schemes, verbosity=verbosity))

        self.request_middlewares.append(
            AllowedDomainsMiddleware(verbosity=verbosity))

        if filters_path is not None:
            self.adblock_rules = AdblockRulesRegistry(filters_path,
                                                      verbosity=verbosity)
            self.request_middlewares.append(
                AdblockMiddleware(self.adblock_rules, verbosity=verbosity))