vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / parser / reading / reader.py
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12
13 from ...utils.openclose import OpenClose
14 from .exceptions import ReaderException, AlreadyReadException
15
16
17 class Reader(object):
18     """
19     Base class for ARIA readers.
20
21     Readers provide agnostic raw data by consuming :class:`aria.parser.loading.Loader` instances.
22     """
23
24     def __init__(self, context, location, loader):
25         self.context = context
26         self.location = location
27         self.loader = loader
28
29     def load(self):
30         with OpenClose(self.loader) as loader:
31             if self.context is not None:
32                 with self.context._locations:
33                     for location in self.context._locations:
34                         if location.is_equivalent(loader.location):
35                             raise AlreadyReadException('already read: %s' % loader.location)
36                     self.context._locations.append(loader.location)
37
38             data = loader.load()
39             if data is None:
40                 raise ReaderException('loader did not provide data: %s' % loader)
41             return data
42
43     def read(self):
44         raise NotImplementedError