def get_object(self, vars, routeobj): """ Given the matching variables, find the object that it points to. Typically this means finding the ``controller.action`` module/object/method. """ controller = vars['controller'] if controller.startswith('egg:'): return self.get_egg_object(vars, routeobj) controller = self.controller_prefix + controller if vars.get('action'): if ':' not in controller: controller = controller + ':' + vars['action'] else: controller = controller + '.' + vars['action'] if ':' in controller: controller_mod, controller_name = controller.split(':', 1) else: controller_mod = controller controller_name = 'index' if controller_mod not in sys.modules: import_string.simple_import(controller_mod) controller_mod = sys.modules[controller_mod] obj = controller_mod for part in controller_name.split('.'): obj = getattr(obj, part) return obj
def load_sysconfigs(self): configs = self.sysconfigs[:] configs.reverse() self.sysconfig_modules = [] for index, (explicit, name) in enumerate(configs): # @@: At some point I'd like to give the specialized # modules some access to the values in earlier modules, # e.g., to specialize those values or functions. That's # why these modules are loaded backwards. if name.endswith(".py"): if not os.path.exists(name): if explicit: raise BadCommand, ("sysconfig file %s does not exist" % name) else: continue globs = {} execfile(name, globs) mod = new.module("__sysconfig_%i__" % index) for name, value in globs.items(): setattr(mod, name, value) mod.__file__ = name else: try: mod = import_string.simple_import(name) except ImportError, e: if explicit: raise else: continue mod.paste_command = self self.sysconfig_modules.insert(0, mod)
def load_sysconfigs(self): configs = self.sysconfigs[:] configs.reverse() self.sysconfig_modules = [] for index, (explicit, name) in enumerate(configs): # @@: At some point I'd like to give the specialized # modules some access to the values in earlier modules, # e.g., to specialize those values or functions. That's # why these modules are loaded backwards. if name.endswith('.py'): if not os.path.exists(name): if explicit: raise BadCommand, ("sysconfig file %s does not exist" % name) else: continue globs = {} execfile(name, globs) mod = new.module('__sysconfig_%i__' % index) for name, value in globs.items(): setattr(mod, name, value) mod.__file__ = name else: try: mod = import_string.simple_import(name) except ImportError, e: if explicit: raise else: continue mod.paste_command = self self.sysconfig_modules.insert(0, mod)
def __call__(self, environ, start_response): global cache, request cache = environ['beaker.cache'] app_cache = cache.get_cache(__name__) request = Request(environ) urlvars = request.urlvars.copy() if 'controller' in urlvars and 'action' in urlvars: if urlvars['action'].startswith('_'): start_response(status, headers) return HTTPNotFound() module_reference = 'solder.controllers.%s' % urlvars['controller'] module = simple_import(module_reference) action = getattr(module, urlvars['action']) if inspect.isfunction(action): cache_key = urlvars.copy() del urlvars['controller'] del urlvars['action'] cache_key['hash'] = str(urlvars) cache_key['is_xhr'] = request.is_xhr # TODO something with format if 'format' in urlvars: del urlvars['format'] key = Template('$controller-$action-$hash-$is_xhr') key = key.substitute(**cache_key) res = app_cache.get(key=key, createfunc=lambda: self._create_content(action,\ urlvars, request.is_xhr)) else: res = app_cache.get(key='not-found', createfunc=self._create_not_found) else: res = app_cache.get(key='not-found', createfunc=self._create_not_found) return res(environ, start_response)
def __call__(self, environ, start_response): global cache, request cache = environ["beaker.cache"] app_cache = cache.get_cache(__name__) request = Request(environ) urlvars = request.urlvars.copy() if "controller" in urlvars and "action" in urlvars: if urlvars["action"].startswith("_"): start_response(status, headers) return HTTPNotFound() module_reference = "solder.controllers.%s" % urlvars["controller"] module = simple_import(module_reference) action = getattr(module, urlvars["action"]) if inspect.isfunction(action): cache_key = urlvars.copy() del urlvars["controller"] del urlvars["action"] cache_key["hash"] = str(urlvars) cache_key["is_xhr"] = request.is_xhr # TODO something with format if "format" in urlvars: del urlvars["format"] key = Template("$controller-$action-$hash-$is_xhr") key = key.substitute(**cache_key) res = app_cache.get(key=key, createfunc=lambda: self._create_content(action, urlvars, request.is_xhr)) else: res = app_cache.get(key="not-found", createfunc=self._create_not_found) else: res = app_cache.get(key="not-found", createfunc=self._create_not_found) return res(environ, start_response)
def main(args=None): if args is None: args = sys.argv[1:] options, args = parser.parse_args(args) if len(args) < 1: print "Please enter one SITE" parser.print_help() sys.exit(1) urls = args mapper_options = {} for value in options.mapper_options or []: if ':' not in value: print 'Bad argument to --option: %r' % value parser.print_help() sys.exit(1) name, value = value.split(':', 1) mapper_options[name] = value mapper = options.mapper if mapper.endswith('.py'): mapper_mod = new.module('__mapper__') execfile(mapper, mapper_mod.__dict__) else: from paste.util import import_string mapper_mod = import_string.simple_import(mapper) output = options.output if not output: output = urlparse.urlsplit(urls[0])[1] verbosity = 1 + (options.verbose or 0) - (options.quiet or 0) if not options.hosts: options.hosts = [urlparse.urlsplit(urls[0])[1].split(':')[0]] url_matcher = URLMatcher(options.hosts, options.base_url, verbosity) mapper_options['url_matcher'] = url_matcher mapper_options['host_options'] = options.hosts mapper_options['base_url'] = options.base_url if options.base_url: mapper_options['base_path'] = urlparse.urlsplit(options.base_url)[2] mapper_options['urls'] = urls policy = Policy(mapper_mod, mapper_options) run_command(urls, output, policy, options.redir, verbosity, options.recurse, url_matcher)
def load_sysconfigs(self): configs = self.sysconfigs[:] configs.reverse() self.sysconfig_modules = [] for index, (explicit, name) in enumerate(configs): # @@: At some point I'd like to give the specialized # modules some access to the values in earlier modules, # e.g., to specialize those values or functions. That's # why these modules are loaded backwards. if name.endswith('.py'): if not os.path.exists(name): if explicit: raise BadCommand( "sysconfig file %s does not exist" % name) else: continue globs = {} exec(compile(open(name).read(), name, 'exec'), globs) mod = new.module('__sysconfig_%i__' % index) for name, value in list(globs.items()): setattr(mod, name, value) mod.__file__ = name else: try: mod = import_string.simple_import(name) except ImportError as e: if explicit: raise else: continue mod.paste_command = self self.sysconfig_modules.insert(0, mod) # @@: I'd really prefer to clone the parser here somehow, # not to modify it in place parser = self.parser self.call_sysconfig_functions('add_custom_options', parser)
def do_doctest_mod(module): module = simple_import(module) failure, total = doctest.testmod(module, optionflags=options) assert not failure, "Failure in %r" % module
def do_doctest_mod(module): module = simple_import(module) failure, total = doctest.testmod( module, optionflags=options) assert not failure, "Failure in %r" % module
def init(self): for module_name in self.import_modules: module_name = self.package_name + '.' + module_name import_string.simple_import(module_name)