当前位置: 首页>>代码示例>>Python>>正文


Python path.caller_package函数代码示例

本文整理汇总了Python中pyramid.path.caller_package函数的典型用法代码示例。如果您正苦于以下问题:Python caller_package函数的具体用法?Python caller_package怎么用?Python caller_package使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了caller_package函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, config):
        settings = dict((name[6:], value) for name, value in
                        config.registry.settings.items()
                        if name.startswith('breve.'))
        self.tags = config.maybe_dotted(settings.get('tags', html.tags))
        self.doctype = settings.get('doctype', html.doctype)
        if self.doctype and not self.doctype.startswith('<!DOCTYPE '):
            self.doctype = '<!DOCTYPE %s>' % self.doctype
        self.xmlns = settings.get('xmlns', html.xmlns)
        self.fragment = asbool(settings.get('fragment', False))

        if 'monitor' in settings:
            monitor = config.maybe_dotted(settings['monitor'])
            assert IFileMonitor in providedBy(monitor)
        else:
            interval = int(settings.get('monitor_interval', 5))
            monitor = IntervalMonitor(interval)

        default_package = settings.get('default_package')
        if default_package is None:
            # Configurator.include('pyramid_breve') has different
            # "depth" than when it's configured via INI-file
            default_package = caller_package(4)
            if default_package.__name__ == 'pyramid.config':
                default_package = caller_package(6)

        self.loader = TemplateLoader(default_package, monitor)
开发者ID:momyc,项目名称:pyramid-breve,代码行数:27,代码来源:renderer.py

示例2: login

    def login(self):
        args = self.params()
        result = {}
        headers = {}
        registry = self.request.registry
        if args.get('external_login', False):
            data = {'external_login': args.pop('external_login')}
            data['preferredUsername'] = args.pop('user_name')
            data['profile'] = {'accounts': [args]}
            login_result = create_user(None, None, data)
            user = login_result.get('user', None)
            if not user:
                result = {'loggedin': False}
            else:
                headers = remember(self.request, get_oid(user))
                registry.notify(LoggedIn(
                    data['preferredUsername'], user,
                    self.context, self.request))
                result = {'loggedin': True}
        else:
            user, valid, headers = validate_user(
                self.context, self.request, args)
            result = {'loggedin': valid}

        renderer = RendererHelper(name='json', package=caller_package(),
                                  registry=registry)
        response = renderer.render_view(self.request, result, self,
                                        self.context)
        response.headerlist.extend(headers)
        return response
开发者ID:ecreall,项目名称:lagendacommun,代码行数:30,代码来源:__init__.py

示例3: __init__

 def __init__(self,
              registry=None,
              package=None,
              settings=None,
              root_factory=None,
              authentication_policy=None,
              authorization_policy=None,
              renderers=DEFAULT_RENDERERS,
              debug_logger=None,
              locale_negotiator=None,
              request_factory=None,
              renderer_globals_factory=None,
              default_permission=None,
              session_factory=None,
              autocommit=True,
              ):
     if package is None:
         package = caller_package()
     BaseConfigurator.__init__(
         self,
         registry=registry,
         package=package,
         settings=settings,
         root_factory=root_factory,
         authentication_policy=authentication_policy,
         authorization_policy=authorization_policy,
         renderers=renderers,
         debug_logger=debug_logger,
         locale_negotiator=locale_negotiator,
         request_factory=request_factory,
         renderer_globals_factory=renderer_globals_factory,
         default_permission=default_permission,
         session_factory=session_factory,
         autocommit=autocommit,
         )
开发者ID:SMFOSS,项目名称:pyramid,代码行数:35,代码来源:configuration.py

示例4: path

def path(spec, package_name=None):
    if os.path.exists(spec):
        return spec, caller_package(3).__name__

    try:
        package_name, filename = spec.split(':', 1)
    except ValueError:
        # somehow we were passed a relative pathname
        if package_name is None:
            package_name = caller_package(2).__name__
        filename = spec

    abspath = pkg_resources.resource_filename(package_name, filename)
    if not pkg_resources.resource_exists(package_name, filename):
        return None, package_name
    return abspath, package_name
开发者ID:blaflamme,项目名称:ptah,代码行数:16,代码来源:tmpl.py

示例5: render

def render(renderer_name, value, request=None, package=None):
    """ Using the renderer ``renderer_name`` (a template
    or a static renderer), render the value (or set of values) present
    in ``value``. Return the result of the renderer's ``__call__``
    method (usually a string or Unicode).

    If the ``renderer_name`` refers to a file on disk, such as when the
    renderer is a template, it's usually best to supply the name as an
    :term:`asset specification`
    (e.g. ``packagename:path/to/template.pt``).

    You may supply a relative asset spec as ``renderer_name``.  If
    the ``package`` argument is supplied, a relative renderer path
    will be converted to an absolute asset specification by
    combining the package ``package`` with the relative
    asset specification ``renderer_name``.  If ``package``
    is ``None`` (the default), the package name of the *caller* of
    this function will be used as the package.

    The ``value`` provided will be supplied as the input to the
    renderer.  Usually, for template renderings, this should be a
    dictionary.  For other renderers, this will need to be whatever
    sort of value the renderer expects.

    The 'system' values supplied to the renderer will include a basic set of
    top-level system names, such as ``request``, ``context``,
    ``renderer_name``, and ``view``.  See :ref:`renderer_system_values` for
    the full list.  If :term:`renderer globals` have been specified, these
    will also be used to augment the value.

    Supply a ``request`` parameter in order to provide the renderer
    with the most correct 'system' values (``request`` and ``context``
    in particular).

    """
    try:
        registry = request.registry
    except AttributeError:
        registry = None
    if package is None:
        package = caller_package()
    helper = RendererHelper(name=renderer_name, package=package,
                            registry=registry)

    saved_response = None
    # save the current response, preventing the renderer from affecting it
    attrs = request.__dict__ if request is not None else {}
    if 'response' in attrs:
        saved_response = attrs['response']
        del attrs['response']

    result = helper.render(value, None, request=request)

    # restore the original response, overwriting any changes
    if saved_response is not None:
        attrs['response'] = saved_response
    elif 'response' in attrs:
        del attrs['response']

    return result
开发者ID:Adniel,项目名称:pyramid,代码行数:60,代码来源:renderers.py

示例6: cleanUp

def cleanUp(*arg, **kw):
    """ An alias for :func:`pyramid.testing.setUp`. """
    package = kw.get('package', None)
    if package is None:
        package = caller_package()
        kw['package'] = package
    return setUp(*arg, **kw)
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:7,代码来源:testing.py

示例7: __init__

    def __init__(self, settings=None, appname=None, global_config=None, **base_kwargs):
        package = base_kwargs.get('package') or caller_package()
        base_kwargs['package'] = package
        super(configurator, self).__init__(settings=settings, **base_kwargs)
        if 'root_factory' in base_kwargs:
            self.root_factory_set = True
        if settings:
            settings = dict(settings)
            self._settings = settings.copy()
            base_kwargs['settings'] = settings

            self.app_factory = self.rf_kw in settings \
                               and self.open_resolve(settings[self.rf_kw]) 

            self.request_factory = self.req_kw in settings \
                                   and self.open_resolve(settings[self.req_kw]) 

            self.plugin_spec = settings.get(self.stack_key, None)
        
        if appname:
            self.appname = appname

        if global_config:
            self.config_file = global_config['__file__']
            self.exec_dir = global_config['here']        
开发者ID:SMFOSS,项目名称:Prism,代码行数:25,代码来源:config.py

示例8: __init__

    def __init__(self, manifest_spec, reload=False):
        package_name = caller_package().__name__
        self.manifest_path = abspath_from_asset_spec(manifest_spec, package_name)
        self.reload = reload

        self._mtime = None
        if not reload:
            self._manifest = self.get_manifest()
开发者ID:canni,项目名称:pyramid,代码行数:8,代码来源:static.py

示例9: __init__

 def __init__(self, template_name=None):
     pkg = caller_package(level=3)
     if template_name:
         _, template_name = resolve_asset_spec(
             template_name, pkg.__name__)
         template_name = '%s:%s' % (_, template_name)
     self.template_name = template_name
     self.exposed = True
开发者ID:Pylons,项目名称:pyramid_metatg,代码行数:8,代码来源:__init__.py

示例10: static_path

def static_path(request, path, **kw):
    if not os.path.isabs(path):
        if not ':' in path:
            package = caller_package()
            path = '%s:%s' % (package.__name__, path)
    kw['_app_url'] = ''
    path = request.static_url(path, **kw)
    return os.path.relpath(path, os.path.dirname(request.path))
开发者ID:fschulze,项目名称:stasis,代码行数:8,代码来源:core.py

示例11: config_celery

def config_celery(settings, package=None):
    if package is None:
        package = caller_package()
    touch_all_package(package)
    obj_config = config_celery_for_mongo(settings)
    global celery
    celery = _Celery()
    celery.config_from_object(obj_config)
开发者ID:xflash96,项目名称:pyramid_celery,代码行数:8,代码来源:__init__.py

示例12: __new__

 def __new__(cls, namespace, base, *args, **kw):
     # Dotted name support makes it easy to configure with pyramid_multiauth
     name_resolver = DottedNameResolver(caller_package())
     base = name_resolver.maybe_resolve(base)
     # Dynamically create a subclass
     name = 'Namespaced_%s_%s' % (namespace, base.__name__)
     klass = type(name, (cls, base), {'_namespace_prefix': namespace + '.'})
     return super(NamespacedAuthenticationPolicy, klass).__new__(klass)
开发者ID:ClinGen,项目名称:clincoded,代码行数:8,代码来源:authentication.py

示例13: static_url

def static_url(path, request, **kw):
    """
    Generates a fully qualified URL for a static :term:`asset`.
    The asset must live within a location defined via the
    :meth:`pyramid.config.Configurator.add_static_view`
    :term:`configuration declaration` or the ``<static>`` ZCML
    directive (see :ref:`static_assets_section`).

    .. note:: Calling :meth:`pyramid.Request.static_url` can be used to
              achieve the same result as :func:`pyramid.url.static_url`.

    Example::

        static_url('mypackage:static/foo.css', request) =>

                                http://example.com/static/foo.css


    The ``path`` argument points at a file or directory on disk which
    a URL should be generated for.  The ``path`` may be either a
    relative path (e.g. ``static/foo.css``) or a :term:`asset
    specification` (e.g. ``mypackage:static/foo.css``).  A ``path``
    may not be an absolute filesystem path (a :exc:`ValueError` will
    be raised if this function is supplied with an absolute path).

    The ``request`` argument should be a :term:`request` object.

    The purpose of the ``**kw`` argument is the same as the purpose of
    the :func:`pyramid.url.route_url` ``**kw`` argument.  See the
    documentation for that function to understand the arguments which
    you can provide to it.  However, typically, you don't need to pass
    anything as ``*kw`` when generating a static asset URL.

    This function raises a :exc:`ValueError` if a static view
    definition cannot be found which matches the path specification.

    """
    if os.path.isabs(path):
        raise ValueError('Absolute paths cannot be used to generate static '
                         'urls (use a package-relative path or an asset '
                         'specification).')
    if not ':' in path:
        # if it's not a package:relative/name and it's not an
        # /absolute/path it's a relative/path; this means its relative
        # to the package in which the caller's module is defined.
        package = caller_package()
        path = '%s:%s' % (package.__name__, path)

    try:
        reg = request.registry
    except AttributeError:
        reg = get_current_registry() # b/c
    
    info = reg.queryUtility(IStaticURLInfo)
    if info is None:
        raise ValueError('No static URL definition matching %s' % path)
        
    return info.generate(path, request, **kw)
开发者ID:csenger,项目名称:pyramid,代码行数:58,代码来源:url.py

示例14: __init__

 def __init__(self, root_dir, cache_max_age=3600, package_name=None):
     if package_name is None:
         package_name = caller_package().__name__
     static_view.__init__(
         self,
         root_dir,
         cache_max_age=cache_max_age,
         package_name=package_name,
         use_subpath=True)
开发者ID:slmf,项目名称:pyramid,代码行数:9,代码来源:view.py

示例15: logout

 def logout(self):
     headers = forget(self.request)
     result = {'loggedout': True}
     registry = self.request.registry
     renderer = RendererHelper(name='json', package=caller_package(),
                               registry=registry)
     response = renderer.render_view(self.request, result, self,
                                     self.context)
     response.headerlist.extend(headers)
     return response
开发者ID:ecreall,项目名称:lagendacommun,代码行数:10,代码来源:__init__.py


注:本文中的pyramid.path.caller_package函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。