Skip to content

Commit

Permalink
feat: add new module isValidImage 0.1.0v
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed May 15, 2024
1 parent d0fe80d commit 2b7144b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
28 changes: 27 additions & 1 deletion packages/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This package contains various modules for validating different types of data. Be
- **isEmail**: Email address validation format.
- **passwordStrengthTester**: Password strength test.
- **validateBRPhoneNumber**: Brazilian phone number validation.
- **isValidImage**: Image validation.

## Usage

Expand All @@ -52,10 +53,13 @@ from multiform_validator import (
isCreditCardValid,
isEmail,
passwordStrengthTester,
validateBRPhoneNumber
validateBRPhoneNumber,
isValidImage
)
```

### Usage Example

```python

print("Is email", isEmail("foo@bar.com")) # True
Expand All @@ -69,6 +73,25 @@ print("Validate BR phone number", validateBRPhoneNumber("(11) 91234-5678")) # {

```

### isValidImage Usage Example

```python
import os
from pathlib import Path

from multiform_validator import isValidImage

# Resolve the file path
file_path = Path.cwd() / 'static' / 'uploads'
retrieved_file = file_path / filename

# Read the first 4 bytes of the file
with open(retrieved_file, 'rb') as f:
file_buffer = f.read(4)

print(isValidImage(file_buffer)) # True or False
```

## Functions signature

All params with default values are optional.
Expand Down Expand Up @@ -112,6 +135,9 @@ default_error_msg = ['Invalid value passed', 'Invalid phone number', 'Unknown er
def validateBRPhoneNumber(phoneNumber: str, errorMsg=default_error_msg) -> Dict[str, Union[bool, str, None]]:
pass

def isValidImage(file_buffer: bytes) -> bool:
pass

```

## Looking for contributions.
Expand Down
4 changes: 2 additions & 2 deletions packages/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ build-backend = "setuptools.build_meta"

[project]
name = "multiform-validator"
version = "0.0.10"
version = "0.1.0"
authors = [
{ name="Gabriel Logan" },
]
description = "Multilingual library made for validation, various form fields, such as: email, cpf, cnpj, credit card, and much more."
readme = "README.md"
keywords = ["validator", "multiform", "validação", "email-validator", "multiform-validator", "python", "security", "safe", "pentest", "security-tools", "Validator", "validate", "cpf", "cnpj", "email validator", "password", "email", "isEmail"]
keywords = ["validator", "multiform", "validação", "email-validator", "image", "multiform-validator", "python", "security", "safe", "pentest", "security-tools", "Validator", "validate", "cpf", "cnpj", "email validator", "password", "email", "isEmail"]
requires-python = ">=3.1"
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
1 change: 1 addition & 0 deletions packages/python/src/multiform_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .isCreditCardValid import isCreditCardValid
from .passwordStrengthTester import passwordStrengthTester
from .validateBRPhoneNumber import validateBRPhoneNumber
from .isValidImage import isValidImage
8 changes: 8 additions & 0 deletions packages/python/src/multiform_validator/isValidImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def isValidImage(file_buffer):
# Check the magic numbers to determine the mimetype
is_jpeg = file_buffer[0] == 0xff and file_buffer[1] == 0xd8 and file_buffer[2] == 0xff
is_png = file_buffer[0] == 0x89 and file_buffer[1] == 0x50 and file_buffer[2] == 0x4e and file_buffer[3] == 0x47
is_gif = file_buffer[0] == 0x47 and file_buffer[1] == 0x49 and file_buffer[2] == 0x46 and file_buffer[3] == 0x38

return is_jpeg or is_png or is_gif

0 comments on commit 2b7144b

Please sign in to comment.