Пример #1
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)

        from jsonspec.operations import remove, Error
        from jsonspec.pointer import ParseError

        try:
            response = remove(args.document, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error:
            raise Exception('{} does not match'.format(args.pointer))
        except ParseError:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #2
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)

        from jsonspec.operations import remove, Error
        from jsonspec.pointer import ParseError

        try:
            response = remove(args.document, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error:
            raise Exception('{} does not match'.format(args.pointer))
        except ParseError:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #3
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)

        from jsonspec.pointer import extract
        from jsonspec.pointer import ExtractError, ParseError

        try:
            response = extract(args.document, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except ExtractError:
            raise Exception(args)
            raise Exception('{} does not match'.format(args.pointer))
        except ParseError:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #4
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)
        parse_target(args)

        from jsonspec.operations import copy, Error
        from jsonspec.pointer import ParseError

        try:
            response = copy(args.document, args.target, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #5
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)

        from jsonspec.pointer import extract
        from jsonspec.pointer import ExtractError, ParseError

        try:
            response = extract(args.document, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except ExtractError:
            raise Exception(args)
            raise Exception('{} does not match'.format(args.pointer))
        except ParseError:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #6
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)
        parse_target(args)

        from jsonspec.operations import copy, Error
        from jsonspec.pointer import ParseError

        try:
            response = copy(args.document, args.target, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #7
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)
        parse_fragment(args)

        from jsonspec.operations import replace, Error
        from jsonspec.pointer import ParseError

        try:
            response = replace(args.document, args.pointer, args.fragment)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception("{} is not a valid pointer".format(args.pointer))
Пример #8
0
    def run(self, args):
        parse_document(args)
        parse_schema(args)

        from jsonspec.validators import load
        from jsonspec.validators import ValidationError

        try:
            validated = load(args.schema).validate(args.document)
            return driver.dumps(validated, indent=args.indent)
        except ValidationError as error:
            msg = 'document does not validate with schema.\n\n'
            for pointer, reasons in error.flatten.items():
                msg += '  {}\n'.format(pointer)
                for reason in reasons:
                    msg += '    - reason {}\n'.format(reason)
                msg += '\n'
            raise Exception(msg)
Пример #9
0
    def run(self, args):
        parse_document(args)
        parse_schema(args)

        from jsonspec.validators import load
        from jsonspec.validators import ValidationError

        try:
            validated = load(args.schema).validate(args.document)
            return driver.dumps(validated, indent=args.indent)
        except ValidationError as error:
            msg = 'document does not validate with schema.\n\n'
            for pointer, reasons in error.flatten().items():
                msg += '  {}\n'.format(pointer)
                for reason in reasons:
                    msg += '    - reason {}\n'.format(reason)
                msg += '\n'
            raise Exception(msg)
Пример #10
0
 def validate_unique_items(self, obj, pointer=None):
     if self.attrs.get('unique_items'):
         if len(obj) > len(set(json.dumps(element) for element in obj)):
             self.fail('Elements must be unique', obj, pointer)
     return obj
Пример #11
0
 def validate_unique_items(self, obj, pointer=None):
     if self.attrs.get('unique_items'):
         if len(obj) > len(set(json.dumps(element) for element in obj)):
             self.fail('Elements must be unique', obj, pointer)
     return obj