semvec/pypi-packages huggingface dataset:
dropt-util 0.5.1
DrOpt utility package
License: MIT
Requires Python: >=3.6
Keywords: DrOpt,utility

# `dropt.util`: DrOpt Utility Package
This package provides utilities required by the DrOpt suite.
Here is the list of utilities and their description.


## `dropt.util.log`: logging
This module provides standardized logging tools,
including __standard format__, __logger classes__ and __logger wrapper__.
- __standard format__:  
  The standard format for console output is
  ```
  [yyyy-mm-dd HH:MM:SS] {logger_name} [{level_name}] {message}
  ```

  The standard format for log file output is
  ```
  yyyy-mm-dd HH:MM:SS|{logger_name}|{level_name}|{message}
  ```

- __logger classes__:
  - `class Logger`
  - `class DrOptLogger(Logger)`
  - `class DrOptServiceLogger(DrOptLogger)`
  - `class DrOptClientLogger(DrOptLogger)`
  - `class DroptUserLogger(DrOptLogger)`

- __logger wrapper__:
  - `class FuncLoggingWrapper`

## `dropt.util.crypt`: cryptographic utilities

The `crypt` module implements common cryptographic functions for Dr.Opt client & system. The following shows the usage of each class.

### `Crypt`: basic encrypt & decrypt
* **Import**    

    ```python
    from dropt.util.crypt import Crypt
    ```

- **Encryption**  
  Encrypt the given `string`:

    ```python
    >>> Crypt().encrypt("hello world")
    'gAAAAABfYIMWXwSYDC2...'
    ```
- **Decryption**  
  Decrypt the given `string` (cipher):

    ```python
    >>> Crypt().decrypt("gAAAAABfYIMWXwSYDC2...")
    'hello world'
    ```

### `FileEncryptor`: apply encryption / decryption to files
* **Initial Options**
    * `file`: file name 
        - default: None
    * `auth`: if require password authentication to apply the encryption
        - default: True

* **Import**    

    ```python
    from dropt.util.crypt import FileEncryptor
    ```

- **Encryption**  
  Encrypt the given `[file]` and generate an output file `[file].e`

    ```python
    >>> FileEncryptor().encrypt('package.json')
    Encrypt the given file [package.json] ...
    Password: 
    Generate the encrypted file [package.json.e]
    ```
- **Decryption**  
  Decrypt the given encrypted `file`, and return the plain text as `byte string`

    ```python
    >>> FileEncryptor().decrypt('package.json.e')
    b'{\n  "name": "dropt-util",\n  "version": "1.0.0",\ ...
    ```

### `FileDigest`: get the MD5 message digest for a file
* **Import**    

    ```python
    from dropt.util.crypt import FileDigest
    ```

- **Get the MD5 checksum**   
    ```python
    >>> FileDigest().get('[FILE]')
    '7e335d398de79a029a0f9262300ddb5b'
    ```

### `PasswordAuth`: password prompt for authentication
* **Import**    

    ```python
    from dropt.util.crypt import PasswordAuth
    ```

- **Trigger the prompt**   

    ```python
    PasswordAuth().auth()
    ```
     * If the password is correct, the process will keep executing.
        ```python
        >>> PasswordAuth().auth()
        Password: 
        >>>
        ```

     * If the password is wrong, the process will exit.
        ```python
        >>> PasswordAuth().auth()
        Password: 
        The password is incorrect. Exit.
        ```