本文整理汇总了Python中pyramid.settings.asbool函数的典型用法代码示例。如果您正苦于以下问题:Python asbool函数的具体用法?Python asbool怎么用?Python asbool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asbool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: includeme
def includeme(config):
"""Bind to the db engine specifed in ``config.registry.settings``.
Setup::
>>> from mock import Mock
>>> import pyramid_basemodel
>>> _engine_from_config = pyramid_basemodel.engine_from_config
>>> _bind_engine = pyramid_basemodel.bind_engine
>>> pyramid_basemodel.engine_from_config = Mock()
>>> pyramid_basemodel.engine_from_config.return_value = 'engine'
>>> pyramid_basemodel.bind_engine = Mock()
>>> mock_config = Mock()
>>> mock_config.registry.settings = {}
Calls ``bind_engine`` with the configured ``engine``::
>>> includeme(mock_config)
>>> pyramid_basemodel.bind_engine.assert_called_with('engine',
... should_create=True, should_drop=False)
Teardown::
>>> pyramid_basemodel.engine_from_config = _engine_from_config
>>> pyramid_basemodel.bind_engine = _bind_engine
"""
# Bind the engine.
settings = config.registry.settings
engine = engine_from_config(settings, 'sqlalchemy.')
should_create = asbool(settings.get('basemodel.should_create_all', True))
should_drop = asbool(settings.get('basemodel.should_drop_all', False))
bind_engine(engine, should_create=should_create, should_drop=should_drop)
示例2: includeme
def includeme(config):
"""Configure basic REST settings for a Pyramid application.
You should not call this function directly, but use
:py:func:`pyramid.config.Configurator.include` to initialise
the REST toolkit.
.. code-block:: python
:linenos:
config = Configurator()
config.include('rest_toolkit')
"""
settings = config.registry.settings
settings['rest_toolkit.debug'] = \
settings.get('debug_all') or \
settings.get('pyramid.debug_all') or \
settings.get('rest_toolkit.debug') or \
asbool(os.environ.get('PYRAMID_DEBUG_ALL')) or \
asbool(os.environ.get('REST_TOOLKIT_DEBUG'))
if not settings['rest_toolkit.debug']:
config.add_view('rest_toolkit.error.generic',
context=Exception, renderer='json',
permission=NO_PERMISSION_REQUIRED)
config.add_view('rest_toolkit.error.http_error', context=IExceptionResponse, renderer='json')
config.add_view('rest_toolkit.error.http_error', context=WSGIHTTPException, renderer='json')
config.add_notfound_view('rest_toolkit.error.notfound', renderer='json')
config.add_forbidden_view('rest_toolkit.error.forbidden', renderer='json')
示例3: setup_app
def setup_app(registry, ini_location):
loader = INILoader(celery_app, ini_file=ini_location)
celery_config = loader.read_configuration()
#: TODO: There might be other variables requiring special handling
boolify(celery_config, 'CELERY_ALWAYS_EAGER', 'CELERY_ENABLE_UTC', 'CELERY_RESULT_PERSISTENT')
if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True:
config_path = 'celeryconfig'
celery_app.config_from_object(config_path)
else:
# TODO: Couldn't find a way with celery to do this
hijack_logger = asbool(
celery_config.get('CELERYD_HIJACK_ROOT_LOGGER', False)
)
celery_config['CELERYD_HIJACK_ROOT_LOGGER'] = hijack_logger
if hijack_logger is False:
global ini_file
ini_file = ini_location
signals.setup_logging.connect(configure_logging)
celery_app.config_from_object(celery_config)
celery_app.conf.update({'PYRAMID_REGISTRY': registry})
示例4: includeme
def includeme(config):
"""
RPC loader for Pyramid
"""
global _do_xmlrpc, _do_jsonrpc
cfg = config.registry.settings
_do_xmlrpc = asbool(cfg.get('netprofile.rpc.xmlrpc', True))
_do_jsonrpc = asbool(cfg.get('netprofile.rpc.jsonrpc', True))
if _do_xmlrpc:
config.include('pyramid_rpc.xmlrpc')
config.add_xmlrpc_endpoint('api.xmlrpc', '/api/xmlrpc')
if _do_jsonrpc:
config.include('pyramid_rpc.jsonrpc')
renderer = JSON()
def _json_datetime(obj, req):
if obj.tzinfo is None:
obj = obj.replace(tzinfo=tzlocal())
return obj.isoformat()
renderer.add_adapter(dt.datetime, _json_datetime)
renderer.add_adapter(dt.date, lambda obj, req: obj.isoformat())
renderer.add_adapter(dt.time, lambda obj, req: obj.isoformat())
renderer.add_adapter(ipaddress.IPv4Address, lambda obj, req: int(obj))
renderer.add_adapter(decimal.Decimal, lambda obj, req: str(obj))
config.add_renderer('jsonrpc', renderer)
config.add_jsonrpc_endpoint('api.jsonrpc', '/api/jsonrpc',
default_renderer='jsonrpc')
config.scan()
示例5: get_global_base_url
def get_global_base_url(require_secure=None, override_port=None):
"""Get the base URL of this server
DO NOT USE directly, except for Linked data;
use Discussion.get_base_url()
"""
port = str(override_port or config.get('public_port'))
accept_secure_connection = asbool(
config.get('accept_secure_connection'))
require_secure_connection = accept_secure_connection and (require_secure or asbool(
config.get('require_secure_connection')))
service = 'http'
portString = ''
if accept_secure_connection or require_secure_connection:
if port is None or port == "443":
service += 's'
elif port == "80":
if require_secure_connection:
service += 's' # assume standard port upgrade
else:
if require_secure_connection:
service += 's'
portString = (':'+port)
else:
if port is not None and port != "80":
portString = (':'+port)
return '%s://%s%s' % (
service, config.get('public_hostname'), portString)
示例6: client_activate
def client_activate(request):
if authenticated_userid(request):
return HTTPSeeOther(location=request.route_url('access.cl.home'))
did_fail = True
cur_locale = locale_neg(request)
cfg = request.registry.settings
comb_js = asbool(cfg.get('netprofile.client.combine_js', False))
can_reg = asbool(cfg.get('netprofile.client.registration.enabled', False))
must_verify = asbool(cfg.get('netprofile.client.registration.verify_email', True))
link_id = int(cfg.get('netprofile.client.registration.link_id', 1))
rand_len = int(cfg.get('netprofile.client.registration.code_length', 20))
if (not can_reg) or (not must_verify):
return HTTPSeeOther(location=request.route_url('access.cl.login'))
code = request.GET.get('code', '').strip().upper()
login = request.GET.get('for', '')
if code and login and (len(code) == rand_len):
sess = DBSession()
for link in sess.query(AccessEntityLink)\
.options(joinedload(AccessEntityLink.entity))\
.filter(AccessEntityLink.type_id == link_id, AccessEntityLink.value == code):
# TODO: implement code timeouts
ent = link.entity
if (ent.access_state == AccessState.block_inactive.value) and (ent.nick == login):
ent.access_state = AccessState.ok.value
sess.delete(link)
did_fail = False
break
tpldef = {
'failed' : did_fail,
'comb_js' : comb_js,
'cur_loc' : cur_locale
}
request.run_hook('access.cl.tpldef.activate', tpldef, request)
return tpldef
示例7: __init__
def __init__(self, context, request):
self.context = context
self.request = request
self.version = __version__
self.home_url = request.application_url
self.help_url = request.registry.settings.get('help.url')
self.support_url = request.registry.settings.get('support.url') or "http://support.eucalyptus.com"
self.aws_enabled = asbool(request.registry.settings.get('aws.enabled'))
self.aws_regions = AWS_REGIONS
self.default_region = request.registry.settings.get('aws.default.region')
self.browser_password_save = 'true' if asbool(request.registry.settings.get('browser.password.save')) else 'false'
self.cloud_type = request.session.get('cloud_type')
self.selected_region = self.request.session.get('region', self.default_region)
self.selected_region_label = self.get_selected_region_label(self.selected_region)
self.username = self.request.session.get('username')
self.account = self.request.session.get('account')
self.username_label = self.request.session.get('username_label')
self.euca_logout_form = EucaLogoutForm(request=self.request)
self.date_format = _(u'%I:%M:%S %p %b %d %Y')
self.angular_date_format = _(u'hh:mm:ss a MMM d yyyy')
self.tag_pattern_key = '^(?!aws:).{0,128}$'
self.tag_pattern_value = '^(?!aws:).{0,256}$'
self.integer_gt_zero_pattern = '^[1-9]\d*$'
self.non_negative_pattern = '^[0-9]\d*$'
self.cidr_pattern = '{0}{1}'.format(
'^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}',
'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\/\d+)$'
)
self.querystring = self.get_query_string()
self.help_html_dir = 'eucaconsole:static/html/help/'
示例8: authenticate_user
def authenticate_user(self, user: IUser, login_source:str, location: str=None):
"""Make the current session logged in session for this particular user."""
request = self.request
settings = request.registry.settings
require_activation = asbool(settings.get('horus.require_activation', True))
allow_inactive_login = asbool(settings.get('horus.allow_inactive_login', False))
if (not allow_inactive_login) and require_activation and (not user.is_activated()):
raise AuthenticationFailure('Your account is not active, please check your e-mail. If your account activation email as expired please request a password reset.')
if not user.can_login():
raise AuthenticationFailure('This user account cannot log in at the moment.')
user_registry = get_user_registry(request)
token = user_registry.get_session_token(user)
headers = remember(request, token)
# assert headers, "Authentication backend did not give us any session headers"
if not location:
location = get_config_route(request, 'horus.login_redirect')
self.greet_user(user)
self.update_login_data(user)
e = events.Login(request, user)
request.registry.notify(e)
return HTTPFound(location=location, headers=headers)
示例9: rewrite
def rewrite(self, session=None, skip_rollback=True, deferred=True,
start=False):
self.check_initialized()
session = session or Session.object_session(self)
if not session:
raise DetachedInstanceError()
self.log.info("Rewriting configuration for %s", self)
if asbool(self.settings.get('supervisor.enabled')):
pfx = self.settings.get('supervisor.command.prefix', 'aybu')
session.activity_log.add(render, 'supervisor.conf.mako',
self.paths.configs.supervisor_conf,
env=self, uwsgi=self.uwsgi_config,
program_prefix=pfx,
skip_rollback=skip_rollback,
deferred=deferred)
self.update_supervisor_conf(session)
elif asbool(self.settings.get('upstart.enabled')):
self.log.info("rendering %s", self.paths.configs.upstart_conf)
session.activity_log.add(render, 'upstart.conf.mako',
self.paths.configs.upstart_conf,
env=self, uwsgi=self.uwsgi_config,
skip_rollback=skip_rollback,
deferred=deferred)
action = "start" if start else "restart"
self.update_upstart(session, action)
示例10: set_config_types
def set_config_types(config):
"""
convert raw config values to proper types
:param config:
:return:
"""
config = copy.deepcopy(config)
config["debug"] = asbool(config["debug"])
config["port"] = int(config["port"])
config["validate_requests"] = asbool(config["validate_requests"])
config["enforce_https"] = asbool(config["enforce_https"])
if not config["cookie_secret"]:
config["cookie_secret"] = str(uuid.uuid4())
if config["http_scheme"] not in ["http", "https"]:
config["http_scheme"] = ""
for key in ["allow_posting_from", "allow_cors"]:
if not config[key]:
continue
# if those keys are strings from ini convert to lists of individual values
if isinstance(config[key], str):
try:
listed = [ip.strip() for ip in config[key].split(",") if ip.strip()]
config[key] = listed
except ValueError:
pass
return config
示例11: main
def main(global_config, **settings):
settings = dict(global_config, **settings)
settings.setdefault('jinja2.i18n.domain', 'CheesePrism')
session_factory = UnencryptedCookieSessionFactoryConfig('cheeseprism')
config = Configurator(root_factory=App, settings=settings,
session_factory=session_factory,
authentication_policy=\
BasicAuthenticationPolicy(BasicAuthenticationPolicy.noop_check))
setup_workers(config.registry)
config.add_translation_dirs('locale/')
config.include('.request')
config.include('.views')
config.include('.index')
tempspec = settings.get('cheeseprism.index_templates', '')
config.registry['cp.index_templates'] = EnvFactory.from_str(tempspec)
if asbool(settings.get('cheeseprism.pipcache_mirror', False)):
config.include('.sync.pip')
if asbool(settings.get('cheeseprism.auto_sync', False)):
config.include('.sync.auto')
tempfile_limit = int(settings.get('cheeseprism.temp_file_limit', 10*1024))
config.add_request_method(lambda req: tempfile_limit,
name='request_body_tempfile_limit', reify=True)
config.add_request_method(lambda req: asbool(settings.get('cheeseprism.disable.regenerate', False)),
name='disable_regen', reify=True)
return config.make_wsgi_app()
示例12: __init__
def __init__(self, registry):
self.es = registry[ELASTIC_SEARCH]
self.esstorage = registry[STORAGE]
self.index = registry.settings['snovault.elasticsearch.index']
self.queue_server = None
self.queue_worker = None
self.worker_runs = []
available_queues = registry['available_queues']
queue_type = registry.settings.get('queue_type', None)
is_queue_server = asbool(registry.settings.get('queue_server'))
is_queue_worker = asbool(registry.settings.get('queue_worker'))
queue_worker_processes = int(
registry.settings.get('queue_worker_processes', 1)
)
queue_worker_chunk_size = int(
registry.settings.get('queue_worker_chunk_size', 1024)
)
queue_worker_batch_size = int(
registry.settings.get('queue_worker_batch_size', 1024)
)
queue_options = {
'processes': queue_worker_processes,
'chunk_size': queue_worker_chunk_size,
'batch_size': queue_worker_batch_size,
}
if is_queue_server and queue_type in available_queues:
if not queue_type or queue_type == 'Simple':
self.queue_server = SimpleUuidServer(queue_options)
else:
log.error('No queue available for Indexer')
if self.queue_server and is_queue_worker:
self.queue_worker = self.queue_server.get_worker()
示例13: configure
def configure(cls, settings):
kwargs = super(LDAPAccessBackend, cls).configure(settings)
conn = LDAP(
admin_field=settings.get("auth.ldap.admin_field"),
admin_group_dn=settings.get("auth.ldap.admin_group_dn"),
admin_value=aslist(
settings.get("auth.ldap.admin_value", []), flatten=False
),
base_dn=settings.get("auth.ldap.base_dn"),
cache_time=settings.get("auth.ldap.cache_time"),
service_dn=settings.get("auth.ldap.service_dn"),
service_password=settings.get("auth.ldap.service_password", ""),
service_username=settings.get("auth.ldap.service_username"),
url=settings["auth.ldap.url"],
user_dn_format=settings.get("auth.ldap.user_dn_format"),
user_search_filter=settings.get("auth.ldap.user_search_filter"),
ignore_cert=asbool(settings.get("auth.ldap.ignore_cert")),
ignore_referrals=asbool(settings.get("auth.ldap.ignore_referrals", False)),
ignore_multiple_results=asbool(
settings.get("auth.ldap.ignore_multiple_results", False)
),
)
conn.connect()
kwargs["conn"] = conn
fallback = settings.get("auth.ldap.fallback")
if fallback == "config":
kw = ConfigAccessBackend.configure(settings)
kwargs["fallback_factory"] = lambda r: ConfigAccessBackend(r, **kw)
return kwargs
示例14: __init__
def __init__(self, request):
super(AuthController, self).__init__(request)
schema = request.registry.getUtility(ILoginSchema)
self.schema = schema().bind(request=self.request)
form = request.registry.getUtility(ILoginForm)
self.login_redirect_view = get_config_route(
request,
'horus.login_redirect'
)
self.logout_redirect_view = get_config_route(
request,
'horus.logout_redirect'
)
self.require_activation = asbool(
self.settings.get('horus.require_activation', True)
)
self.allow_inactive_login = asbool(
self.settings.get('horus.allow_inactive_login', False)
)
# XXX: Bootstrap classes leak into Deform here
login_button = deform.Button(name="login_email", title="Login with email", css_class="btn-lg btn-block")
self.form = form(self.schema, buttons=(login_button,))
# If the form is embedded on other pages force it go to right HTTP POST endpoint
self.form.action = request.route_url("login")
示例15: load
def load(self, settings, prefix):
d = {key[len(prefix):]: value
for key, value in settings.items()
if key.startswith(prefix)}
self.sitename = d.get('sitename', 'PizzaVolus')
footer_file = d.get('footer_file')
if footer_file:
with open(footer_file) as f:
self.footer_text = f.read()
else:
self.footer_text = d.get('footer_text')
self.log_user_auth = asbool(d.get('log_user_auth', True))
self.log_address_auth = asbool(d.get('log_address_auth', False))
self.user_log_limit = int(d.get('user_log_limit', 10))
self.address_log_limit = int(d.get('address_log_limit', 5))
default_recaptcha_api = 'https://www.google.com/recaptcha/api/siteverify'
self.recaptcha_site = d.get('recaptcha_site')
self.recaptcha_secret = d.get('recaptcha_secret')
self.recaptcha_api = d.get('recaptcha_api', default_recaptcha_api)
self.use_recaptcha = self.recaptcha_secret and self.recaptcha_site
# Required level to see logs.
# "address" < "user" < other values (disable log access)
self.address_log_access = d.get('address_log_access', 'user')
self.user_log_access = d.get('user_log_access', 'user')
# Default local name regexp
self.lname_pattern = d.get('lname_pattern', '^[a-zA-Z0-9_.-]{3,64}$')