def renderer_factory(info): path = info.name registry = info.registry settings = info.settings lookup = registry.queryUtility(IMakoLookup) if lookup is None: reload_templates = settings.get('reload_templates', False) directories = settings.get('mako.directories', None) module_directory = settings.get('mako.module_directory', None) input_encoding = settings.get('mako.input_encoding', 'utf-8') error_handler = settings.get('mako.error_handler', None) default_filters = settings.get('mako.default_filters', 'h') imports = settings.get('mako.imports', None) strict_undefined = settings.get('mako.strict_undefined', 'false') preprocessor = settings.get('mako.preprocessor', None) if directories is None: raise ConfigurationError( 'Mako template used without a ``mako.directories`` setting') if not is_nonstr_iter(directories): directories = list(filter(None, directories.splitlines())) directories = [ abspath_from_asset_spec(d) for d in directories ] if module_directory is not None: module_directory = abspath_from_asset_spec(module_directory) if error_handler is not None: dotted = DottedNameResolver(info.package) error_handler = dotted.maybe_resolve(error_handler) if default_filters is not None: if not is_nonstr_iter(default_filters): default_filters = list(filter( None, default_filters.splitlines())) if imports is not None: if not is_nonstr_iter(imports): imports = list(filter(None, imports.splitlines())) strict_undefined = asbool(strict_undefined) if preprocessor is not None: dotted = DottedNameResolver(info.package) preprocessor = dotted.maybe_resolve(preprocessor) lookup = PkgResourceTemplateLookup(directories=directories, module_directory=module_directory, input_encoding=input_encoding, error_handler=error_handler, default_filters=default_filters, imports=imports, filesystem_checks=reload_templates, strict_undefined=strict_undefined, preprocessor=preprocessor) registry_lock.acquire() try: registry.registerUtility(lookup, IMakoLookup) finally: registry_lock.release() return MakoLookupTemplateRenderer(path, lookup)
def renderer_factory(info): path = info.name registry = info.registry settings = info.settings lookup = registry.queryUtility(IMakoLookup) if lookup is None: reload_templates = settings.get('reload_templates', False) directories = settings.get('mako.directories', None) module_directory = settings.get('mako.module_directory', None) input_encoding = settings.get('mako.input_encoding', 'utf-8') error_handler = settings.get('mako.error_handler', None) default_filters = settings.get('mako.default_filters', 'h') imports = settings.get('mako.imports', None) strict_undefined = settings.get('mako.strict_undefined', 'false') preprocessor = settings.get('mako.preprocessor', None) if directories is None: raise ConfigurationError( 'Mako template used without a ``mako.directories`` setting') if not hasattr(directories, '__iter__'): directories = filter(None, directories.splitlines()) directories = [abspath_from_asset_spec(d) for d in directories] if module_directory is not None: module_directory = abspath_from_asset_spec(module_directory) if error_handler is not None: dotted = DottedNameResolver(info.package) error_handler = dotted.maybe_resolve(error_handler) if default_filters is not None: if not hasattr(default_filters, '__iter__'): default_filters = filter(None, default_filters.splitlines()) if imports is not None: if not hasattr(imports, '__iter__'): imports = filter(None, imports.splitlines()) strict_undefined = asbool(strict_undefined) if preprocessor is not None: dotted = DottedNameResolver(info.package) preprocessor = dotted.maybe_resolve(preprocessor) lookup = PkgResourceTemplateLookup(directories=directories, module_directory=module_directory, input_encoding=input_encoding, error_handler=error_handler, default_filters=default_filters, imports=imports, filesystem_checks=reload_templates, strict_undefined=strict_undefined, preprocessor=preprocessor) registry_lock.acquire() try: registry.registerUtility(lookup, IMakoLookup) finally: registry_lock.release() return MakoLookupTemplateRenderer(path, lookup)
def pshell_file_config(self, filename): config = self.ConfigParser() config.optionxform = str config.read(filename) # Avoid DEFAULT section items = config._sections.get('pshell', None) if not items: return resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in items.iteritems(): if k == '__name__': continue if k == 'setup': self.setup = v elif k == 'default_shell': self.preferred_shells = [x.lower() for x in aslist(v)] else: try: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v except ImportError: print "Pshell ImportError\n" print k, v
def pcelery(args=None): argv = list(sys.argv) if args is None: args = argv[1:] parser = argparse.ArgumentParser(description="Execute celery command") parser.add_argument( '--ini', required=True, help='The URI to the pyramid configuration file.', ) parser.add_argument( '--setup', dest='setup', help='A callable that will be passed the environment ' 'before it is made available to the celery.' ) parsed_args, unknown_args = parser.parse_known_args(args) config_uri = parsed_args.ini with bootstrap(config_uri) as env: if parsed_args.setup: # call the setup callable resolver = DottedNameResolver(None) setup = resolver.maybe_resolve(parsed_args.setup) setup(env) return run_celery(env['request'], args=unknown_args)
def base_config(**settings): from pyramid.authorization import ACLAuthorizationPolicy resolver = DottedNameResolver() setup_defaults(settings) authn_policy = resolver.maybe_resolve(settings['arche.authn_factory'])(settings) authz_policy = ACLAuthorizationPolicy() return Configurator(root_factory = root_factory, settings = settings, authentication_policy = authn_policy, authorization_policy = authz_policy,)
def pshell_file_config(self, filename): resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} config = self.ConfigParser() config.read(filename) try: items = config.items('pshell') except ConfigParser.NoSectionError: return for k, v in items: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def pshell_file_config(self, loader, defaults): settings = loader.get_settings('pshell', defaults) resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in settings.items(): if k == 'setup': self.setup = v elif k == 'default_shell': self.preferred_shells = [x.lower() for x in aslist(v)] else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def pshell_file_config(self, loader, defaults): settings = loader.get_settings('pshell', defaults) resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in settings.items(): if k == 'setup': self.setup = v elif k == 'default_shell': self.preferred_shells = [x.lower() for x in aslist(v)] elif k in ('__file__', 'here'): continue else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def addable(self, context, request): resolver = DottedNameResolver() if hasattr(self, 'dotted_class'): resource_class = resolver.maybe_resolve(self.dotted_class) if resource_class: already_exists_box = DBSession.query(resource_class).\ filter(resource_class.parent_id == context.id).first() if already_exists_box is not None: return False else: return False else: return False return super(BoxManagerTypeInfo, self).addable(context, request)
def pshell_file_config(self, filename): config = self.ConfigParser() config.read(filename) try: items = config.items('pshell') except configparser.NoSectionError: return resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in items: if k == 'setup': self.setup = v else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def pshell_file_config(self, filename): config = self.ConfigParser() config.read(filename) try: items = config.items("pshell") except configparser.NoSectionError: return resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in items: if k == "setup": self.setup = v else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def pshell_file_config(self, filename): loader = plaster.get_loader(filename) if 'plshell' not in loader.get_sections(): return items = loader.get_settings('plshell') resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in items: if k == 'setup': self.setup = v elif k == 'default_shell': self.preferred_shells = [x.lower() for x in aslist(v)] else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def addable(self, context, request): resolver = DottedNameResolver() if hasattr(self, 'dotted_class'): resource_class = resolver.maybe_resolve(self.dotted_class) if resource_class: already_exists_action = DBSession.query(resource_class).\ filter(resource_class.parent_id == context.id).first() if already_exists_action is not None: return False else: return False else: return False if INavigationRoot.providedBy(context) and \ view_permitted(context, request, self.add_view): return True else: return False
def proxy_it(request, port): """Proxy HTTP request to upstream IPython Notebook Tornado server.""" # Check if we have websocket proxy configured websocket_proxy = request.registry.settings.get( "pyramid_notebook.websocket_proxy", "") if websocket_proxy.strip(): r = DottedNameResolver() websocket_proxy = r.maybe_resolve(websocket_proxy) if "upgrade" in request.headers.get("connection", "").lower(): if websocket_proxy: return websocket_proxy(request, port) else: # If we run on localhost on pserve, we should never hit here as requests go directly to IPython Notebook kernel, not us raise RuntimeError("Websocket proxy support is not configured.") proxy_app = WSGIProxyApplication(port) return request.get_response(proxy_app)
def pshell_file_config(self, filename): config = self.ConfigParser() config.optionxform = str config.read(filename) try: items = config.items('pshell') except configparser.NoSectionError: return resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} self.setup = None for k, v in items: if k == 'setup': self.setup = v elif k == 'default_shell': self.preferred_shells = [x.lower() for x in aslist(v)] else: self.loaded_objects[k] = resolver.maybe_resolve(v) self.object_help[k] = v
def __call__(self, info): p = re.compile(r"(?P<asset>[\w_.:/]+)" r"(?:\#(?P<defname>[\w_]+))?" r"(\.(?P<ext>.*))") asset, defname, ext = p.match(info.name).group("asset", "defname", "ext") path = "%s.%s" % (asset, ext) registry = info.registry settings = info.settings settings_prefix = self.settings_prefix if settings_prefix is None: settings_prefix = info.type + "." lookup = registry.queryUtility(IMakoLookup, name=settings_prefix) def sget(name, default=None): return settings.get(settings_prefix + name, default) if lookup is None: reload_templates = settings.get("pyramid.reload_templates", None) if reload_templates is None: reload_templates = settings.get("reload_templates", False) reload_templates = asbool(reload_templates) directories = sget("directories", []) module_directory = sget("module_directory", None) input_encoding = sget("input_encoding", "utf-8") error_handler = sget("error_handler", None) default_filters = sget("default_filters", "h") imports = sget("imports", None) strict_undefined = asbool(sget("strict_undefined", False)) preprocessor = sget("preprocessor", None) if not is_nonstr_iter(directories): directories = list(filter(None, directories.splitlines())) directories = [abspath_from_asset_spec(d) for d in directories] if module_directory is not None: module_directory = abspath_from_asset_spec(module_directory) if error_handler is not None: dotted = DottedNameResolver(info.package) error_handler = dotted.maybe_resolve(error_handler) if default_filters is not None: if not is_nonstr_iter(default_filters): default_filters = list(filter(None, default_filters.splitlines())) if imports is not None: if not is_nonstr_iter(imports): imports = list(filter(None, imports.splitlines())) if preprocessor is not None: dotted = DottedNameResolver(info.package) preprocessor = dotted.maybe_resolve(preprocessor) lookup = PkgResourceTemplateLookup( directories=directories, module_directory=module_directory, input_encoding=input_encoding, error_handler=error_handler, default_filters=default_filters, imports=imports, filesystem_checks=reload_templates, strict_undefined=strict_undefined, preprocessor=preprocessor, ) registry_lock.acquire() try: registry.registerUtility(lookup, IMakoLookup, name=settings_prefix) finally: registry_lock.release() return MakoLookupTemplateRenderer(path, defname, lookup)
def run(self, shell=None): if self.args.list: return self.show_shells() if not self.args.config_uri: self.out('Requires a config file argument') return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) self.pshell_file_config(loader, config_vars) env = self.bootstrap(config_uri, options=config_vars) # remove the closer from the env self.closer = env.pop('closer') # setup help text for default environment env_help = dict(env) env_help['app'] = 'The WSGI application.' env_help['root'] = 'Root of the default resource tree.' env_help['registry'] = 'Active Pyramid registry.' env_help['request'] = 'Active request object.' env_help['root_factory'] = ( 'Default root factory used to create `root`.') # override use_script with command-line options if self.args.setup: self.setup = self.args.setup if self.setup: # store the env before muddling it with the script orig_env = env.copy() # call the setup callable resolver = DottedNameResolver(None) setup = resolver.maybe_resolve(self.setup) setup(env) # remove any objects from default help that were overidden for k, v in env.items(): if k not in orig_env or env[k] != orig_env[k]: if getattr(v, '__doc__', False): env_help[k] = v.__doc__.replace("\n", " ") else: env_help[k] = v # load the pshell section of the ini file env.update(self.loaded_objects) # eliminate duplicates from env, allowing custom vars to override for k in self.loaded_objects: if k in env_help: del env_help[k] # generate help text help = '' if env_help: help += 'Environment:' for var in sorted(env_help.keys()): help += '\n %-12s %s' % (var, env_help[var]) if self.object_help: help += '\n\nCustom Variables:' for var in sorted(self.object_help.keys()): help += '\n %-12s %s' % (var, self.object_help[var]) if shell is None: try: shell = self.make_shell() except ValueError as e: self.out(str(e)) self.closer() return 1 if self.pystartup and os.path.isfile(self.pystartup): with open(self.pystartup, 'rb') as fp: exec_(fp.read().decode('utf-8'), env) if '__builtins__' in env: del env['__builtins__'] try: shell(env, help) finally: self.closer()
def command(self, shell=None): config_uri = self.args[0] config_file = config_uri.split('#', 1)[0] self.logging_file_config(config_file) self.pshell_file_config(config_file) # bootstrap the environ env = self.bootstrap[0](config_uri) # remove the closer from the env closer = env.pop('closer') # setup help text for default environment env_help = dict(env) env_help['app'] = 'The WSGI application.' env_help['root'] = 'Root of the default resource tree.' env_help['registry'] = 'Active Pyramid registry.' env_help['request'] = 'Active request object.' env_help['root_factory'] = ( 'Default root factory used to create `root`.') # override use_script with command-line options if self.options.setup: self.setup = self.options.setup if self.setup: # store the env before muddling it with the script orig_env = env.copy() # call the setup callable resolver = DottedNameResolver(None) setup = resolver.maybe_resolve(self.setup) setup(env) # remove any objects from default help that were overidden for k, v in env.iteritems(): if k not in orig_env or env[k] != orig_env[k]: env_help[k] = v # load the pshell section of the ini file env.update(self.loaded_objects) # eliminate duplicates from env, allowing custom vars to override for k in self.loaded_objects: if k in env_help: del env_help[k] # generate help text help = '' if env_help: help += 'Environment:' for var in sorted(env_help.keys()): help += '\n %-12s %s' % (var, env_help[var]) if self.object_help: help += '\n\nCustom Variables:' for var in sorted(self.object_help.keys()): help += '\n %-12s %s' % (var, self.object_help[var]) if shell is None and not self.options.disable_ipython: shell = self.make_ipython_v0_11_shell() if shell is None: shell = self.make_ipython_v0_10_shell() if shell is None: shell = self.make_default_shell() try: shell(env, help) finally: closer()
def run(self, shell=None): if not self.args: self.out('Requires a config file argument') return 2 config_uri = self.args[0] config_file = config_uri.split('#', 1)[0] setup_logging(config_file) self.pshell_file_config(config_file) # bootstrap the environ env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:])) # remove the closer from the env closer = env.pop('closer') # setup help text for default environment env_help = dict(env) env_help['app'] = 'The WSGI application.' env_help['root'] = 'Root of the default resource tree.' env_help['registry'] = 'Active Pyramid registry.' env_help['request'] = 'Active request object.' env_help['root_factory'] = ( 'Default root factory used to create `root`.') # override use_script with command-line options if self.options.setup: self.setup = self.options.setup if self.setup: # store the env before muddling it with the script orig_env = env.copy() # call the setup callable resolver = DottedNameResolver(None) setup = resolver.maybe_resolve(self.setup) setup(env) # remove any objects from default help that were overidden for k, v in env.items(): if k not in orig_env or env[k] != orig_env[k]: env_help[k] = v # load the pshell section of the ini file env.update(self.loaded_objects) # eliminate duplicates from env, allowing custom vars to override for k in self.loaded_objects: if k in env_help: del env_help[k] # generate help text help = '' if env_help: help += 'Environment:' for var in sorted(env_help.keys()): help += '\n %-12s %s' % (var, env_help[var]) if self.object_help: help += '\n\nCustom Variables:' for var in sorted(self.object_help.keys()): help += '\n %-12s %s' % (var, self.object_help[var]) if shell is None: shell = self.make_shell() try: shell(env, help) finally: closer()
bootstrap = (bootstrap, ) config = configparser.ConfigParser() config.read(config_file) resolver = DottedNameResolver(None) loaded_objects = {} object_help = {} setup = None try: items = config.items('pshell') for k, v in items: if k == 'setup': setup = v else: loaded_objects[k] = resolver.maybe_resolve(v) object_help[k] = v except configparser.NoSectionError: pass # use #main section by default config_uri = config_file # bootstrap the environ env = bootstrap[0](config_uri) # remove the closer from the env closer = env.pop('closer') # setup help text for default environment env_help = dict(env)
def __call__(self, info): path = info.name registry = info.registry settings = info.settings settings_prefix = self.settings_prefix if settings_prefix is None: settings_prefix = info.type +'.' lookup = registry.queryUtility(IMakoLookup, name=settings_prefix) def sget(name, default=None): return settings.get(settings_prefix + name, default) if lookup is None: reload_templates = settings.get('pyramid.reload_templates', None) if reload_templates is None: reload_templates = settings.get('reload_templates', False) reload_templates = asbool(reload_templates) directories = sget('directories', []) module_directory = sget('module_directory', None) input_encoding = sget('input_encoding', 'utf-8') error_handler = sget('error_handler', None) default_filters = sget('default_filters', 'h') imports = sget('imports', None) strict_undefined = asbool(sget('strict_undefined', False)) preprocessor = sget('preprocessor', None) if not is_nonstr_iter(directories): directories = list(filter(None, directories.splitlines())) directories = [ abspath_from_asset_spec(d) for d in directories ] if module_directory is not None: module_directory = abspath_from_asset_spec(module_directory) if error_handler is not None: dotted = DottedNameResolver(info.package) error_handler = dotted.maybe_resolve(error_handler) if default_filters is not None: if not is_nonstr_iter(default_filters): default_filters = list(filter( None, default_filters.splitlines())) if imports is not None: if not is_nonstr_iter(imports): imports = list(filter(None, imports.splitlines())) if preprocessor is not None: dotted = DottedNameResolver(info.package) preprocessor = dotted.maybe_resolve(preprocessor) lookup = PkgResourceTemplateLookup( directories=directories, module_directory=module_directory, input_encoding=input_encoding, error_handler=error_handler, default_filters=default_filters, imports=imports, filesystem_checks=reload_templates, strict_undefined=strict_undefined, preprocessor=preprocessor ) registry_lock.acquire() try: registry.registerUtility(lookup, IMakoLookup, name=settings_prefix) finally: registry_lock.release() return MakoLookupTemplateRenderer(path, lookup)
def __call__(self, info): p = re.compile(r'(?P<asset>[\w_.:/-]+)' r'(?:\#(?P<defname>[\w_]+))?' r'(\.(?P<ext>.*))') asset, defname, ext = p.match(info.name).group('asset', 'defname', 'ext') path = '%s.%s' % (asset, ext) registry = info.registry settings = info.settings settings_prefix = self.settings_prefix if settings_prefix is None: settings_prefix = info.type + '.' lookup = registry.queryUtility(IMakoLookup, name=settings_prefix) def sget(name, default=None): return settings.get(settings_prefix + name, default) if lookup is None: reload_templates = settings.get('pyramid.reload_templates', None) if reload_templates is None: reload_templates = settings.get('reload_templates', False) reload_templates = asbool(reload_templates) directories = sget('directories', []) module_directory = sget('module_directory', None) input_encoding = sget('input_encoding', 'utf-8') error_handler = sget('error_handler', None) default_filters = sget('default_filters', 'h') imports = sget('imports', None) strict_undefined = asbool(sget('strict_undefined', False)) preprocessor = sget('preprocessor', None) if not is_nonstr_iter(directories): directories = list(filter(None, directories.splitlines())) directories = [abspath_from_asset_spec(d) for d in directories] if module_directory is not None: module_directory = abspath_from_asset_spec(module_directory) if error_handler is not None: dotted = DottedNameResolver(info.package) error_handler = dotted.maybe_resolve(error_handler) if default_filters is not None: if not is_nonstr_iter(default_filters): default_filters = list( filter(None, default_filters.splitlines())) if imports is not None: if not is_nonstr_iter(imports): imports = list(filter(None, imports.splitlines())) if preprocessor is not None: dotted = DottedNameResolver(info.package) preprocessor = dotted.maybe_resolve(preprocessor) lookup = PkgResourceTemplateLookup( directories=directories, module_directory=module_directory, input_encoding=input_encoding, error_handler=error_handler, default_filters=default_filters, imports=imports, filesystem_checks=reload_templates, strict_undefined=strict_undefined, preprocessor=preprocessor) with registry_lock: registry.registerUtility(lookup, IMakoLookup, name=settings_prefix) return MakoLookupTemplateRenderer(path, defname, lookup)
def __init__(self, *args, **kwargs): res = DottedNameResolver('pyramid_formalchemy.actions') list.__init__(self, [res.maybe_resolve(a) for a in args])
def __init__(self, *args, **kwargs): self.sep = kwargs.get('sep', u'\n') res = DottedNameResolver('pyramid_formalchemy.actions') list.__init__(self, [res.maybe_resolve(a) for a in args])