vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / parser / loading / location.py
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16
17 import os
18
19 from ...utils.uris import as_file
20
21
22 class Location(object):
23     """
24     Base class for ARIA locations.
25
26     Locations are used by :class:`~aria.parser.loading.LoaderSource` to delegate to
27     an appropriate :class:`~aria.parser.loading.Loader`.
28     """
29
30     def is_equivalent(self, location):
31         raise NotImplementedError
32
33     @property
34     def prefix(self):
35         return None
36
37
38 class UriLocation(Location):
39     """
40     A URI location can be absolute or relative, and can include a scheme or not.
41
42     If no scheme is included, it should be treated as a filesystem path.
43
44     See :class:`~aria.parser.loading.UriTextLoader`.
45     """
46
47     def __init__(self, uri):
48         self.uri = uri
49
50     def is_equivalent(self, location):
51         return isinstance(location, UriLocation) and (location.uri == self.uri)
52
53     @property
54     def prefix(self):
55         prefix = os.path.dirname(self.uri)
56         if prefix and (as_file(prefix) is None):
57             # Yes, it's weird, but dirname handles URIs,
58             # too: http://stackoverflow.com/a/35616478/849021
59             # We just need to massage it with a trailing slash
60             prefix += '/'
61         return prefix
62
63     def __str__(self):
64         return self.uri
65
66
67 class LiteralLocation(Location):
68     """
69     A location that embeds content.
70
71     See :class:`~aria.parser.loading.LiteralLoader`.
72     """
73
74     def __init__(self, content, name='literal'):
75         self.content = content
76         self.name = name
77
78     def is_equivalent(self, location):
79         return isinstance(location, LiteralLocation) and (location.content == self.content)
80
81     def __str__(self):
82         return '<%s>' % self.name