def validate(cls, strict=False, fields=None, ignore=None):
        if callable(strict):
            # Decorator is used without any parameter and call parentesis.
            func = strict
            strict = False
        else:
            func = None

        rules = cls.create_validation_rules(strict, ignore)
        if fields:
            rules.update(fields)

        decorator = validate(**rules)

        if func:
            return decorator(func)

        return decorator
Exemple #2
0
    def validate(cls, strict=False, fields=None, ignore=None):
        if callable(strict):
            # Decorator is used without any parameter and call parentesis.
            func = strict
            strict = False
        else:
            func = None

        rules = cls.create_validation_rules(strict, ignore)
        if fields:
            for k, v in fields.items():
                d = rules.setdefault(k, {}).update(v)

        decorator = validate(**rules)

        if func:
            return decorator(func)

        return decorator
Exemple #3
0
import re

from nanohttp import validate

EMAIL_PATTERN = re.compile(
    r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)')

login_validator = validate(
    email=dict(
        required='722 Email Not In Form',
        pattern=(EMAIL_PATTERN, '701 Invalid Email Format'),
    ),
    password=dict(
        required='723 Password Is Not In Form',
        max_length=(50, '706 Title Length Is More Than 50'),
        min_length=(5, '707 Title Length Is More Than 50'),
    ),
)

member_validator = validate(
    email=dict(
        required='722 Email Not In Form',
        pattern=(EMAIL_PATTERN, '701 Invalid Email Format'),
    ),
    password=dict(
        required='723 Password Is Not In Form',
        max_length=(50, '706 Password Length Is More Than 50'),
        min_length=(5, '707 Password Length Is More Than 50'),
    ),
    name=dict(required='723 Name Not In Form', ),
)
Exemple #4
0
import re

from nanohttp import validate


TITLE_PATTERN = re.compile(r'^(?!\s).*[^\s]$')


create_room_validator = validate(
    title=dict(
        min_length=(1, '701 Must Be Greater Than 1 Charecters'),
        max_length=(50, '702 Must Be Less Than 50 Charecters'),
        required='703 Room Title Is Required',
    )
)


create_member_validator = validate(
    title=dict(
        min_length=(1, '701 Must Be Greater Than 1 Charecters'),
        max_length=(50, '702 Must Be Less Than 50 Charecters'),
        required='703 member Title Is Required',
    )
)


kick_member_validator = validate(
    memberId=dict(
        type_=(int, '705 Invalid Member Id'),
        required='709 Member Id Is Required',
    )
Exemple #5
0
import re

from nanohttp import validate


USER_EMAIL_PATTERN = \
    re.compile('(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)')
USER_TITLE_PATTERN = re.compile('^[a-zA-Z][\w]{5,16}$')

# Password be to have numbers, uppercase, and lowercase
USER_PASSWORD_PATTERN = re.compile('(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).+')

email_validator = validate(email=dict(required='701 Invalid Email Format',
                                      pattern=(USER_EMAIL_PATTERN,
                                               '701 Invalid Email Format')))

title_validator = validate(title=dict(required='705 Invalid Title Format',
                                      pattern=(USER_TITLE_PATTERN,
                                               '705 Invalid Title Format')))

password_validator = validate(
    password=dict(required='702 Invalid Password Length',
                  min_length=(6, '702 Invalid Password Length'),
                  max_length=(20, '702 Invalid Password Length'),
                  pattern=(USER_PASSWORD_PATTERN,
                           '703 Password Not Complex Enough')))

new_password_validator = validate(
    newPassword=dict(required='702 Invalid Password Length',
                     min_length=(6, '702 Invalid Password Length'),
                     max_length=(20, '702 Invalid Password Length'),
Exemple #6
0
import re

from nanohttp import validate, HTTPStatus, context, int_or_notfound, \
    HTTPBadRequest
from restfulpy.orm import DBSession
from restfulpy.datetimehelpers import parse_datetime

from .exceptions import *
from .models import *

USER_EMAIL_PATTERN = re.compile(
    r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)')

email_validator = validate(email=dict(required='400 Email Not In Form',
                                      pattern=(USER_EMAIL_PATTERN,
                                               '400 Invalid Email Format')))