def validate(self, chunk): return_snippet = chunk.contents if type(chunk.contents) != CommentedMap: raise_exception( "when expecting a mapping", "found non-mapping", chunk, ) else: for key, value in chunk.contents.items(): if key not in self._validator_dict.keys(): raise_exception( u"while parsing a mapping", u"unexpected key not in schema '{0}'".format( unicode(key)), chunk.key(key)) validator = self._validator_dict[key] del return_snippet[key] return_snippet[YAML(key, chunk=chunk.key(key), validator=validator)] = validator( chunk.val(key)) return YAML(return_snippet, chunk=chunk, validator=self)
def validate_scalar(self, chunk, value): val = unicode(chunk.contents) if value is None else value return YAML( [ YAML(self._item_validator.validate_scalar(chunk, value=item.lstrip())) for item in val.split(",") ], chunk=chunk, )
def validate_scalar(self, chunk, value=None): val = unicode(chunk.contents) if value is None else value if unicode(val).lower() not in constants.BOOL_VALUES: raise_exception( """when expecting a boolean value (one of "{0}")""".format( '", "'.join(constants.BOOL_VALUES)), "found non-boolean", chunk, ) else: if val.lower() in constants.TRUE_VALUES: return YAML(True, val, chunk=chunk, validator=self) else: return YAML(False, val, chunk=chunk, validator=self)
def validate_scalar(self, chunk, value=None): return YAML( unicode(chunk.contents) if value is None else value, text=chunk.contents, chunk=chunk, validator=self, )
def validate(self, chunk): return_snippet = chunk.contents if not isinstance(return_snippet, CommentedSeq): raise_exception( "when expecting a sequence of {0} elements".format( len(self._validators)), "found non-sequence", chunk, ) else: if len(self._validators) != len(chunk.contents): raise_exception( "when expecting a sequence of {0} elements".format( len(self._validators)), "found a sequence of {0} elements".format( len(chunk.contents)), chunk, ) for i, item_and_val in enumerate( zip(chunk.contents, self._validators)): item, validator = item_and_val return_snippet[i] = validator(chunk.index(i)) return YAML(return_snippet, chunk=chunk)
def __call__(self, chunk): chunk.expect_scalar(self.rule_description) return YAML( self.validate_scalar(chunk), text=chunk.contents, chunk=chunk, validator=self, )
def __call__(self, chunk): self.validate(chunk) return YAML( chunk.strictparsed(), text=None, chunk=chunk, validator=self, )
def validate_scalar(self, chunk, value=None): val = unicode(chunk.contents) if value is None else value if not utils.is_integer(val): raise_exception( "when expecting an integer", "found non-integer", chunk, ) else: return YAML(int(val), val, chunk=chunk)
def validate_scalar(self, chunk, value=None): val = unicode(chunk.contents) if value is None else value if not utils.is_decimal(val): raise_exception( "when expecting a decimal", "found non-decimal", chunk, ) else: return YAML(decimal.Decimal(val), val, chunk=chunk, validator=self)
def validate_scalar(self, chunk, value): val = unicode(chunk.contents) if value is None else value if val not in self._restricted_to: raise_exception( "when expecting one of: {0}".format(", ".join(self._restricted_to)), "found '{0}'".format(val), chunk, ) else: return YAML(val, chunk=chunk)
def validate_scalar(self, chunk, value=None): val = unicode(chunk.contents) if value is None else value try: return YAML(dateutil.parser.parse(val), val, chunk=chunk) except ValueError: raise_exception( "when expecting a datetime", "found non-datetime", chunk, )
def validate_scalar(self, chunk, value=None): if re.compile(self._regex).match(chunk.contents) is None: raise_exception( self._matching_message, "found non-matching string", chunk, ) return YAML( unicode(chunk.contents) if value is None else value, text=chunk.contents, chunk=chunk )
def validate(self, chunk): return_snippet = chunk.contents if not isinstance(return_snippet, CommentedSeq): raise_exception( "when expecting a sequence", "found non-sequence", chunk, ) else: for i, item in enumerate(chunk.contents): return_snippet[i] = self._validator(chunk.index(i)) return YAML(return_snippet, chunk=chunk)
def validate(self, chunk): return_snippet = chunk.contents if not isinstance(return_snippet, CommentedMap): raise_exception( "when expecting a mapping", "found non-mapping", chunk, ) else: for key, value in chunk.contents.items(): valid_key = self._key_validator(chunk.key(key)) valid_val = self._value_validator(chunk.val(key)) return_snippet[valid_key] = valid_val del return_snippet[valid_key] return_snippet[valid_key] = self._value_validator( chunk.val(key)) return YAML(return_snippet, chunk=chunk)
def validate(self, chunk): return_snippet = chunk.contents if type(chunk.contents) != CommentedSeq: raise_exception( "when expecting a unique sequence", "found non-sequence", chunk, ) else: existing_items = set() for i, item in enumerate(chunk.contents): if item in existing_items: raise_exception("while parsing a sequence", "duplicate found", chunk) else: existing_items.add(item) return_snippet[i] = self._validator(chunk.index(i)) return YAML(return_snippet, chunk=chunk)
def empty(self, chunk): return YAML(None, '', chunk=chunk)
def __call__(self, chunk): self.validate(chunk) return YAML(chunk, validator=self)
def empty(self, chunk): return YAML([], '', chunk=chunk, validator=self)
def empty(self, chunk): return YAML([], '', chunk=chunk)
def __call__(self, chunk): chunk.expect_scalar(self.rule_description) return YAML(chunk, validator=self)