caellion-python-commons: caellion.pycommons.hashing.file_hashing.FileHasher Class Reference

caellion-python-commons

Public Member Functions | Public Attributes | Static Public Attributes | List of all members
caellion.pycommons.hashing.file_hashing.FileHasher Class Reference

This class provides hashlib-based file hasher. More...

## Public Member Functions
def | __init__ (self, algo=None)
| Initializes hasher. More...
def | hash_file (self, file)
| Hashes file-object with currently chosen algorithm. More...
def | hash_path (self, path)
| Hashes file-object with currently chosen algorithm. More...
def | get_hexdigest (self)
| Returns hexadecimal value of hash from this object. More...
def | get_hashbytes (self)
| Returns hexadecimal value of hash from this object. More...
def | hash_file_and_get_hashbytes (self, file)
| Hashes a file-object and returns hash. More...
def | hash_path_and_get_hashbytes (self, path)
| Hashes a file at path and returns hash. More...
def | hash_file_and_get_hexdigest (self, file)
| Hashes a file-object and returns hash. More...
def | hash_path_and_get_hexdigest (self, path)
| Hashes a file at path and returns hash. More...

## Public Attributes
| islocked

## Static Public Attributes
| hashlib_instance = None
| Instance of hashlib algorithm implementation. More...
bool | islocked = False
| Is this FileHasher done hashing a file. More...
| digest = None
| result of hashing (raw) More...
| hexdigest = None
| result of hashing (hex) More...

## Detailed Description

This class provides hashlib-based file hasher.

Definition at line 32 of file file_hashing.py.

## Constructor & Destructor Documentation

## ◆ __init__()

def caellion.pycommons.hashing.file_hashing.FileHasher.__init__ | ( |  | self,
|  |  | algo = `None`
| ) |  |

Initializes hasher.

Currently supported hashes: SHA1, SHA256, SHA384, SHA512, MD5 (not recommended)

Parameters

  algo | String with name of algorithm to use

Exceptions

  UnsupportedAlgorithmException | when attempting to use unsupported algorithm

Definition at line 46 of file file_hashing.py.

## Member Function Documentation

## ◆ get_hashbytes()

def caellion.pycommons.hashing.file_hashing.FileHasher.get_hashbytes | ( |  | self | ) |

Returns hexadecimal value of hash from this object.

Returns
  bytes of hash

Exceptions

  NotDoneYetException | if no file was hashed with this FileHasher.

Definition at line 119 of file file_hashing.py.

## ◆ get_hexdigest()

def caellion.pycommons.hashing.file_hashing.FileHasher.get_hexdigest | ( |  | self | ) |

Returns hexadecimal value of hash from this object.

Returns
  hexadecimal string representation of hash

Exceptions

  NotDoneYetException | if no file was hashed with this FileHasher.

Definition at line 106 of file file_hashing.py.

## ◆ hash_file()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_file | ( |  | self,
|  |  | file
| ) |  |

Hashes file-object with currently chosen algorithm.

Parameters

  file | file-object to be hashed

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 69 of file file_hashing.py.

## ◆ hash_file_and_get_hashbytes()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_file_and_get_hashbytes | ( |  | self,
|  |  | file
| ) |  |

Hashes a file-object and returns hash.

Parameters

  file | file-object to be hashed

Returns
  bytes of hash

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 132 of file file_hashing.py.

## ◆ hash_file_and_get_hexdigest()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_file_and_get_hexdigest | ( |  | self,
|  |  | file
| ) |  |

Hashes a file-object and returns hash.

Parameters

  file | file-object to be hashed

Returns
  hexadecimal string representation of hash

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 158 of file file_hashing.py.

## ◆ hash_path()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_path | ( |  | self,
|  |  | path
| ) |  |

Hashes file-object with currently chosen algorithm.

Parameters

  path | path to file to be hashed

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 87 of file file_hashing.py.

## ◆ hash_path_and_get_hashbytes()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_path_and_get_hashbytes | ( |  | self,
|  |  | path
| ) |  |

Hashes a file at path and returns hash.

Parameters

  path | path to the file to be hashed

Returns
  bytes of hash

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 145 of file file_hashing.py.

## ◆ hash_path_and_get_hexdigest()

def caellion.pycommons.hashing.file_hashing.FileHasher.hash_path_and_get_hexdigest | ( |  | self,
|  |  | path
| ) |  |

Hashes a file at path and returns hash.

Parameters

  path | path to the file to be hashed

Returns
  hexadecimal string representation of hash

Exceptions

  AlreadyDoneException | if this FileHasher is already done hashing a different file

Definition at line 171 of file file_hashing.py.

## Member Data Documentation

## ◆ digest

caellion.pycommons.hashing.file_hashing.FileHasher.digest = None
| static

result of hashing (raw)

Definition at line 42 of file file_hashing.py.

## ◆ hashlib_instance

caellion.pycommons.hashing.file_hashing.FileHasher.hashlib_instance = None
| static

Instance of hashlib algorithm implementation.

Definition at line 38 of file file_hashing.py.

## ◆ hexdigest

caellion.pycommons.hashing.file_hashing.FileHasher.hexdigest = None
| static

result of hashing (hex)

Definition at line 44 of file file_hashing.py.

## ◆ islocked [1/2]

bool caellion.pycommons.hashing.file_hashing.FileHasher.islocked = False
| static

Is this FileHasher done hashing a file.

Definition at line 40 of file file_hashing.py.

## ◆ islocked [2/2]

caellion.pycommons.hashing.file_hashing.FileHasher.islocked

Definition at line 85 of file file_hashing.py.

The documentation for this class was generated from the following file:

- caellion/pycommons/hashing/file_hashing.py