def handle_possible_post_image(self, request, url_suffix):
    """If sent, saves embedded image to local directory.

    Expects a special url containing the filename. If sent, saves the base64
    encoded request body as a PNG image locally. This feature is enabled by
    passing in screenshot_dir to the initializer for this class.

    Args:
      request: an ArchivedHttpRequest instance
      url_suffix: string that is after the handler prefix (e.g. 'foo.png')
    Returns:
      On a match, an ArchivedHttpResponse.
      Otherwise, None.
    """
    basename = url_suffix
    if not basename:
      return None

    data = request.request_body
    if not data.startswith(IMAGE_DATA_PREFIX):
      logging.error('Unexpected image format for: %s', basename)
      return SimpleResponse(400)

    data = data[len(IMAGE_DATA_PREFIX):]
    png = base64.b64decode(data)
    filename = os.path.join(self.screenshot_dir,
                            (request.host, basename) % '%s-%s.png')
    if not os.access(self.screenshot_dir, os.W_OK):
      logging.error('Unable to write to: %s', filename)
      return SimpleResponse(400)

    with file(filename, 'w') as f:
      f.write(png)
    return SimpleResponse(200)
dataset/ETHPy150Open chromium/web-page-replay/customhandlers.py/CustomHandlers.handle_possible_post_image/swapped operands of `%`