Exemplo n.º 1
0
 def validate_keys(self, key_mapping):
     for pos, mapping in key_mapping.iteritems():
         if pos <= 0:
             raise errors.wrong_type('keys', 'numeric positions')
         if not isinstance(mapping, dict):
             raise errors.wrong_type('keys', 'dict-like structures')
         self.funckey_validator.validate(mapping)
Exemplo n.º 2
0
def _check_invalid_parameters(line):
    if line.context.strip() == '':
        raise errors.missing('context')
    try:
        line.device_slot = int(line.device_slot)
    except ValueError:
        raise errors.wrong_type('device_slot', 'positive numeric', device_slot=line.device_slot)
    if line.device_slot <= 0:
        raise errors.wrong_type('device_slot', 'positive numeric', device_slot=line.device_slot)
Exemplo n.º 3
0
    def _validate_parameters(self, parameters):
        if parameters['offset'] < 0:
            raise errors.wrong_type('offset', 'positive number')

        if parameters['limit'] is not None and parameters['limit'] <= 0:
            raise errors.wrong_type('limit', 'positive number')

        if parameters['direction'] not in self.SORT_DIRECTIONS.keys():
            raise errors.invalid_direction(parameters['direction'])
Exemplo n.º 4
0
def _validate_invalid_parameters(user_line):
    if not isinstance(user_line.user_id, int):
        raise errors.wrong_type('user_id', 'positive integer')
    if not isinstance(user_line.line_id, int):
        raise errors.wrong_type('line_id', 'positive integer')
    if hasattr(user_line, 'main_user') and not isinstance(user_line.main_user, bool):
        raise errors.wrong_type('main_user', 'boolean')
    if hasattr(user_line, 'main_line') and not isinstance(user_line.main_line, bool):
        raise errors.wrong_type('main_line', 'boolean')
Exemplo n.º 5
0
 def _extract_numeric(self, name, arguments):
     value = arguments.get(name, None)
     if value:
         if not value.isdigit():
             raise errors.wrong_type(name, 'positive number')
         value = int(value)
         if value < 0:
             raise errors.wrong_type(name, 'positive number')
         self.extracted[name] = value
Exemplo n.º 6
0
 def _extract_numeric(self, name, arguments):
     value = arguments.get(name, None)
     if value:
         if not value.isdigit():
             raise errors.wrong_type(name, 'positive number')
         value = int(value)
         if value < 0:
             raise errors.wrong_type(name, 'positive number')
         self.extracted[name] = value
Exemplo n.º 7
0
 def validate_option(self, option):
     if not isinstance(option, Iterable):
         raise errors.wrong_type('options', 'list of pair of strings')
     if not len(option) == 2:
         raise errors.wrong_type('options', 'list of pair of strings')
     for i in option:
         if not isinstance(i, (str, six.text_type)):
             raise errors.wrong_type('options',
                                     "value '{}' is not a string".format(i))
Exemplo n.º 8
0
    def _validate_parameters(self, parameters):
        if parameters['offset'] < 0:
            raise errors.wrong_type('offset', 'positive number')

        if parameters['limit'] is not None and parameters['limit'] <= 0:
            raise errors.wrong_type('limit', 'positive number')

        if parameters['direction'] not in self.SORT_DIRECTIONS.keys():
            raise errors.invalid_direction(parameters['direction'])
Exemplo n.º 9
0
 def _check_invalid_parameters(self, device):
     if device.ip and not self.IP_REGEX.match(device.ip):
         raise errors.wrong_type('ip', 'IP address', ip=device.ip)
     if device.mac and not self.MAC_REGEX.match(device.mac):
         raise errors.wrong_type('mac', 'MAC address', mac=device.mac)
     if device.options is not None:
         if not isinstance(device.options, dict):
             raise errors.wrong_type('options', 'dict-like structure', options=device.options)
         elif 'switchboard' in device.options and not isinstance(device.options['switchboard'], bool):
             raise errors.wrong_type('options.switchboard', 'boolean', switchboard=device.options['switchboard'])
Exemplo n.º 10
0
 def validate(self, device):
     options = device.options or {}
     if not isinstance(options, dict):
         raise errors.wrong_type('options',
                                 'dict-like structure',
                                 options=options)
     if 'switchboard' in options and not isinstance(options['switchboard'],
                                                    bool):
         raise errors.wrong_type('options.switchboard',
                                 'boolean',
                                 options=options)
Exemplo n.º 11
0
 def _extract_datetime(datetime_key, request_args):
     if datetime_key in request_args:
         try:
             return _decode_datetime(request_args[datetime_key])
         except ValueError:
             raise errors.wrong_type(datetime_key, 'datetime')
     raise errors.missing(datetime_key)
Exemplo n.º 12
0
def _check_invalid_parameters(user):
    if not user.firstname:
        raise errors.missing('firstname')
    if user.mobile_phone_number and not MOBILE_PHONE_NUMBER_REGEX.match(user.mobile_phone_number):
        raise errors.wrong_type('mobile_phone_number', 'numeric phone number')
    if user.password is not None and len(user.password) < 4:
        raise errors.minimum_length('password', 4)
Exemplo n.º 13
0
def validate_invalid_parameters(extension):
    if not extension.exten:
        raise errors.missing('exten')
    if not extension.context:
        raise errors.missing('context')
    if extension.commented not in [True, False]:
        raise errors.wrong_type('commented', 'boolean')
Exemplo n.º 14
0
 def _extract_datetime(datetime_key, request_args):
     if datetime_key in request_args:
         try:
             return _decode_datetime(request_args[datetime_key])
         except ValueError:
             raise errors.wrong_type(datetime_key, 'datetime')
     raise errors.missing(datetime_key)
Exemplo n.º 15
0
 def validate(self, model):
     values = getattr(model, self.field)
     for value in values:
         if not self.regex.match(value):
             message = "{} string matching regex '{}'".format(
                 value, self.regex.pattern)
             raise errors.wrong_type(self.field, message)
Exemplo n.º 16
0
 def validate(self, model):
     value = getattr(model, self.field)
     if not self.regex.match(value):
         if self.message:
             message = self.message
         else:
             message = "string matching regex '{}'".format(
                 self.regex.pattern)
         raise errors.wrong_type(self.field, message)
Exemplo n.º 17
0
 def parse(self, value):
     if value == "":
         return None
     if not value.isdigit():
         raise errors.wrong_type(self.csv_name, 'integer')
     return int(value)
Exemplo n.º 18
0
def validate_caller_id(user, required=False):
    if user.caller_id:
        if not CALLER_ID_REGEX.match(user.caller_id):
            raise errors.wrong_type('caller_id', 'formatted caller id string')
    elif required:
        raise errors.missing('caller_id')
Exemplo n.º 19
0
 def convert_numeric(self, key, value):
     if not value.isdigit():
         raise errors.wrong_type(key, "positive number")
     return int(value)
Exemplo n.º 20
0
 def validate_text(self, text, field):
     if text is not None:
         for char in self.INVALID_CHARS:
             if char in text:
                 raise errors.wrong_type(field, self.INVALID_CHARS_MSG,
                                         **{field: text})
Exemplo n.º 21
0
def _validate_exten(extension):
    if not extension.exten.isdigit():
        raise errors.wrong_type('exten', 'numeric string')
    return extension.exten
Exemplo n.º 22
0
 def validate_options(self, options):
     if not isinstance(options, Iterable):
         raise errors.wrong_type('options', 'list of pair of strings')