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.
16 from aria.parser.loading import UriLocation
17 from aria.parser.consumption import (
27 from aria.utils.imports import import_fullname
30 def create_context(uri,
31 loader_source='aria.parser.loading.DefaultLoaderSource',
32 reader_source='aria.parser.reading.DefaultReaderSource',
33 presenter_source='aria.parser.presentation.DefaultPresenterSource',
36 context = ConsumptionContext()
37 context.loading.loader_source = import_fullname(loader_source)()
38 context.reading.reader_source = import_fullname(reader_source)()
39 context.presentation.location = UriLocation(uri) if isinstance(uri, basestring) else uri
40 context.presentation.presenter_source = import_fullname(presenter_source)()
41 context.presentation.presenter_class = import_fullname(presenter)
42 context.presentation.print_exceptions = debug
46 def create_consumer(context, consumer_class_name):
47 consumer = ConsumerChain(context, (Read, Validate))
49 if consumer_class_name == 'validate':
51 elif consumer_class_name == 'presentation':
52 dumper = consumer.consumers[0]
53 elif consumer_class_name == 'template':
54 consumer.append(ServiceTemplate)
55 elif consumer_class_name == 'types':
56 consumer.append(ServiceTemplate, Types)
57 elif consumer_class_name == 'instance':
58 consumer.append(ServiceTemplate, Inputs, ServiceInstance)
60 consumer.append(ServiceTemplate, Inputs, ServiceInstance)
61 consumer.append(import_fullname(consumer_class_name))
64 # Default to last consumer
65 dumper = consumer.consumers[-1]
67 return consumer, dumper