This decorator validates the file extension and file size of an in memory file object.
Project description
File Validation Decorator
A decorator for validating file types and sizes. If the validation fails, an Exception will be raised and the code will stop before reaching the function you are decorating. A successful validation will execute the function being decorated - business as usual.
Example Of A Successful File Validation
from file_validation_decorator.file_validation import file_validation
with open('places_to_go.txt') as file:
@file_validation(file, ['txt', 'jpeg'], 10)
def test():
print('it works')
test()
Example Of A File That Is Too Large In Size
The decorator is provided a file size of 0 below and will raise a FileSizeExceeded error.
from file_validation_decorator.file_validation import file_validation
with open('places_to_go.txt') as file:
@file_validation(file, ['txt', 'jpeg'], 0)
def test():
print('it works')
test()
Example Of A File Extension That Is Not Allowed
The example file being uploaded here is a .txt but a text file is not provided in the accepted file extensions list. This will raise a FileTypeNotAllowed error.
from file_validation_decorator.file_validation import file_validation
with open('places_to_go.txt') as file:
@file_validation(file, ['jpeg'], 0)
def test():
print('it works')
test()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for file_validation_decorator-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d34376959ae1a111aaddc406b13f318ad341ceccd0028dca493f075a0401051c |
|
MD5 | a094466b77777aaafe5561fe973dd386 |
|
BLAKE2b-256 | 730eab49258858600ba2520bf6afeaf6e0c2ff04f522d0548a367ddaa4e246a6 |
Close
Hashes for file_validation_decorator-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87d6a1086bc255324d3065e36656573b25af8ae9312fc5406e493d7af1dafd91 |
|
MD5 | 2d1aae7f241b0dbe857b69878bfd7668 |
|
BLAKE2b-256 | 2c252dcf970a68a17197028651e1dcf8cee98fd1fb0de4df7b83c6b2c2908beb |