libraries
os_info
os_info = {
"Linux": {
"archive_manager": {
"file_name": "libglasswall.archi ...
Library
class Library()
A Glasswall library.
__init__
def __init__(library_path: str)
load_library
def load_library(library_path: str)
Success
class Success(WordSearchSuccess)
WordSearch success code 1.
success_codes
success_codes = {
1: Success,
}
UnknownErrorCode
class UnknownErrorCode(WordSearchError)
Unknown error code.
Fail
class Fail(WordSearchError)
WordSearch error code 0.
DisallowedItemFound
class DisallowedItemFound(WordSearchError)
WordSearch error code -1024. Item disallowed by policy found in file.
RequiredItemNotFound
class RequiredItemNotFound(WordSearchError)
WordSearch error code -1025. Item required by policy not found in file.
IllegalActionRedact
class IllegalActionRedact(WordSearchError)
WordSearch error code -1026. Redact action specified but filetype doesn't support redaction.
IllegalActionRequire
class IllegalActionRequire(WordSearchError)
WordSearch error code -1027. Require action specified but filetype doesn't support redaction.
IllegalActionNoRequire
class IllegalActionNoRequire(WordSearchError)
WordSearch error code -1028. Require action not specified but filetype needs one.
FiletypeUnsupported
class FiletypeUnsupported(WordSearchError)
WordSearch error code -1029. Filetype supported by Editor but not by Word Search.
error_codes
error_codes = {
0: Fail,
-1024: DisallowedItemFound,
-1025: RequiredItemNotFound,
-1 ...
WordSearchError
class WordSearchError(Exception)
Base class for all WordSearch errors.
WordSearchSuccess
class WordSearchSuccess()
Base class for all WordSearch successes.
WordSearch
class WordSearch(Library)
A high level Python wrapper for Glasswall WordSearch.
__init__
def __init__(library_path: str)
version
def version()
Returns the Glasswall library version.
Returns:
versionstr - The Glasswall library version.
redact_file
@glasswall.utils.deprecated_alias(xml_config="content_management_policy")
def redact_file(input_file: Union[str, bytes, bytearray, io.BytesIO],
content_management_policy: Union[str, bytes, bytearray,
io.BytesIO],
output_file: Union[None, str] = None,
output_report: Union[None, str] = None,
homoglyphs: Union[None, str, bytes, bytearray,
io.BytesIO] = None,
raise_unsupported: bool = True)
Redacts text from input_file using the given content_management_policy and homoglyphs file, optionally writing the redacted file and report to the paths specified by output_file and output_report.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes. content_management_policy (Union[str, bytes, bytearray, io.BytesIO)]): The content management policy to apply.output_fileUnion[None, str], optional - Default None. If str, write output_file to that path.output_reportUnion[None, str], optional - Default None. If str, write output_file to that path. homoglyphs (Union[None, str, bytes, bytearray, io.BytesIO)], optional): Default None. The homoglyphs json file path or bytes.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
redact_directory
@glasswall.utils.deprecated_alias(xml_config="content_management_policy")
def redact_directory(input_directory: str,
content_management_policy: Union[
str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.policy.Policy],
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
homoglyphs: Union[None, str, bytes, bytearray,
io.BytesIO] = None,
raise_unsupported: bool = True)
Redacts all files in a directory and it's subdirectories using the given content_management_policy and homoglyphs file. The redacted files are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing files to redact.output_directorystr - The output directory where the redacted files will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where analysis reports for each redacted file will be written. content_management_policy (Union[str, bytes, bytearray, io.BytesIO)]): The content management policy to apply. homoglyphs (Union[None, str, bytes, bytearray, io.BytesIO)], optional): Default None. The homoglyphs file path, str, or bytes.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
redacted_files_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
Success
class Success(RebuildSuccess)
Rebuild success code 1. This value indicates the operation completed successfully. Any required Analysis or Protection was carried out and completed.
success_codes
success_codes = {
1: Success,
}
UnknownErrorCode
class UnknownErrorCode(RebuildError)
Unknown error code.
Error
class Error(RebuildError)
Rebuild error code 0. This value indicates that the document was non-conformant in some way, but any requested output files were written.
SuccessDocumentWriteFailure
class SuccessDocumentWriteFailure(RebuildError)
Rebuild error code -1. This value indicates that the document was managed successfully, but a failure occured when writing the managed version of the document to file.
SuccessAnalysisWriteFailure
class SuccessAnalysisWriteFailure(RebuildError)
Rebuild error code -2. This value indicates that the document was analysed successfully, but a failure occured when writing the analysis of the document to file.
ErrorAnalysisWriteFailure
class ErrorAnalysisWriteFailure(RebuildError)
Rebuild error code -3. This value indicates that the document was non-conformant in some way, and a failure occured when writing the analysis of the document to file.
SuccessReportWriteFailure
class SuccessReportWriteFailure(RebuildError)
Rebuild error code -4. This value indicates that the document was processed successfully, but that a failure occured when writing the processing report to file.
SuccessDocumentReportWriteFailure
class SuccessDocumentReportWriteFailure(RebuildError)
Rebuild error code -5. This value indicates that the document was managed successfully, but a failure occured when writing both the managed version of the document and the processing report to file.
ErrorReportWriteFailure
class ErrorReportWriteFailure(RebuildError)
Rebuild error code -6. This value indicates that the document was non-conformant in some way, and that a failure occured when writing the processing report to file.
SuccessAnalysisReportWriteFailure
class SuccessAnalysisReportWriteFailure(RebuildError)
Rebuild error code -7. This value indicates that the document was analysed successfully, but a failure occured when writing both the analysis of the document and the processing report to file.
ErrorAnalysisReportWriteFailure
class ErrorAnalysisReportWriteFailure(RebuildError)
Rebuild error code -8. This value indicates that the document was non-conformant in some way, but a failure occured when writing both the analysis of the document and the processing report to file.
InternalError
class InternalError(RebuildError)
Rebuild error code -9. This value indicates an uncategorised error
SuccessDocumentAnalysisReportWriteFailure
class SuccessDocumentAnalysisReportWriteFailure(RebuildError)
Rebuild error code -10. This value indicates that the document was analysed successfully, but failures occured when writing the document, the analysis of the document and the processing report to file (AMP mode).
SuccessDocumentAnalysisWriteFailure
class SuccessDocumentAnalysisWriteFailure(RebuildError)
Rebuild error code -11. This value indicates that the document was analysed successfully, but failures occured when writing the document and the analysis of the document to file (AMP mode).
SuccessExportWriteFailure
class SuccessExportWriteFailure(RebuildError)
Rebuild error code -12. This value indicates that the document was exported successfully, but failures occured when writing the archive package. (Export mode)
ErrorExportWriteFailure
class ErrorExportWriteFailure(RebuildError)
Rebuild error code -13. This value indicates that the document was non-conformant in some way, and failures occured when writing the archive package. (Export mode)
ErrorRejectedFileFailure
class ErrorRejectedFileFailure(RebuildError)
Rebuild error code -16. This value indicates that the document was processed successfully but rejected based on policy.
error_codes
error_codes = {
0: Error,
-1: SuccessDocumentWriteFailure,
-2: SuccessAnalysisWriteFailu ...
RebuildError
class RebuildError(Exception)
Base class for all Glasswall Rebuild errors.
RebuildSuccess
class RebuildSuccess()
Base class for all Glasswall Rebuild successes.
Rebuild
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:
versionstr - 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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file, can be a local path.as_stringbool, optional - Return file type as string, eg: "bmp" instead of: 29. Defaults to False.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_typeUnion[int, str] - The file format.
get_content_management_policy
def get_content_management_policy()
Gets the current content management configuration.
Returns:
xml_stringstr - 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_fileUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
Returns:
statusint - 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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileUnion[None, str], optional - The output file path where the protected file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - 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_directorystr - The input directory containing files to protect.output_directoryUnion[None, str] - The output directory where the protected file will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
protected_files_dictdict - 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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileUnion[None, str], optional - The output file path where the analysis file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - 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_directorystr - The input directory containing files to analyse.output_directoryUnion[None, str] - The output directory where the analysis files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
analysis_files_dictdict - 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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileUnion[None, str], optional - The output file path where the .zip file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - 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_directorystr - The input directory containing files to export.output_directoryUnion[None, str] - The output directory where the export files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
export_files_dictdict - 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_fileUnion[str, bytes, bytearray, io.BytesIO] - The .zip input file path or bytes.output_fileUnion[None, str], optional - The output file path where the constructed file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - 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_directorystr - The input directory containing files to import.output_directoryUnion[None, str] - The output directory where the constructed files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
import_files_dictdict - A dictionary of file paths relative to input_directory, and file bytes.
GWFileErrorMsg
def GWFileErrorMsg()
Retrieve the Glasswall Process error message.
Returns:
error_messagestr - The Glasswall Process error message.
ArchiveManager
class ArchiveManager(Library)
A high level Python wrapper for Glasswall Archive Manager.
__init__
def __init__(library_path)
version
def version()
Returns the Glasswall library version.
Returns:
versionstr - The Glasswall library version.
release
def release()
Releases any resources held by the Glasswall Archive Manager library.
supported_archives
@property
@functools.lru_cache()
def supported_archives()
Returns a list of supported archive file formats.
is_supported_archive
@functools.lru_cache()
def is_supported_archive(archive_type: str)
Returns True if the archive type (e.g. 7z) is supported.
list_archive_paths
def list_archive_paths(directory: str,
recursive: bool = True,
absolute: bool = True,
followlinks: bool = True)
Returns a list of file paths of supported archives in a directory and all of its subdirectories.
determine_file_type
def determine_file_type(input_file: str,
as_string: bool = False,
raise_unsupported: bool = True)
Returns an int representing the file type of an archive.
Arguments:
input_file (str) The input file path.
as_stringbool, optional - Return file type as string, eg: "xz" instead of: 262. Defaults to False.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_typeUnion[int, str] - The file format.
analyse_archive
def analyse_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
analyse_directory
def analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls analyse_archive on each file in input_directory using the given content management configuration. The resulting archives and analysis reports are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to analyse.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives containing analysis reports of each file will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
analysed_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
protect_archive
def protect_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
protect_directory
def protect_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls protect_archive on each file in input_directory using the given content management configuration. The resulting archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to protect.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
protected_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
file_to_file_unpack
def file_to_file_unpack(input_file: str,
output_directory: str,
raise_unsupported: bool = True)
file_to_file_pack
def file_to_file_pack(input_directory: str,
output_directory: str,
file_type: Optional[str] = None,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True)
unpack
def unpack(input_file: str,
output_directory: str,
recursive: bool = True,
include_file_type: bool = False,
raise_unsupported: bool = True,
delete_origin: bool = False)
Unpack an archive, maintaining directory structure. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".
Arguments:
input_filestr - The archive file pathoutput_directorystr - The output directory where the archive will be unpacked to a new directory.recursivebool, optional - Default True. Recursively unpack all nested archives.include_file_typebool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_file after unpacking to output_directory.
unpack_directory
def unpack_directory(input_directory: str,
output_directory: str,
recursive: bool = True,
include_file_type: Optional[bool] = False,
raise_unsupported: bool = True,
delete_origin: bool = False)
Unpack a directory of archives, maintaining directory structure.
Arguments:
input_directorystr - The input directory containing archives to unpack.output_directorystr - The output directory where archives will be unpacked to a new directory.recursivebool, optional - Default True. Recursively unpack all nested archives.include_file_typebool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_file after unpacking to output_directory.
pack_directory
def pack_directory(input_directory: str,
output_directory: str,
file_type: str,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True,
delete_origin: Optional[bool] = False)
Pack a directory. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".
Arguments:
input_directorystr - The input directory containing files to archive.output_directorystr - The output directory to store the created archive.file_typestr - The archive file type.add_extensionbool, optional - Default: True. Archive file type extension to result file.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_directory after packing to output_directory.
export_archive
def export_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Exports an archive using the Glasswall engine.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
export_directory
def export_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls export_archive on each file in input_directory. The exported archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to export.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
exported_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
import_archive
def import_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: Optional[bool] = True)
Imports an archive using the Glasswall engine.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.include_analysis_reportOptional[bool], optional - Default False. If True, write the analysis report into the imported archive.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
import_directory
def import_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: bool = True)
Calls import_archive on each file in input_directory. The imported archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to import.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.include_analysis_reportOptional[bool], optional - Default False. If True, write the analysis report into the imported archive.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
imported_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
Success
class Success(ArchiveManagerSuccess)
ArchiveManager success code 1.
success_codes
success_codes = {
1: Success,
}
UnknownErrorCode
class UnknownErrorCode(ArchiveManagerError)
Unknown error code.
Fail
class Fail(ArchiveManagerError)
ArchiveManager error code 0.
error_codes
error_codes = {
0: Fail,
}
ArchiveManagerError
class ArchiveManagerError(Exception)
Base class for all Glasswall ArchiveManager errors.
ArchiveManagerSuccess
class ArchiveManagerSuccess()
Base class for all Glasswall ArchiveManager successes.
OK
class OK(EditorSuccess)
Editor success code 0.
OKWithCleaning
class OKWithCleaning(EditorSuccess)
Editor success code 1.
success_codes
success_codes = {
0: OK,
1: OKWithCleaning,
}
UnknownErrorCode
class UnknownErrorCode(EditorError)
Unknown error code.
GeneralFail
class GeneralFail(EditorError)
Editor error code -1.
UnexpectedEndOfFile
class UnexpectedEndOfFile(EditorError)
Editor error code -2.
LicenceExpired
class LicenceExpired(EditorError)
Editor error code -3.
LicenseExpired
LicenseExpired = LicenceExpired
alias <= 0.2.42
IncorrectSessionSetup
class IncorrectSessionSetup(EditorError)
Editor error code -4.
IncorrectPolicySetup
class IncorrectPolicySetup(EditorError)
Editor error code -5.
UnableToLoadInput
class UnableToLoadInput(EditorError)
Editor error code -6.
FileTypeUnknown
class FileTypeUnknown(EditorError)
Editor error code -7.
UnknownSessionID
class UnknownSessionID(EditorError)
Editor error code -8.
ArgumentError
class ArgumentError(EditorError)
Editor error code -9.
UnableToLoadImport
class UnableToLoadImport(EditorError)
Editor error code -10.
CameraDidNotInitialise
class CameraDidNotInitialise(EditorError)
Editor error code -11.
NoCamerasConnected
class NoCamerasConnected(EditorError)
Editor error code -12.
EngineeringOnlyGoesToFile
class EngineeringOnlyGoesToFile(EditorError)
Editor error code -13.
UnableToWriteOutput
class UnableToWriteOutput(EditorError)
Editor error code -14
UnableToWriteExport
class UnableToWriteExport(EditorError)
Editor error code -15
FileRejected
class FileRejected(EditorError)
Editor error code -16
UnableToWriteExportTextDump
class UnableToWriteExportTextDump(EditorError)
Editor error code -17
UnableToWriteAnalysisReport
class UnableToWriteAnalysisReport(EditorError)
Editor error code -18
InputTooLarge
class InputTooLarge(EditorError)
Editor error code -19
InputZeroBytes
class InputZeroBytes(EditorError)
Editor error code -20
error_codes
error_codes = {
-1: GeneralFail,
-2: UnexpectedEndOfFile,
-3: LicenseExpired,
-4: In ...
Editor
class Editor(Library)
A high level Python wrapper for Glasswall Editor / Core2.
__init__
def __init__(library_path: str,
licence: Union[str, bytes, bytearray, io.BytesIO] = None)
Initialise the Editor instance.
Arguments:
library_pathstr - The file or directory path to the Editor library.licencestr, bytes, bytearray, or io.BytesIO, optional - The licence file content or path. This can be:- A string representing the file path to the licence.
- A
bytesorbytearrayobject containing the licence data. - An
io.BytesIOobject for in-memory licence data. If not specified, it is assumed that the licence file is located in the same directory as thelibrary_path.
validate_licence
def validate_licence()
Validates the licence of the library by checking the licence details.
Raises:
LicenceExpired- If the licence has expired or could not be validated.
version
def version()
Returns the Glasswall library version.
Returns:
versionstr - The Glasswall library version.
open_session
def open_session()
Open a new Glasswall session.
Returns:
sessionint - An incrementing integer repsenting the current session.
close_session
def close_session(session: int) -> int
Close the Glasswall session. All resources allocated by the session will be destroyed.
Arguments:
sessionint - The session to close.
Returns:
statusint - The status code of the function call.
new_session
@contextmanager
def new_session()
Context manager. Opens a new session on entry and closes the session on exit.
run_session
def run_session(session)
Runs the Glasswall session and begins processing of a file.
Arguments:
sessionint - The session to run.
Returns:
statusint - The status code of the function call.
determine_file_type
def determine_file_type(input_file: Union[str, bytes, bytearray, io.BytesIO],
as_string: bool = False,
raise_unsupported: bool = True) -> Union[int, str]
Determine the file type of a given input file, either as an integer identifier or a string.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file to analyse. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.as_stringbool, optional - Return file type as string, eg: "bmp" instead of: 29. Defaults to False.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_typeUnion[int, str] - The file type.
get_content_management_policy
def get_content_management_policy(session: int)
Returns the content management configuration for a given session.
Arguments:
sessionint - The session integer.
Returns:
xml_stringstr - The XML string of the current content management configuration.
set_content_management_policy
def set_content_management_policy(
session: int,
input_file: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
policy_format=0)
Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.
Arguments:
sessionint - The session integer.input_fileUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.policy_formatint - The format of the content management policy. 0=XML.
Returns:
-
result (glasswall.GwReturnObj): Depending on the input 'input_file':
-
If input_file is a str file path:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'policy_format', 'status'.
-
If input_file is a file in memory:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'policy_format', 'status'.
register_input
def register_input(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])
Register an input file or bytes for the given session.
Arguments:
sessionint - The session integer.input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
Returns:
-
result (glasswall.GwReturnObj): Depending on the input 'input_file':
-
If input_file is a str file path:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'status'.
-
If input_file is a file in memory:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'status'.
register_output
def register_output(session, output_file: Optional[str] = None)
Register an output file for the given session. If output_file is None the file will be returned as 'buffer' and 'buffer_length' attributes.
Arguments:
sessionint - The session integer.output_fileOptional[str] - If specified, during run session the file will be written to output_file, otherwise the file will be written to the glasswall.GwReturnObj 'buffer' and 'buffer_length' attributes.
Returns:
gw_return_objectglasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.
register_analysis
def register_analysis(session: int, output_file: Optional[str] = None)
Registers an analysis file for the given session. The analysis file will be created during the session's run_session call.
Arguments:
sessionint - The session integer.output_fileOptional[str] - Default None. The file path where the analysis will be written. None returns the analysis as bytes.
Returns:
gw_return_objectglasswall.GwReturnObj - A GwReturnObj instance with the attributes 'status', 'session', 'analysis_format'. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size. If output_file is not None (file mode) 'output_file' is included.
protect_file
def protect_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the protected file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - The protected file bytes.
protect_directory
def protect_directory(
input_directory: str,
output_directory: Optional[str] = None,
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_directorystr - The input directory containing files to protect.output_directoryOptional[str] - The output directory where the protected file will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
protected_files_dictdict - 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: Optional[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_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the analysis file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - The analysis file bytes.
analyse_directory
def analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
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_directorystr - The input directory containing files to analyse.output_directoryOptional[str] - The output directory where the analysis files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
analysis_files_dictdict - A dictionary of file paths relative to input_directory, and file bytes.
protect_and_analyse_file
def protect_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)
Protects and analyses a file in a single session, returning both protected file bytes and analysis report bytes.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the protected file will be written.output_analysis_reportOptional[str] - The output file path where the XML analysis report will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
Tuple[Optional[bytes], Optional[bytes]]: A tuple of (protected_file_bytes, analysis_report_bytes).
protect_and_analyse_directory
def protect_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
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 using protect and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.
Arguments:
input_directorystr - The input directory containing files to process.output_directoryOptional[str] - The output directory for protected files.analysis_directoryOptional[str] - The output directory for XML analysis reports.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
result_dictdict - A dictionary mapping relative file paths to tuples of (protected_file_bytes, analysis_report_bytes).
register_export
def register_export(session: int, output_file: Optional[str] = None)
Registers a file to be exported for the given session. The export file will be created during the session's run_session call.
Arguments:
sessionint - The session integer.output_fileOptional[str] - Default None. The file path where the export will be written. None exports the file in memory.
Returns:
gw_return_objectglasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call and 'session', the session integer. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.
export_file
def export_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[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 if it is provided.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the .zip file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - The exported .zip file.
export_directory
def export_directory(
input_directory: str,
output_directory: Optional[str] = None,
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_directorystr - The input directory containing files to export.output_directoryOptional[str] - The output directory where the export files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
export_files_dictdict - A dictionary of file paths relative to input_directory, and file bytes.
export_and_analyse_file
def export_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)
Exports and analyses a file in a single session, returning both exported .zip bytes and analysis report bytes.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the .zip export will be written.output_analysis_reportOptional[str] - The output file path where the XML analysis report will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
Tuple[Optional[bytes], Optional[bytes]]: A tuple of (export_file_bytes, analysis_report_bytes).
export_and_analyse_directory
def export_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
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 using export and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.
Arguments:
input_directorystr - The input directory containing files to process.output_directoryOptional[str] - The output directory for exported .zip files.analysis_directoryOptional[str] - The output directory for XML analysis reports.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
result_dictdict - A dictionary mapping relative file paths to tuples of (export_file_bytes, analysis_report_bytes).
register_import
def register_import(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])
Registers a .zip file to be imported for the given session. The constructed file will be created during the session's run_session call.
Arguments:
sessionint - The session integer.input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input import file path or bytes.
Returns:
gw_return_objectglasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.
import_file
def import_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[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_fileUnion[str, bytes, bytearray, io.BytesIO] - The .zip input file path or bytes.output_fileOptional[str] - The output file path where the constructed file will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_bytesbytes - The imported file bytes.
import_directory
def import_directory(
input_directory: str,
output_directory: Optional[str] = None,
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_directorystr - The input directory containing files to import.output_directoryOptional[str] - The output directory where the constructed files will be written, or None to not write files.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
import_files_dictdict - A dictionary of file paths relative to input_directory, and file bytes.
import_and_analyse_file
def import_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)
Imports and analyses a file in a single session, returning both imported file bytes and analysis report bytes.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.output_fileOptional[str] - The output file path where the imported file will be written.output_analysis_reportOptional[str] - The output file path where the XML analysis report will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
Tuple[Optional[bytes], Optional[bytes]]: A tuple of (import_file_bytes, analysis_report_bytes).
import_and_analyse_directory
def import_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
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 using import and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.
Arguments:
input_directorystr - The input directory containing export .zip files to process.output_directoryOptional[str] - The output directory for imported files.analysis_directoryOptional[str] - The output directory for XML analysis reports.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
result_dictdict - A dictionary mapping relative file paths to tuples of (import_file_bytes, analysis_report_bytes).
file_error_message
@functools.lru_cache()
def file_error_message(session: int) -> str
Retrieve the Glasswall Session Process error message.
Arguments:
sessionint - The session integer.
Returns:
error_messagestr - The Glasswall Session Process error message.
GW2GetFileType
def GW2GetFileType(session: int, file_type_id)
Retrieve the file type as a string.
Arguments:
sessionint - The session integer.file_type_idint - The file type id.
Returns:
file_typestr - The formal file name for the corresponding file id.
GW2GetFileTypeID
def GW2GetFileTypeID(session: int, file_type_str)
Retrieve the Glasswall file type id given a file type string.
Arguments:
sessionint - The session integer.file_type_strstr - The file type as a string.
Returns:
file_type_idstr - The Glasswall file type id for the specified file type.
get_file_type_info
def get_file_type_info(file_type: Union[str, int])
Retrieve information about a file type based on its identifier.
Arguments:
file_typeUnion[str, int] - The file type identifier. This can be either a string representing a file extension (e.g. 'bmp') or an integer corresponding to a file type (e.g. 29).
Returns:
- file_type_info (Union[int, str]): Depending on the input 'file_type':
- If
file_typeis a string (e.g. 'bmp'): - If the file type is recognised, returns an integer corresponding to that file type.
- If the file type is not recognised, returns 0.
- If
file_typeis an integer (e.g. 29): - If the integer corresponds to a recognised file type, returns a more detailed string description of the file type (e.g. 'BMP Image').
- If the integer does not match any recognised file type, returns an empty string.
get_file_info
@utils.deprecated_function(replacement_function=get_file_type_info)
def get_file_info(*args, **kwargs)
Deprecated in 1.0.6. Use get_file_type_info.
register_report_file
def register_report_file(session: int, output_file: str)
Register the report file path for the given session.
Arguments:
sessionint - The session integer.output_filestr - The file path of the report file.
Returns:
gw_return_objectglasswall.GwReturnObj - A GwReturnObj instance with the attributes 'session', 'output_file', 'status'.
get_id_info
def get_id_info(issue_id: int, raise_unsupported: bool = True)
Retrieves the group description for the given Issue ID. e.g. issue_id 96 returns "Document Processing Instances"
Arguments:
issue_idint - The issue id.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
id_infostr - The group description for the given Issue ID.
get_all_id_info
def get_all_id_info(output_file: Optional[str] = None,
raise_unsupported: bool = True) -> str
Retrieves the XML containing all the Issue ID ranges with their group descriptions
Arguments:
output_fileOptional[str] - The output file path where the analysis file will be written.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
all_id_infostr - A string XML analysis report containing all id info.
file_session_status_message
def file_session_status_message(session: int,
raise_unsupported: bool = True) -> str
Retrieves the Glasswall session status message. Gives a high level indication of the processing that was carried out.
Arguments:
sessionint - The session integer.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
result.message (str):The file session status message.
licence_details
def licence_details()
Returns a string containing details of the licence.
Returns:
resultstr - A string containing details of the licence.
register_licence
def register_licence(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])
Registers a "gwkey.lic" licence from file path or memory.
Arguments:
sessionint - The session integer.input_fileUnion[str, bytes, bytearray, io.BytesIO] - The "gwkey.lic" licence. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.
Returns:
-
result (glasswall.GwReturnObj): Depending on the input 'input_file':
-
If input_file is a str file path:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'status'.
-
If input_file is a file in memory:
-
gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'status'.
EditorError
class EditorError(Exception)
Base class for all Glasswall Editor errors.
EditorSuccess
class EditorSuccess()
Base class for all Glasswall Editor successes.