python里import string_Python werkzeug.import_string方法代码示例

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

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

示例1: _set_cache

​点赞 3

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def _set_cache(self, app, config):

import_me = config['CACHE_TYPE']

if '.' not in import_me:

from . import backends

try:

cache_obj = getattr(backends, import_me)

except AttributeError:

raise ImportError("%s is not a valid FlaskCache backend" % (

import_me))

else:

cache_obj = import_string(import_me)

cache_args = config['CACHE_ARGS'][:]

cache_options = {'default_timeout': config['CACHE_DEFAULT_TIMEOUT']}

if config['CACHE_OPTIONS']:

cache_options.update(config['CACHE_OPTIONS'])

if not hasattr(app, 'extensions'):

app.extensions = {}

app.extensions.setdefault('cache', {})

app.extensions['cache'][self] = cache_obj(

app, config, cache_args, cache_options)

开发者ID:sunqb,项目名称:oa_qian,代码行数:27,

示例2: cmd

​点赞 3

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def cmd():

"""

Help to run the command line

:return:

"""

global application

mochapyfile = os.path.join(os.path.join(CWD, "brew.py"))

if os.path.isfile(mochapyfile):

cwd_to_sys_path()

application = import_string("brew")

else:

print("-" * 80)

print("** Missing << 'brew.py' >> @ %s" % CWD)

print("-" * 80)

[cmd(cli.command, click) for cmd in Manager.__subclasses__()]

cli()

开发者ID:mardix,项目名称:Mocha,代码行数:20,

示例3: install_app

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def install_app(self, app):

install_apps = app.config.setdefault('INSTALLED_APPS', [])

for blueprint in install_apps:

kwargs = {}

if isinstance(blueprint, dict):

kwargs = blueprint['kwargs']

blueprint = blueprint['blueprint']

app.register_blueprint(import_string(blueprint), **kwargs)

开发者ID:honmaple,项目名称:flask-maple,代码行数:10,

示例4: process

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def process(self, app):

for middleware_string in self.middleware:

middleware = import_string(middleware_string)

response = middleware()

if hasattr(response, 'preprocess_request'):

before_request = response.preprocess_request

app.before_request(before_request)

if hasattr(response, 'process_response'):

after_request = response.process_response

app.after_request(after_request)

开发者ID:honmaple,项目名称:flask-maple,代码行数:12,

示例5: view

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def view(self):

view = import_string(self.name)

if isinstance(view, (object, )):

assert self.options.get('endpoint') is not None

endpoint = self.options.pop('endpoint')

view = view.as_view(endpoint)

return view

开发者ID:honmaple,项目名称:flask-maple,代码行数:9,

示例6: _single

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def _single(self, app):

blueprint = import_string(self.module + self.blueprint)

app.register_blueprint(blueprint, **self.options)

开发者ID:honmaple,项目名称:flask-maple,代码行数:5,

示例7: _multi

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def _multi(self, app):

blueprints = list(set(self.blueprint))

for name in blueprints:

blueprint = import_string(self.module + name)

app.register_blueprint(blueprint, **self.options)

开发者ID:honmaple,项目名称:flask-maple,代码行数:7,

示例8: process

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def process(self, app, middleware):

for middleware_string in middleware:

middleware = import_string(middleware_string)

response = middleware()

if hasattr(response, 'preprocess_request'):

before_request = response.preprocess_request

app.before_request(before_request)

if hasattr(response, 'process_response'):

after_request = response.process_response

app.after_request(after_request)

开发者ID:honmaple,项目名称:maple-file,代码行数:12,

示例9: from_object

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug 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

after lowercasing. 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, basestring):

obj = import_string(obj)

for key in dir(obj):

if key.isupper():

self[key] = getattr(obj, key)

开发者ID:hhstore,项目名称:annotated-py-flask,代码行数:30,

示例10: setup_installed_apps

​点赞 2

# 需要导入模块: import werkzeug [as 别名]

# 或者: from werkzeug import import_string [as 别名]

def setup_installed_apps(cls):

"""

To import 3rd party applications along with associated properties

It is a list of dict or string.

When a dict, it contains the `app` key and the configuration,

if it's a string, it is just the app name

If you require dependencies from other packages, dependencies

must be placed before the calling package.

It is required that __init__ in the package app has an entry point method

-> 'main(**kw)' which will be used to setup the default app.

As a dict

INSTALLED_APPS = [

"it.can.be.a.string.to.the.module",

("in.a.tuple.with.props.dict", {options}),

[

("multi.app.list.in.a.list.of.tuple", {options}),

("multi.app.list.in.a.list.of.tuple2", {options})

]

]

:return:

"""

cls._installed_apps = cls._app.config.get("INSTALLED_APPS", [])

if cls._installed_apps:

def import_app(module, props={}):

_ = werkzeug.import_string(module)

setattr(_, "__options__", utils.dict_dot(props))

for k in cls._installed_apps:

if isinstance(k, six.string_types): # One string

import_app(k, {})

elif isinstance(k, tuple):

import_app(k[0], k[1])

elif isinstance(k, list): # list of tuple[(module props), ...]

for t in k:

import_app(t[0], t[1])

开发者ID:mardix,项目名称:Mocha,代码行数:44,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值