コード例 #1
0
ファイル: chrome_html.py プロジェクト: Daniel1989/chromium
  def Parse(self):
    """Parses and inlines the represented file."""

    filename = self.GetInputPath()
    # If there is a grd_node, prefer its GetInputPath(), as that may do more
    # processing to make the call to ToRealPath() below work correctly.
    if self.grd_node:
      filename = self.grd_node.GetInputPath()
    if self.filename_expansion_function:
      filename = self.filename_expansion_function(filename)
    # Hack: some unit tests supply an absolute path and no root node.
    if not os.path.isabs(filename):
      filename = self.grd_node.ToRealPath(filename)
    if self.flatten_html_:
      self.inlined_text_ = html_inline.InlineToString(
          filename,
          self.grd_node,
          allow_external_script = self.allow_external_script_,
          strip_whitespace=True,
          preprocess_only = self.preprocess_only_,
          rewrite_function=lambda fp, t, d: ProcessImageSets(
              fp, t, self.scale_factors_, d,
              filename_expansion_function=self.filename_expansion_function),
          filename_expansion_function=self.filename_expansion_function)
    else:
      distribution = html_inline.GetDistribution()
      self.inlined_text_ = ProcessImageSets(
          os.path.dirname(filename),
          util.ReadFile(filename, 'utf-8'),
          self.scale_factors_,
          distribution,
          filename_expansion_function=self.filename_expansion_function)
コード例 #2
0
    def Parse(self):
        """Parses and inlines the represented file."""

        filename = self.GetInputPath()
        if self.filename_expansion_function:
            filename = self.filename_expansion_function(filename)
        # Hack: some unit tests supply an absolute path and no root node.
        if not os.path.isabs(filename):
            filename = self.grd_node.ToRealPath(filename)
        if self.flatten_html_:
            self.inlined_text_ = html_inline.InlineToString(
                filename,
                self.grd_node,
                allow_external_script=self.allow_external_script_,
                rewrite_function=lambda fp, t, d: ProcessImageSets(
                    fp,
                    t,
                    self.scale_factors_,
                    d,
                    filename_expansion_function=self.
                    filename_expansion_function),
                filename_expansion_function=self.filename_expansion_function)
        else:
            distribution = html_inline.GetDistribution()
            self.inlined_text_ = ProcessImageSets(
                os.path.dirname(filename),
                util.ReadFile(filename, 'utf-8'),
                self.scale_factors_,
                distribution,
                filename_expansion_function=self.filename_expansion_function)