Beispiel #1
0
    def __init__(self, message, obj=None, parent_obj=None):
        super(MarkedError, self).__init__(message)

        if hasattr(obj, 'start_mark'):
            self.obj = obj
            self.start_mark = obj.start_mark
            self.end_mark = obj.end_mark
        elif (  parent_obj and (obj in parent_obj) and
                hasattr(parent_obj, 'start_mark')):
            self.obj = obj_key_node(parent_obj, obj)
            self.start_mark = self.obj.start_mark
            self.end_mark = self.obj.end_mark
        else:
            self.start_mark = None
            self.end_mark = None
    def __init__(self, message, obj=None, parent_obj=None):
        self.message = message
        super(MarkedError, self).__init__(message)

        if hasattr(obj, 'start_mark'):
            self.obj = obj
            self.start_mark = obj.start_mark
            self.end_mark = obj.end_mark
        elif (parent_obj and (obj in parent_obj)
              and hasattr(parent_obj, 'start_mark')):
            self.obj = obj_key_node(parent_obj, obj)
            self.start_mark = self.obj.start_mark
            self.end_mark = self.obj.end_mark
        else:
            self.start_mark = None
            self.end_mark = None
    def mark_object(self, obj, prop=None, as_key=False, required=False):
        """Associtate input property marks with a object.

        Used by tools that use marked input to copy their marks to
        representitive objects. Invoke for objects that are not constructed
        by the parser class.

        :param obj: The object that represents the property
        :param prop: The property that is being represented. If None, the
            full input is used.
        :param as_key: Assoicate with the key of the property instead of it's
            value.
        :param bool required: Causes ParseError to be raised if `prop`
            is not in the input
        :raises reschema.exceptions.ParseError: if the type of the
            data is incorrect or if the property is required but
            missing.

        """

        # If object aleady is marked, short circuit.
        if hasattr(obj, "start_mark"):
            return

        if prop is None:
            val = self.input
        else:
            val = obj_key_node(self.input, prop)
            if val is None:
                if required:
                    raise ParseError(
                        "Missing required property '%s'" % prop, self.input)
                return
            if not as_key:
                val = self.input[val]

        if hasattr(val, "start_mark"):
            obj.start_mark = val.start_mark
            obj.end_mark = val.end_mark
Beispiel #4
0
    def mark_object(self, obj, prop=None, as_key=False, required=False):
        """Associtate input property marks with a object.

        Used by tools that use marked input to copy their marks to
        representitive objects. Invoke for objects that are not constructed
        by the parser class.

        :param obj: The object that represents the property
        :param prop: The property that is being represented. If None, the
            full input is used.
        :param as_key: Assoicate with the key of the property instead of it's
            value.
        :param bool required: Causes ParseError to be raised if `prop`
            is not in the input
        :raises reschema.exceptions.ParseError: if the type of the
            data is incorrect or if the property is required but
            missing.

        """

        # If object aleady is marked, short circuit.
        if hasattr(obj, "start_mark"):
            return

        if prop is None:
            val = self.input
        else:
            val = obj_key_node(self.input, prop)
            if val is None:
                if required:
                    raise ParseError(
                        "Missing required property '%s'" % prop, self.input)
                return
            if not as_key:
                val = self.input[val]

        if hasattr(val, "start_mark"):
            obj.start_mark = val.start_mark
            obj.end_mark = val.end_mark