Skip to main content

libraries.rebuild.rebuild

ct​

io​

os​

Union​

glasswall​

dft​

utils​

log​

Library​

errors​

successes​

Rebuild Objects​

class Rebuild(Library)

A high level Python wrapper for Glasswall Rebuild / Classic.

__init__​

def __init__(library_path: str)

validate_licence​

def validate_licence()

Validates the licence of the library by attempting to call protect_file on a known supported file.

Raises:

  • RebuildError - If the licence could not be validated.

version​

def version()

Returns the Glasswall library version.

Returns:

  • version str - The Glasswall library version.

determine_file_type​

def determine_file_type(input_file: Union[str, bytes, bytearray, io.BytesIO],
as_string: bool = False,
raise_unsupported: bool = True)

Returns an int representing the file type / file format of a file.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file, can be a local path.
  • as_string bool, optional - Return file type as string, eg: "bmp" instead of: 29. Defaults to False.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_type Union[int, str] - The file format.

get_content_management_policy​

def get_content_management_policy()

Gets the current content management configuration.

Returns:

  • xml_string str - The XML string of the current content management configuration.

set_content_management_policy​

def set_content_management_policy(input_file: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None)

Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.

Arguments:

  • input_file Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.

Returns:

  • status int - The result of the Glasswall API call.

protect_file​

def protect_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Protects a file using the current content management configuration, returning the file bytes. The protected file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the protected file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The protected file bytes.

protect_directory​

def protect_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory in protect mode using the given content management policy. The protected files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to protect.
  • output_directory Union[None, str] - The output directory where the protected file will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • protected_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

analyse_file​

def analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses a file, returning the analysis bytes. The analysis is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the analysis file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The analysis file bytes.

analyse_directory​

def analyse_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses all files in a directory and its subdirectories. The analysis files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to analyse.
  • output_directory Union[None, str] - The output directory where the analysis files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • analysis_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

export_file​

def export_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Export a file, returning the .zip file bytes. The .zip file is written to output_file.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the .zip file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The exported .zip file.

export_directory​

def export_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Exports all files in a directory and its subdirectories. The export files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to export.
  • output_directory Union[None, str] - The output directory where the export files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • export_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

import_file​

def import_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Import a .zip file, constructs a file from the .zip file and returns the file bytes. The file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The .zip input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the constructed file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The imported file bytes.

import_directory​

def import_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Imports all files in a directory and its subdirectories. Files are expected as .zip but this is not forced. The constructed files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to import.
  • output_directory Union[None, str] - The output directory where the constructed files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • import_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

GWFileErrorMsg​

def GWFileErrorMsg()

Retrieve the Glasswall Process error message.

Returns:

  • error_message str - The Glasswall Process error message.

_GWFileToFileAnalysisAndProtect​

def _GWFileToFileAnalysisAndProtect(input_file: str, file_type: str,
output_file: str,
output_analysis_report: str)

This function Manages the specified file and carries out an Analysis Audit, saving the results to the specified file locations.

Arguments:

  • input_file str - The input file path or bytes.
  • output_file str - The output file path where the protected file will be written.
  • output_analysis_report str - The output file path where the analysis report will be written.

Returns:

  • status int - The result of the Glasswall API call.

_GWFileAnalysisAndProtect​

def _GWFileAnalysisAndProtect(input_file: str, file_type: str)

This function Manages the specified file and carries out an Analysis Audit, returning both outputs to the specified memory locations.

Arguments:

  • input_file str - The input file path or bytes.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attributes 'input_file', 'file_type', 'output_file_buffer', 'output_file_buffer_length', 'output_report_buffer', 'output_report_buffer_length', 'output_file', 'analysis_file'.