cardinal_pythonlib.openxml.grep_in_openxml


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Performs a grep (global-regular-expression-print) search of files in OpenXML format, which is to say inside ZIP files. See the command-line help for details.

Version history:

  • Written 28 Sep 2017.

Notes:

  • use the vbindiff tool to show how two binary files differ.

class cardinal_pythonlib.openxml.grep_in_openxml.GrepReportContent(value)[source]

An enumeration.

class cardinal_pythonlib.openxml.grep_in_openxml.GrepSearchSubstrate(value)[source]

An enumeration.

cardinal_pythonlib.openxml.grep_in_openxml.main() None[source]

Command-line handler for the grep_in_openxml tool. Use the --help option for help.

cardinal_pythonlib.openxml.grep_in_openxml.parse_zip(zipfilename: str, mode: GrepMode) None[source]

Implement a “grep within an OpenXML file” for a single OpenXML file, which is by definition a .zip file.

Parameters:
  • zipfilename – Name of the OpenXML (zip) file.

  • mode – Object configuring grep-type mode.

cardinal_pythonlib.openxml.grep_in_openxml.report_hit_filename(zipfilename: str, inner_filename: str, display_inner_filename: bool) None[source]

For “hits”: prints either the .zip filename, or the .zip filename and the inner filename.

Parameters:
  • zipfilename – Filename of the outer OpenXML/zip file.

  • inner_filename – Filename of the inner file.

  • display_inner_filename – If True, show both outer and inner filename; if False, show just the outer (OpenXML/zip) filename.

cardinal_pythonlib.openxml.grep_in_openxml.report_line(zipfilename: str, inner_filename: str, line: bytes | str, display_no_filename: bool, display_inner_filename: bool) None[source]

Prints a line from a file, with the .zip filename and optionally also the inner filename.

Parameters:
  • zipfilename – Filename of the .zip file.

  • inner_filename – Filename of the inner file.

  • line – The line from the inner file.

  • display_no_filename – Skip display of the outer filename.

  • display_inner_filename – (Only applicable if no_filename is False.) If True, show both outer and inner filename; if False, show just the outer (OpenXML/zip) filename.

cardinal_pythonlib.openxml.grep_in_openxml.report_miss_filename(zipfilename: str) None[source]

For “misses”: prints the zip filename.