/usr/share/pyshared/tg/wsgiapp.py is in python-turbogears2 2.1.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import os
import sys
from pylons.wsgiapp import PylonsApp, class_name_from_module_name
from pylons.util import class_name_from_module_name
import logging
log = logging.getLogger(__name__)
import warnings
if sys.version_info[:2] == (2,4):
warnings.warn('Python 2.4 support is deprecated, and will be removed in TurboGears 2.2', DeprecationWarning)
class TGApp(PylonsApp):
def find_controller(self, controller):
"""Locates a controller by attempting to import it then grab
the SomeController instance from the imported module.
Override this to change how the controller object is found once
the URL has been resolved.
"""
# Check to see if we've cached the class instance for this name
if controller in self.controller_classes:
return self.controller_classes[controller]
root_module_path = self.config['paths']['root']
base_controller_path = self.config['paths']['controllers']
#remove the part of the path we expect to be the root part (plus one '/')
assert base_controller_path.startswith(root_module_path)
controller_path = base_controller_path[len(root_module_path)+1:]
#attach the package
pylons_package = self.config['pylons.package']
full_module_name = '.'.join([pylons_package] +
controller_path.split(os.sep) + controller.split('/'))
# Hide the traceback here if the import fails (bad syntax and such)
__traceback_hide__ = 'before_and_this'
__import__(full_module_name)
module_name = controller.split('/')[-1]
class_name = class_name_from_module_name(module_name) + 'Controller'
if self.log_debug:
log.debug("Found controller, module: '%s', class: '%s'",
full_module_name, class_name)
mycontroller = getattr(sys.modules[full_module_name], class_name)
self.controller_classes[controller] = mycontroller
return mycontroller
|