(self, request, spider)
| 258 | return self.crawler.spider.state[self.remote_keys_key] |
| 259 | |
| 260 | def process_request(self, request, spider): |
| 261 | if 'splash' not in request.meta: |
| 262 | return |
| 263 | |
| 264 | if request.method not in {'GET', 'POST'}: |
| 265 | logger.warning( |
| 266 | "Currently only GET and POST requests are supported by " |
| 267 | "SplashMiddleware; %(request)s will be handled without Splash", |
| 268 | {'request': request}, |
| 269 | extra={'spider': spider} |
| 270 | ) |
| 271 | return request |
| 272 | |
| 273 | if request.meta.get("_splash_processed"): |
| 274 | # don't process the same request more than once |
| 275 | return |
| 276 | |
| 277 | splash_options = request.meta['splash'] |
| 278 | request.meta['_splash_processed'] = True |
| 279 | |
| 280 | slot_policy = splash_options.get('slot_policy', self.slot_policy) |
| 281 | self._set_download_slot(request, request.meta, slot_policy) |
| 282 | |
| 283 | args = splash_options.setdefault('args', {}) |
| 284 | |
| 285 | if '_replaced_args' in splash_options: |
| 286 | # restore arguments before sending request to the downloader |
| 287 | load_args = {} |
| 288 | save_args = [] |
| 289 | local_arg_fingerprints = {} |
| 290 | for name in splash_options['_replaced_args']: |
| 291 | fp = args[name] |
| 292 | # Use remote Splash argument cache: if Splash key |
| 293 | # for a value is known then don't send the value to Splash; |
| 294 | # if it is unknown then try to save the value on server using |
| 295 | # ``save_args``. |
| 296 | if fp in self._remote_keys: |
| 297 | load_args[name] = self._remote_keys[fp] |
| 298 | del args[name] |
| 299 | else: |
| 300 | save_args.append(name) |
| 301 | args[name] = self._argument_values[fp] |
| 302 | |
| 303 | local_arg_fingerprints[name] = fp |
| 304 | |
| 305 | if load_args: |
| 306 | args['load_args'] = load_args |
| 307 | if save_args: |
| 308 | args['save_args'] = save_args |
| 309 | splash_options['_local_arg_fingerprints'] = local_arg_fingerprints |
| 310 | |
| 311 | del splash_options['_replaced_args'] # ?? |
| 312 | |
| 313 | args.setdefault('url', request.url) |
| 314 | if request.method == 'POST': |
| 315 | args.setdefault('http_method', request.method) |
| 316 | # XXX: non-UTF8 request bodies are not supported now |
| 317 | args.setdefault('body', request.body.decode('utf8')) |
nothing calls this directly
no test coverage detected