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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbf54ef9d3baa6d225ef30a08632d9f1a556af07230621bf65a80017fe37c6b1 |
|
MD5 | b21f12569dac1c8eaeebfb3184430b9a |
|
BLAKE2b-256 | 22eab17f7993b8111267ca41b77e178cc9ef603b1f7fab943d75de5bdcea180c |
Close
Hashes for file_validation_decorator-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d405194c868ca3bd7787059d409b1c8e76c9c32d6bfc1696d7d09563cb4101 |
|
MD5 | 64c94c90d707d890ae0db863664cfb4a |
|
BLAKE2b-256 | 576e880ceccb68dab5af303268456ebc70218f1de3469bef5486c64ac9b1afec |