本文整理汇总了Python中ptah.config.get_cfg_storage函数的典型用法代码示例。如果您正苦于以下问题:Python get_cfg_storage函数的具体用法?Python get_cfg_storage怎么用?Python get_cfg_storage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_cfg_storage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(self):
data = []
fields = config.get_cfg_storage(FIELD_ID)
previews = config.get_cfg_storage(PREVIEW_ID)
for name, cls in fields.items():
data.append({'name': name,
'doc': cls.__doc__,
'preview': previews.get(cls)})
data.sort()
self.fields = data
示例2: run
def run(self):
# print defaults
if self.options.printcfg:
data = config.get_cfg_storage(SETTINGS_OB_ID).export(True)
parser = configparser.ConfigParser(dict_type=OrderedDict)
for key, val in sorted(data.items()):
parser.set(configparser.DEFAULTSECT,
key, val.replace('%', '%%'))
fp = NativeIO()
try:
parser.write(fp)
finally:
pass
print (fp.getvalue())
return
if self.options.all:
section = ''
else:
section = self.options.section
# print description
groups = sorted(config.get_cfg_storage(ID_SETTINGS_GROUP).items(),
key = lambda item: item[1].__title__)
for name, group in groups:
if section and name != section:
continue
print ('')
title = group.__title__ or name
print (grpTitleWrap.fill('{0} ({1})'.format(title, name)))
if group.__description__:
print (grpDescriptionWrap.fill(
group.__description__))
print ('')
for node in group.__fields__.values():
default = '<required>' if node.required else node.default
print (nameWrap.fill(
('%s.%s: %s (%s: %s)' % (
name, node.name, node.title,
node.__class__.__name__, default))))
print (nameTitleWrap.fill(node.description))
print ('')
示例3: test_rest_registerService_apidoc
def test_rest_registerService_apidoc(self):
from ptahcms import restsrv
restsrv.RestService('test', 'Test service')
self.init_ptah()
srv = config.get_cfg_storage(restsrv.ID_REST)['test']
@srv.action('action', 'Action')
def raction(request, *args):
""" doc string """
self.assertIn('apidoc', srv.actions)
info = srv(self.make_request(), 'apidoc')
self.assertEqual(info['name'], 'test')
self.assertEqual(info['title'], 'Test service')
self.assertEqual(len(info['actions']), 2)
self.assertEqual(info['actions'][0]['name'], 'apidoc')
self.assertEqual(
info['actions'][0]['__link__'], 'http://example.com/apidoc')
self.assertEqual(info['actions'][1]['name'], 'action')
self.assertEqual(
info['actions'][1]['__link__'], 'http://example.com/action')
示例4: __init__
def __init__(self, name, title, description='',
prefix='role:', system=False):
id = '%s%s' % (prefix, name)
self.id = id
self.name = name
self.title = title
self.description = description
self.system = system
self.allowed = set()
self.denied = set()
# conflict detection and introspection
info = config.DirectiveInfo()
discr = (ID_ROLE, name)
intr = config.Introspectable(ID_ROLE, discr, title, ID_ROLE)
intr['role'] = self
intr['codeinfo'] = info.codeinfo
info.attach(
config.Action(
lambda config, r: \
config.get_cfg_storage(ID_ROLE).update({r.name: r}),
(self, ), discriminator=discr, introspectables=(intr,))
)
示例5: list_types
def list_types(self, container):
if container.__type__ is not self or \
not isinstance(container, BaseContainer):
return ()
types = []
all_types = config.get_cfg_storage(TYPES_DIR_ID)
if self.filter_content_types:
allowed_types = self.allowed_content_types
if callable(allowed_types):
allowed_types = allowed_types(container)
for tinfo in allowed_types:
if isinstance(tinfo, string_types):
tinfo = all_types.get('cms-type:%s'%tinfo)
if tinfo and tinfo.is_allowed(container):
types.append(tinfo)
else:
for tinfo in all_types.values():
if tinfo.global_allow and tinfo.is_allowed(container):
types.append(tinfo)
return types
示例6: register_settings
def register_settings(name, *fields, **kw):
""" register settings group """
iname = name
for ch in ('.', '-'):
iname = iname.replace(ch, '_')
category = InterfaceClass(
'SettingsGroup:%s' % iname.upper(), (),
__doc__='Settings group: %s' % name,
__module__='ptah.config.settings')
for field in fields:
field.required = False
if field.default is form.null:
raise StopException(
'Default value is required for "{0}.{1}"'.format(name,field.name))
group = Group(name=name, *fields, **kw)
interface.directlyProvides(Group, category)
info = config.DirectiveInfo()
discr = (ID_SETTINGS_GROUP, name)
intr = config.Introspectable(
ID_SETTINGS_GROUP, discr, group.__title__, ID_SETTINGS_GROUP)
intr['name'] = name
intr['group'] = group
intr['codeinfo'] = info.codeinfo
info.attach(
config.Action(
lambda config, group: config.get_cfg_storage(ID_SETTINGS_GROUP)\
.update({group.__name__: group.clone(config.registry)}),
(group,), discriminator=discr, introspectables=(intr,))
)
示例7: getInfo
def getInfo(self, action):
factory, ifaces = action.args[1:]
factoryInfo = '%s.%s'%(action.info.module.__name__, factory.__name__)
if len(action.args[2]) > 1:
obj = action.args[2][0]
klass = action.args[2][-1]
event = config.get_cfg_storage(directives.EVENT_ID).get(
action.args[2][-1], None)
else:
obj = None
klass = action.args[2][0]
event = config.get_cfg_storage(directives.EVENT_ID).get(
action.args[2][0], None)
return locals()
示例8: update
def update(self):
ev = self.request.params.get('ev')
all_events = config.get_cfg_storage(directives.EVENT_ID)
self.event = event = all_events.get(ev)
if event is None:
events = []
for n, ev in all_events.items():
if isinstance(n, basestring):
events.append((ev.title, ev))
events.sort()
self.events = [ev for _t, ev in events]
else:
pkgs = list_packages()
evinst = event.instance
seen = set()
actions = []
for pkg in pkgs:
for action in directives.scan(pkg, seen, exclude):
if action.discriminator[0] == 'ptah.config:subscriber':
required = action.args[2]
if len(required) == 2 and required[1] == evinst:
actions.append(action)
elif required[0] == evinst:
actions.append(action)
self.actions = actions
示例9: authenticate
def authenticate(self, credentials):
providers = config.get_cfg_storage(AUTH_PROVIDER_ID)
for pname, provider in providers.items():
principal = provider.authenticate(credentials)
if principal is not None:
info = AuthInfo(principal)
for checker in \
config.get_cfg_storage(AUTH_CHECKER_ID).values():
if not checker(info):
return info
info.status = True
return info
return AuthInfo(None)
示例10: pyramid_auth_provider
def pyramid_auth_provider(config, name, provider):
""" pyramid configurator directive for
authentication provider registration::
class AuthProvider(object):
...
config = Configurator()
config.include('ptah')
config.ptah_auth_provider('my-provider', AuthProvider())
"""
info = ptah.config.DirectiveInfo()
discr = (AUTH_PROVIDER_ID, name)
intr = ptah.config.Introspectable(
AUTH_PROVIDER_ID, discr, name, AUTH_PROVIDER_ID)
intr['id'] = name
intr['name'] = '{0}.{1}'.format(
info.codeinfo.module, provider.__class__.__name__)
intr['provider'] = provider
intr['codeinfo'] = info.codeinfo
config.action(
discr,
lambda config, n, p: \
config.get_cfg_storage(AUTH_PROVIDER_ID).update({n: p}),
(config, name, provider), introspectables=(intr,))
示例11: render_includes
def render_includes(request):
_libraries = config.get_cfg_storage(LIBRARY_ID)
seen = set()
libraries = []
libs = getattr(request, '__includes', None)
if libs is None:
return u''
def _process(l_id):
lib = _libraries.get(l_id)
if lib is None:
seen.add(l_id)
return
for require in lib.require:
if require not in seen:
_process(require)
seen.add(l_id)
libraries.append(lib)
for id in libs:
if id not in seen:
_process(id)
return u'\n'.join(lib.render(request) for lib in libraries)
示例12: auth_checker
def auth_checker(checker, __cfg=None, __depth=1):
"""Register authentication checker. Checker function accepts
:py:class:`ptah.authentication.AuthInfo` object.
:param checker: Checker function.
Checker function interface :py:func:`ptah.interfaces.auth_checker`
.. code-block:: python
@ptah.auth_checker
def my_checker(info):
...
"""
info = config.DirectiveInfo(__depth)
discr = (AUTH_CHECKER_ID, hash(checker))
intr = config.Introspectable(
AUTH_CHECKER_ID, discr, checker.__name__, AUTH_CHECKER_ID)
intr['name'] = '{0}.{1}'.format(info.codeinfo.module, checker.__name__)
intr['callable'] = checker
intr['codeinfo'] = info.codeinfo
info.attach(
config.Action(
lambda config, checker: config.get_cfg_storage(AUTH_CHECKER_ID)\
.update({id(checker): checker}),
(checker,), discriminator=discr, introspectables=(intr,)),
__cfg)
return checker
示例13: render_includes
def render_includes(request):
"""
Renders HTML for all included libraries for this request.
:param request: Pyramid request
"""
_libraries = config.get_cfg_storage(LIBRARY_ID)
seen = set()
libraries = []
libs = getattr(request, '__includes', None)
if libs is None:
return ''
def _process(l_id):
lib = _libraries.get(l_id)
if lib is None:
seen.add(l_id)
return
for require in lib.require:
if require not in seen:
_process(require)
seen.add(l_id)
libraries.append(lib)
for id in libs:
if id not in seen:
_process(id)
return '\n'.join(lib.render(request) for lib in libraries)
示例14: register_type_impl
def register_type_impl(
config, cls, tinfo, name, fieldset=None, fieldNames=None, **kw):
# generate schema
fieldset = kw.get('fieldset')
if fieldset is None:
kw['fieldset'] = ptah.generate_fieldset(
cls, fieldNames=fieldNames, namesFilter=names_filter)
log.info("Generating fieldset for %s content type.", cls)
if 'global_allow' not in kw and not issubclass(cls, Content):
kw['global_allow'] = False
tinfo.__dict__.update(kw)
tinfo.cls = cls
config.get_cfg_storage(TYPES_DIR_ID)[tinfo.__uri__] = tinfo
# sql query for content resolver
cls.__uri_sql_get__ = ptah.QueryFreezer(
lambda: ptah.get_session().query(cls) \
.filter(cls.__uri__ == sqla.sql.bindparam('uri')))
# build cms actions
build_class_actions(cls)
示例15: test_rest_registerService_apidoc
def test_rest_registerService_apidoc(self):
import ptah.rest
ptah.rest.RestService('test', 'Test service')
self._init_ptah()
srv = config.get_cfg_storage(ptah.rest.REST_ID)['test']
@srv.action('action', 'Action')
def raction(request, *args):
""" doc string """
self.assertIn('apidoc', srv.actions)
info = srv(self._makeRequest(), 'apidoc')
self.assertEqual(info['name'], 'test')
self.assertEqual(info['title'], 'Test service')
self.assertEqual(len(info['actions']), 2)
self.assertEqual(info['actions'][0]['name'], 'apidoc')
self.assertEqual(
info['actions'][0]['__link__'], 'http://localhost:8080/apidoc')
self.assertEqual(info['actions'][1]['name'], 'action')
self.assertEqual(
info['actions'][1]['__link__'], 'http://localhost:8080/action')