1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') 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
|
|
|
from pecan import expose |
17
|
|
|
|
18
|
|
|
__all__ = [ |
19
|
|
|
'BaseRootController' |
20
|
|
|
] |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class BaseRootController(object): |
24
|
|
|
logger = None |
25
|
|
|
controllers = None |
26
|
|
|
default_controller = None |
27
|
|
|
|
28
|
|
|
@expose() |
29
|
|
|
def _lookup(self, *remainder): |
30
|
|
|
version = '' |
31
|
|
|
if len(remainder) > 0: |
32
|
|
|
version = remainder[0] |
33
|
|
|
|
34
|
|
|
if remainder[len(remainder) - 1] == '': |
35
|
|
|
# If the url has a trailing '/' remainder will contain an empty string. |
36
|
|
|
# In order for further pecan routing to work this method needs to remove |
37
|
|
|
# the empty string from end of the tuple. |
38
|
|
|
remainder = remainder[:len(remainder) - 1] |
39
|
|
|
versioned_controller = self.controllers.get(version, None) |
40
|
|
|
if versioned_controller: |
41
|
|
|
return versioned_controller, remainder[1:] |
42
|
|
|
self.logger.debug('No version specified in URL. Will use default controller.') |
43
|
|
|
return self.default_controller, remainder |
44
|
|
|
|