コード例 #1
0
ファイル: decimal.py プロジェクト: Polipaul13/for_resume
 def interpolate(self, subject, parameters, interpolator=None):
     if subject is None:
         return None
     elif isinstance(subject, decimal):
         return subject
     else:
         return decimal(interpolate_parameters(subject, parameters, True, interpolator))
コード例 #2
0
ファイル: integer.py プロジェクト: egon1024/scheme
 def interpolate(self, subject, parameters, interpolator=None):
     if subject is None:
         return None
     elif isinstance(subject, numbers):
         return int(subject)
     else:
         return int(interpolate_parameters(subject, parameters, True, interpolator))
コード例 #3
0
ファイル: tuple.py プロジェクト: Polipaul13/for_resume
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        if not isinstance(subject, (list, tuple)):
            raise CannotInterpolateError(
                'interpolation candidate must be a list or tuple')

        interpolation = []
        for i, definition in enumerate(self.values):
            try:
                interpolation.append(
                    definition.interpolate(subject[i], parameters,
                                           interpolator))
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError(
                        "field %r of this tuple is undefined" % i)
                else:
                    raise

        return tuple(interpolation)
コード例 #4
0
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        if not isinstance(subject, dict):
            raise CannotInterpolateError(
                'interpolation candidate must be a dict value')

        definition = self.value
        interpolation = {}

        for key, value in subject.items():
            try:
                interpolation[key] = definition.interpolate(
                    value, parameters, interpolator)
            except UndefinedParameterError:
                continue
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError(
                        "the 'value' field of this map is undefined")
                else:
                    raise

        return interpolation
コード例 #5
0
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        if not isinstance(subject, dict):
            raise CannotInterpolateError(
                'interpolation candidate must be a dict value')

        definition = self._get_definition(subject)
        interpolation = {}

        for name, field in definition.items():
            try:
                value = subject[name]
            except KeyError:
                continue

            try:
                interpolation[name] = field.interpolate(
                    value, parameters, interpolator)
            except UndefinedParameterError:
                continue
            except AttributeError:
                if isinstance(field, Undefined):
                    raise UndefinedFieldError(
                        'the %r field of this structure is undefined' % name)
                else:
                    raise

        return interpolation
コード例 #6
0
ファイル: sequence.py プロジェクト: Polipaul13/for_resume
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        if not isinstance(subject, (list, tuple)):
            raise CannotInterpolateError(
                'interpolation candidate must be a list or tuple value')

        definition = self.item
        interpolation = []

        for item in subject:
            try:
                interpolation.append(
                    definition.interpolate(item, parameters, interpolator))
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError(
                        'the item field of this sequence is undefined')
                else:
                    raise

        return interpolation
コード例 #7
0
ファイル: map.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True, interpolator)

        if not isinstance(subject, dict):
            raise CannotInterpolateError('interpolation candidate must be a dict value')

        definition = self.value
        interpolation = {}

        for key, value in subject.items():
            try:
                interpolation[key] = definition.interpolate(value, parameters, interpolator)
            except UndefinedParameterError:
                continue
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError("the 'value' field of this map is undefined")
                else:
                    raise

        return interpolation
コード例 #8
0
ファイル: token.py プロジェクト: Polipaul13/for_resume
 def interpolate(self, subject, parameters, interpolator=None):
     if subject is None:
         return subject
     else:
         return interpolate_parameters(subject,
                                       parameters,
                                       interpolator=interpolator)
コード例 #9
0
ファイル: structure.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True, interpolator)

        if not isinstance(subject, dict):
            raise CannotInterpolateError('interpolation candidate must be a dict value')

        definition = self._get_definition(subject)
        interpolation = {}

        for name, field in definition.items():
            try:
                value = subject[name]
            except KeyError:
                continue

            try:
                interpolation[name] = field.interpolate(value, parameters, interpolator)
            except UndefinedParameterError:
                continue
            except AttributeError:
                if isinstance(field, Undefined):
                    raise UndefinedFieldError('the %r field of this structure is undefined' % name)
                else:
                    raise

        return interpolation
コード例 #10
0
ファイル: field.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        """Attempts to interpolate variables within ``subject`` using the specified
        ``parameters``."""

        equivalent = self.equivalent
        if subject is None or (equivalent and isinstance(subject, equivalent)):
            return subject
        else:
            return interpolate_parameters(subject, parameters, True, interpolator)
コード例 #11
0
 def interpolate(self, subject, parameters, interpolator=None):
     if subject is None:
         return None
     elif isinstance(subject, numbers):
         return int(subject)
     else:
         return int(
             interpolate_parameters(subject, parameters, True,
                                    interpolator))
コード例 #12
0
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None or subject in self.enumeration:
            return subject

        value = interpolate_parameters(subject, parameters, True, interpolator)
        if value in self.enumeration:
            return value
        else:
            raise CannotInterpolateError(
                'subject must be a value in this enumeration')
コード例 #13
0
ファイル: field.py プロジェクト: Polipaul13/for_resume
    def interpolate(self, subject, parameters, interpolator=None):
        """Attempts to interpolate variables within ``subject`` using the specified
        ``parameters``."""

        equivalent = self.equivalent
        if subject is None or (equivalent and isinstance(subject, equivalent)):
            return subject
        else:
            return interpolate_parameters(subject, parameters, True,
                                          interpolator)
コード例 #14
0
ファイル: surrogate.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return subject
        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True, interpolator)

        if isinstance(subject, surrogate):
            return subject
        elif isinstance(subject, dict):
            return surrogate.interpolate(subject, parameters, interpolator)
        else:
            raise ValueError(subject)
コード例 #15
0
ファイル: surrogate.py プロジェクト: Polipaul13/for_resume
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return subject
        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        if isinstance(subject, surrogate):
            return subject
        elif isinstance(subject, dict):
            return surrogate.interpolate(subject, parameters, interpolator)
        else:
            raise ValueError(subject)
コード例 #16
0
ファイル: union.py プロジェクト: Polipaul13/for_resume
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None
        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True,
                                             interpolator)

        for field in self.fields:
            try:
                return field.interpolate(subject, parameters, interpolater)
            except CannotInterpolateError:
                pass
            except AttributeError:
                if isinstance(field, Undefined):
                    raise UndefinedFieldError(
                        'a field of this union is undefined')
                else:
                    raise
        else:
            raise CannotInterpolateError('union interpolation failed')
コード例 #17
0
ファイル: test_interpolation.py プロジェクト: egon1024/scheme
    def test_template_interpolation(self):
        result = interpolate_parameters('${alpha}', {'alpha': 1, 'beta': 2})
        self.assertEqual(result, '1')

        result = interpolate_parameters('${alpha} - ${beta}', {'alpha': 1, 'beta': 2})
        self.assertEqual(result, '1 - 2')

        result = interpolate_parameters('${alpha}', {'beta': 2})
        self.assertEqual(result, '')

        result = interpolate_parameters('', {'beta': 2})
        self.assertEqual(result, '')

        with self.assertRaises(ValueError):
            interpolate_parameters(True, {})
コード例 #18
0
ファイル: tuple.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True, interpolator)

        if not isinstance(subject, (list, tuple)):
            raise CannotInterpolateError('interpolation candidate must be a list or tuple')

        interpolation = []
        for i, definition in enumerate(self.values):
            try:
                interpolation.append(definition.interpolate(subject[i], parameters, interpolator))
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError("field %r of this tuple is undefined" % i)
                else:
                    raise

        return tuple(interpolation)
コード例 #19
0
ファイル: sequence.py プロジェクト: egon1024/scheme
    def interpolate(self, subject, parameters, interpolator=None):
        if subject is None:
            return None

        if isinstance(subject, string):
            subject = interpolate_parameters(subject, parameters, True, interpolator)

        if not isinstance(subject, (list, tuple)):
            raise CannotInterpolateError('interpolation candidate must be a list or tuple value')

        definition = self.item
        interpolation = []

        for item in subject:
            try:
                interpolation.append(definition.interpolate(item, parameters, interpolator))
            except AttributeError:
                if isinstance(definition, Undefined):
                    raise UndefinedFieldError('the item field of this sequence is undefined')
                else:
                    raise

        return interpolation
コード例 #20
0
ファイル: test_interpolation.py プロジェクト: egon1024/scheme
    def test_simple_interpolation(self):
        result = interpolate_parameters('${alpha}', {'alpha': 1, 'beta': 2}, True)
        self.assertEqual(result, 1)

        result = interpolate_parameters('${alpha}', {'alpha': '1', 'beta': '2'}, True)
        self.assertEqual(result, '1')
コード例 #21
0
ファイル: emailtemplate.py プロジェクト: siq/flux
 def evaluate(self, parameters):
     return interpolate_parameters(self.template, parameters)
コード例 #22
0
ファイル: uuid.py プロジェクト: egon1024/scheme
 def interpolate(self, subject, parameters, interpolator=None):
     if subject is None:
         return subject
     else:
         return interpolate_parameters(subject, parameters, True, interpolator)
コード例 #23
0
ファイル: emailtemplate.py プロジェクト: siq/flux
 def evaluate(self, parameters):
     return interpolate_parameters(self.template, parameters)