1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from ...extension import parser
19 from .exceptions import PresenterNotFoundError
22 class PresenterSource(object):
24 Base class for ARIA presenter sources.
26 Presenter sources provide appropriate :class:`Presenter` classes for agnostic raw data.
29 def get_presenter(self, raw): # pylint: disable=unused-argument,no-self-use
30 raise PresenterNotFoundError('presenter not found')
33 class DefaultPresenterSource(PresenterSource):
35 The default ARIA presenter source.
38 def __init__(self, classes=None):
40 classes = parser.presenter_class()
41 self.classes = classes
43 def get_presenter(self, raw):
44 for cls in self.classes:
45 if cls.can_present(raw):
48 if 'tosca_definitions_version' in raw:
49 if raw['tosca_definitions_version'] is None:
50 raise PresenterNotFoundError("'tosca_definitions_version' is not specified")
51 if not isinstance(raw['tosca_definitions_version'], basestring):
52 raise PresenterNotFoundError("'tosca_definitions_version' is not a string")
53 if not raw['tosca_definitions_version']:
54 raise PresenterNotFoundError("'tosca_definitions_version' is not specified")
55 return super(DefaultPresenterSource, self).get_presenter(raw)