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


Python utils.import_string方法代码示例

本文整理汇总了Python中werkzeug.utils.import_string方法的典型用法代码示例。如果您正苦于以下问题:Python utils.import_string方法的具体用法?Python utils.import_string怎么用?Python utils.import_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.utils的用法示例。


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

示例1: dispatch_url

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def dispatch_url(self, url_string):
        url, url_adapter, query_args = self.parse_url(url_string)

        try:
            endpoint, kwargs = url_adapter.match()
        except NotFound:
            raise NotSupported(url_string)
        except RequestRedirect as e:
            new_url = "{0.new_url}?{1}".format(e, url_encode(query_args))
            return self.dispatch_url(new_url)

        try:
            handler = import_string(endpoint)
            request = Request(url=url, args=query_args)
            return handler(request, **kwargs)
        except RequestRedirect as e:
            return self.dispatch_url(e.new_url) 
开发者ID:dongweiming,项目名称:daenerys,代码行数:19,代码来源:app.py

示例2: _config_killmails

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def _config_killmails(app):
    killmail_sources = []
    # For now, use a loop with checks. After removing the depecated config
    # method it can be rewritten as a list comprehension
    for source in app.config['SRP_KILLMAIL_SOURCES']:
        if isinstance(source, six.string_types):
            killmail_sources.append(import_string(source))
        elif isinstance(source, type):
            _deprecated_object_instance('SRP_KILLMAIL_SOURCES', source)
            killmail_sources.append(source)
    app.killmail_sources = killmail_sources


# Work around DBAPI-specific issues with Decimal subclasses.
# Specifically, almost everything besides pysqlite and psycopg2 raise
# exceptions if an instance of a Decimal subclass as opposed to an instance of
# Decimal itself is passed in as a value for a Numeric column. 
开发者ID:paxswill,项目名称:evesrp,代码行数:19,代码来源:__init__.py

示例3: create_app

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def create_app():
    app = Flask(__name__)
    app.config['DEBUG'] = settings.DEBUG
    app.config['SECRET_KEY'] = settings.SECRET_KEY
    app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
    app.config['SENTRY_DSN'] = settings.SENTRY_DSN
    app.config['BABEL_DEFAULT_LOCALE'] = settings.DEFAULT_LOCALE
    app.config['BABEL_DEFAULT_TIMEZONE'] = settings.DEFAULT_TIMEZONE
    app.config['LOGGER_HANDLER_POLICY'] = 'never'
    app.logger.propagate = True

    for extension_qualname in extensions:
        extension = import_string(extension_qualname)
        extension.init_app(app)

    for blueprint_qualname, url_prefix in blueprints:
        blueprint = import_string(blueprint_qualname)
        app.register_blueprint(blueprint, url_prefix=url_prefix)

    return app 
开发者ID:huskar-org,项目名称:huskar,代码行数:22,代码来源:app.py

示例4: __init__

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def __init__(self, plugin_name: str, root_url: str = '/static', prefix: str = '') -> None:
        """
        Let's stub some dumb fields to get this one treated like a regular
        Flask blueprint while collecting static files.

        :param plugin_name: Plugin module name
        :type plugin_name: str
        :param root_url: Root static URL
        :type root_url: str
        """
        static_path = import_string(plugin_name).__path__[0]
        static_path = os.path.join(static_path, 'static')

        self.name = '{}{}'.format(prefix, plugin_name)
        self.static_url_path = '{}/{}/static'.format(root_url, self.name)
        self.static_folder = ''
        self.has_static_folder = os.path.isdir(static_path)

        if self.has_static_folder:
            self.static_folder = static_path 
开发者ID:mrgambal,项目名称:vulyk,代码行数:22,代码来源:storage.py

示例5: parse_config

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def parse_config(obj: str) -> Dict[Any, Any]:
    """
    Parse given config either from a file or from an object. Method borrowed from Flask.

    :param obj: The config to parse.
    :type obj: any
    :return: A dictionary containing the parsed Flask config
    :rtype: dict
    """
    config = {}
    if isinstance(obj, str):
        obj = import_string(obj)
    for key in dir(obj):
        if key.isupper():
            config[key] = getattr(obj, key)
    return config 
开发者ID:CCExtractor,项目名称:sample-platform,代码行数:18,代码来源:config_parser.py

示例6: convert

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def convert(self, value, param, ctx):
        try:
            return self.path_type(value, param, ctx)
        except click.BadParameter:
            value = click.STRING(value, param, ctx).lower()

            if value == 'adhoc':
                try:
                    import OpenSSL
                except ImportError:
                    raise click.BadParameter(
                        'Using ad-hoc certificates requires pyOpenSSL.',
                        ctx, param)

                return value

            obj = import_string(value, silent=True)

            if sys.version_info < (2, 7):
                if obj:
                    return obj
            else:
                if isinstance(obj, ssl.SSLContext):
                    return obj

            raise 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:cli.py

示例7: from_object

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def from_object(self, obj):
        """Updates the values from the given object.  An object can be of one
        of the following two types:

        -   a string: in this case the object with that name will be imported
        -   an actual object reference: that object is used directly

        Objects are usually either modules or classes. :meth:`from_object`
        loads only the uppercase attributes of the module/class. A ``dict``
        object will not work with :meth:`from_object` because the keys of a
        ``dict`` are not attributes of the ``dict`` class.

        Example of module-based configuration::

            app.config.from_object('yourapplication.default_config')
            from yourapplication import default_config
            app.config.from_object(default_config)

        You should not use this function to load the actual configuration but
        rather configuration defaults.  The actual config should be loaded
        with :meth:`from_pyfile` and ideally from a location not within the
        package because the package might be installed system wide.

        See :ref:`config-dev-prod` for an example of class-based configuration
        using :meth:`from_object`.

        :param obj: an import name or object
        """
        if isinstance(obj, string_types):
            obj = import_string(obj)
        for key in dir(obj):
            if key.isupper():
                self[key] = getattr(obj, key) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:config.py

示例8: from_object

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def from_object(self, obj):
        """Updates the values from the given object.  An object can be of one
        of the following two types:

        -   a string: in this case the object with that name will be imported
        -   an actual object reference: that object is used directly

        Objects are usually either modules or classes.

        Just the uppercase variables in that object are stored in the config.
        Example usage::

            app.config.from_object('yourapplication.default_config')
            from yourapplication import default_config
            app.config.from_object(default_config)

        You should not use this function to load the actual configuration but
        rather configuration defaults.  The actual config should be loaded
        with :meth:`from_pyfile` and ideally from a location not within the
        package because the package might be installed system wide.

        :param obj: an import name or object
        """
        if isinstance(obj, string_types):
            obj = import_string(obj)
        for key in dir(obj):
            if key.isupper():
                self[key] = getattr(obj, key) 
开发者ID:jpush,项目名称:jbox,代码行数:30,代码来源:config.py

示例9: main

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def main():
    '''A simple command-line interface for :py:func:`run_simple`.'''

    # in contrast to argparse, this works at least under Python < 2.7
    import optparse
    from werkzeug.utils import import_string

    parser = optparse.OptionParser(
        usage='Usage: %prog [options] app_module:app_object')
    parser.add_option('-b', '--bind', dest='address',
                      help='The hostname:port the app should listen on.')
    parser.add_option('-d', '--debug', dest='use_debugger',
                      action='store_true', default=False,
                      help='Use Werkzeug\'s debugger.')
    parser.add_option('-r', '--reload', dest='use_reloader',
                      action='store_true', default=False,
                      help='Reload Python process if modules change.')
    options, args = parser.parse_args()

    hostname, port = None, None
    if options.address:
        address = options.address.split(':')
        hostname = address[0]
        if len(address) > 1:
            port = address[1]

    if len(args) != 1:
        sys.stdout.write('No application supplied, or too much. See --help\n')
        sys.exit(1)
    app = import_string(args[0])

    run_simple(
        hostname=(hostname or '127.0.0.1'), port=int(port or 5000),
        application=app, use_reloader=options.use_reloader,
        use_debugger=options.use_debugger
    ) 
开发者ID:jpush,项目名称:jbox,代码行数:38,代码来源:serving.py

示例10: xml

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def xml(self):
        """Get an etree if possible."""
        if 'xml' not in self.mimetype:
            raise AttributeError(
                'Not a XML response (Content-Type: %s)'
                % self.mimetype)
        for module in ['xml.etree.ElementTree', 'ElementTree',
                       'elementtree.ElementTree']:
            etree = import_string(module, silent=True)
            if etree is not None:
                return etree.XML(self.body)
        raise RuntimeError('You must have ElementTree installed '
                           'to use TestResponse.xml') 
开发者ID:jpush,项目名称:jbox,代码行数:15,代码来源:testtools.py

示例11: _signal_connect

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def _signal_connect(self, app):
        if app.config["MSEARCH_ENABLE"]:
            signal = app.config["MSEARCH_INDEX_SIGNAL"]
            if isinstance(signal, str):
                self._signal = import_string(signal)
            else:
                self._signal = signal
            models_committed.connect(self.index_signal) 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:10,代码来源:backends.py

示例12: init_app

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def init_app(self, app):
        app.config.setdefault('MSEARCH_BACKEND', 'simple')
        msearch_backend = app.config['MSEARCH_BACKEND']
        if msearch_backend == 'simple':
            backend = import_string(
                "flask_msearch.simple_backend.SimpleSearch")
        elif msearch_backend == 'whoosh':
            backend = import_string(
                "flask_msearch.whoosh_backend.WhooshSearch")
        elif msearch_backend == 'elasticsearch':
            backend = import_string(
                "flask_msearch.elasticsearch_backend.ElasticSearch")
        else:
            raise ValueError('backends {} not exists.'.format(msearch_backend))
        self._backend = backend(app, self.db, self.analyzer) 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:17,代码来源:__init__.py

示例13: mount_site

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def mount_site(self, site):
        if isinstance(site, basestring):
            site = import_string(site)
        site.play_actions(target=self) 
开发者ID:dongweiming,项目名称:daenerys,代码行数:6,代码来源:app.py

示例14: mount_sites

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def mount_sites(self, root):
        for name in find_modules(root, recursive=True):
            mod = import_string(name)
            site = name.split('.')[-1]
            if hasattr(mod, 'site') and site not in self.ignore_sites:
                mod.site.play_actions(target=self) 
开发者ID:dongweiming,项目名称:daenerys,代码行数:8,代码来源:app.py

示例15: render_template

# 需要导入模块: from werkzeug import utils [as 别名]
# 或者: from werkzeug.utils import import_string [as 别名]
def render_template(self, *args, **kwargs):
        try:
            render = import_string(current_app.config.get('SECURITY_RENDER'))
        except Exception:
            render = render_template
        return render(*args, **kwargs) 
开发者ID:opendatateam,项目名称:udata,代码行数:8,代码来源:__init__.py


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