aiovalidator
Example
import asyncio
from aiohttp import web
from aiovalidator import (
validator_factory,
middleware_exception,
IntegerField
)
async def foo_validator(value):
await asyncio.sleep(1)
return value
def foo_default(value):
async def default():
return value
return default
class Hello(web.View):
class Field:
field1 = IntegerField()
field2 = IntegerField(required=False, methods={'GET'},
verbose_name='Field method get')
field3 = IntegerField(validator=foo_validator, )
field4 = IntegerField(default=foo_default)
@asyncio.coroutine
def get(self):
fields = self.request['fields']
print(fields)
return web.json_response()
app = web.Application(middlewares=[validator_factory(), middleware_exception])
app.router.add_get('/{user_id}/', Hello)
web.run_app(app, port=8000)
My fields example
import phonenumbers
from aiovalidator import StrField, abort
class PhoneField(StrField):
def get_value(self, value):
value = super().get_value(value)
try:
value = phonenumbers.parse(value, 'RU')
region = phonenumbers.region_code_for_number(value)
regions = phonenumbers.COUNTRY_CODE_TO_REGION_CODE[7]
if not phonenumbers.is_valid_number(value):
abort(status=400,
text='Field {} not format phone'.format(self.name))
if region not in regions:
abort(status=400,
text='Field {} not format phone'.format(self.name))
value = phonenumbers.format_number(
value, phonenumbers.PhoneNumberFormat.E164
)[1:]
return value
except phonenumbers.NumberParseException:
abort(status=400, text='Field {} not valid'.format(self.name))
Metadata
Release files for aiovalidator 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiovalidator-0.0.2.tar.gz | 4.9 kB | Without provenance | Details for aiovalidator-0.0.2.tar.gz |
Release files / aiovalidator-0.0.2.tar.gz
| Download URL | aiovalidator-0.0.2.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a5819437382e3aae7cd315ae45e37737a08046c818c6ac780e87a55c18cda8a
|
|
BLAKE2b-256 checksum How to use checksums |
0a6f74071f15da8d2d2a6e2e4c2a411821f953aed86c73cadeec1483ddde3d18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for aiovalidator 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.