diff --git a/README.md b/README.md index 4cd395a..f2ec800 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,57 @@ # turboguard +[![Build](https://github.com/pylover/turboguard/actions/workflows/build.yml/badge.svg)](https://github.com/pylover/turboguard/actions/workflows/build.yml) +[![Coverage Status](https://coveralls.io/repos/github/pylover/turboguard/badge.svg?branch=master)](https://coveralls.io/github/pylover/turboguard?branch=master) + +Python C extension to validate and sanitize the user input using blacklist +and character map. + +## Install + +```bash +pip install turboguard +``` + + +### Quickstart. + +Create an instance of the `Sanitizer` class as the below. + +The `Sanitizer.__enter__` method returns a `callable(str) -> str` which let +you to call it many times without worring about performance and memory leak. + +```python +from turboguard import Sanitizer, BlacklistedError + + +blacklist = [ + ('\u1d100', '\u1d1ff'), # Blacklist Unicode range + '\u0635', # Blacklist single character + ... +] + +replace = [ + ('\u0636', '\u0637'), # Replace \u0636 by \u0637 + ... +] + +with Sanitizer(blacklist, replace) as sanitize: # Loading(Slow) part + try: + print(sanitize('foo bar baz')) # Fast call! + except BlacklistedError: + print('Validation failed!') +``` + +## Contribution + +```bash +make env +make build +make cover +``` + +Afterward, for development sycle: + +```bash +make clean build cover +``` diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 8e6c37e..4881f01 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -1,7 +1,6 @@ import pytest -from turboguard import Sanitizer -from turboguard.core import BlacklistedError +from turboguard import Sanitizer, BlacklistedError def test_blacklist(): diff --git a/turboguard/__init__.py b/turboguard/__init__.py index e9b7b28..db8a3c2 100644 --- a/turboguard/__init__.py +++ b/turboguard/__init__.py @@ -1,4 +1,5 @@ from . import core +from .core import BlacklistedError __version__ = '0.1.0'