• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.dictset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

    def __init__(self, context, request, _query_params={}, _json_params={}):
        """ Prepare data to be used across the view and run init methods.

        Each view has these dicts on data:
          :_query_params: Params from a query string
          :_json_params: Request JSON data. Populated only for
              PUT, PATCH, POST methods
          :_params: Join of _query_params and _json_params

        For method tunneling, _json_params contains the same data as
        _query_params.
        """
        self.context = context
        self.request = request
        self._query_params = dictset(_query_params or request.params.mixed())
        self._json_params = dictset(_json_params)

        ctype = request.content_type
        if request.method in ['POST', 'PUT', 'PATCH']:
            if ctype == 'application/json':
                try:
                    self._json_params.update(request.json)
                except simplejson.JSONDecodeError:
                    log.error(
                        "Expecting JSON. Received: '{}'. "
                        "Request: {} {}".format(
                            request.body, request.method, request.url))

            self._json_params = BaseView.convert_dotted(self._json_params)
            self._query_params = BaseView.convert_dotted(self._query_params)

        self._params = self._query_params.copy()
        self._params.update(self._json_params)

        # dict of the callables {'action':[callable1, callable2..]}
        # as name implies, before calls are executed before the action is
        # called after_calls are called after the action returns.
        self._before_calls = defaultdict(list)
        self._after_calls = defaultdict(list)

        # no accept headers, use default
        if '' in request.accept:
            request.override_renderer = self._default_renderer
        elif 'application/json' in request.accept:
            request.override_renderer = 'nefertari_json'
        elif 'text/plain' in request.accept:
            request.override_renderer = 'string'

        self._run_init_actions()
开发者ID:karthikmm,项目名称:nefertari,代码行数:49,代码来源:view.py


示例2: filter_fields

 def filter_fields(cls, params):
     """ Filter out fields with invalid names. """
     fields = cls.fields_to_query()
     return dictset({
         name: val for name, val in params.items()
         if name.split('__')[0] in fields
     })
开发者ID:howaryoo,项目名称:nefertari-mongodb,代码行数:7,代码来源:documents.py


示例3: __init__

    def __init__(self, *arg, **kw):
        kw = dictset(kw)
        self.__class__.__base__.__init__(
            self, *arg,
            **kw.subset(BASE_ATTRS+['headers', 'location']))

        create_json_response(self, **kw)
开发者ID:howaryoo,项目名称:nefertari,代码行数:7,代码来源:json_httpexceptions.py


示例4: __init__

    def __init__(self, *arg, **kw):
        from nefertari.utils import dictset

        kw = dictset(kw)
        self.__class__.__base__.__init__(self, *arg, **kw.subset(BASE_ATTRS + ["headers", "location"]))

        create_json_response(self, **kw)
开发者ID:oleduc,项目名称:nefertari,代码行数:7,代码来源:json_httpexceptions.py


示例5: __init__

 def __init__(self, *args, **kwargs):
     """ Init view and set fake `self.Model` so its __name__ would
     contain names of all requested collections.
     """
     super(PolymorphicESView, self).__init__(*args, **kwargs)
     types = self.determine_types()
     self.Model = dictset({'__name__': ','.join(types)})
开发者ID:mbijon,项目名称:nefertari,代码行数:7,代码来源:polymorphic.py


示例6: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    ES.setup(Settings)

    # Load custom index settings
    index_settings = None
    index_settings_path = None
    if "elasticsearch.index.settings_file" in Settings:
        index_settings_path = Settings["elasticsearch.index.settings_file"]

        if not os.path.exists(index_settings_path):
            raise Exception("Custom index settings file does not exist : '{file_name}'".format(
                file_name=index_settings_path
            ))
    else:
        if os.path.exists("index_settings.json"):
            index_settings_path = "index_settings.json"

    if index_settings_path is not None:
        with open(index_settings_path) as data_file:
            try:
                index_settings = json.load(data_file)
            except:
                raise Exception("Could not parse custom index settings : '{file_name}'".format(
                    file_name=index_settings_path
                ))

    ES.create_index(index_settings=index_settings)
    if ES.settings.asbool('enable_polymorphic_query'):
        config.include('nefertari.polymorphic')
开发者ID:oleduc,项目名称:nefertari,代码行数:30,代码来源:elasticsearch.py


示例7: to_dict

    def to_dict(self, **kwargs):
        _depth = kwargs.get('_depth')
        if _depth is None:
            _depth = self._nesting_depth
        depth_reached = _depth is not None and _depth <= 0

        _data = dictset()
        native_fields = self.__class__.native_fields()
        for field in native_fields:
            value = getattr(self, field, None)

            include = field in self._nested_relationships
            if not include or depth_reached:
                encoder = lambda v: getattr(v, v.pk_field(), None)
            else:
                encoder = lambda v: v.to_dict(_depth=_depth-1)

            if isinstance(value, BaseMixin):
                value = encoder(value)
            elif isinstance(value, InstrumentedList):
                value = [encoder(val) for val in value]
            elif hasattr(value, 'to_dict'):
                value = value.to_dict(_depth=_depth-1)

            _data[field] = value
        _data['_type'] = self._type
        _data['_pk'] = str(getattr(self, self.pk_field()))
        return _data
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:28,代码来源:documents.py


示例8: to_dict

    def to_dict(self, **kwargs):
        _depth = kwargs.get('_depth')
        _negative_items=kwargs.get('negative_items',[])
        if _depth is None:
            _depth = self._nesting_depth
        depth_reached = _depth is not None and _depth <= 0

        _data = dictset()
        for field, field_type in self._fields.items():
            # Ignore ForeignKeyField fields
            if _negative_items:
                if field in _negative_items:
                    continue
            if isinstance(field_type, ForeignKeyField):
                continue
            value = getattr(self, field, None)

            if value is not None:
                include = field in self._nested_relationships
                if not include or depth_reached:
                    encoder = lambda v: getattr(v, v.pk_field(), None)
                else:
                    encoder = lambda v: v.to_dict(_depth=_depth-1)

                if isinstance(field_type, ReferenceField):
                    value = encoder(value)
                elif isinstance(field_type, RelationshipField):
                    value = [encoder(val) for val in value]
                elif hasattr(value, 'to_dict'):
                    value = value.to_dict(_depth=_depth-1)

            _data[field] = value
        _data['_type'] = self._type
        _data['_pk'] = str(getattr(self, self.pk_field()))
        return _data
开发者ID:kalyankuramana,项目名称:nefertari-mongodb,代码行数:35,代码来源:documents.py


示例9: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    ES.setup(Settings)
    ES.create_index()

    if ES.settings.asbool('enable_polymorphic_query'):
        config.include('nefertari.polymorphic')
开发者ID:mbijon,项目名称:nefertari,代码行数:7,代码来源:elasticsearch.py


示例10: view_mapper_wrapper

        def view_mapper_wrapper(context, request):
            matchdict = request.matchdict.copy()
            matchdict.pop('action', None)
            matchdict.pop('traverse', None)

            # instance of BaseView (or child of)
            view_obj = view(context, request)
            action = getattr(view_obj, action_name)
            request.action = action_name

            # Tunneled collection PATCH/PUT doesn't support query params
            tunneled = getattr(request, '_tunneled_get', False)
            if tunneled and action_name in ('update_many',):
                view_obj._query_params = dictset()

            # we should not run "after_calls" here, so lets save them in
            # request as filters they will be ran in the renderer factory
            request.filters = view_obj._after_calls

            try:
                # run before_calls (validators) before running the action
                for call in view_obj._before_calls.get(action_name, []):
                    call(request=request)

            except wrappers.ValidationError as e:
                log.error('validation error: %s', e)
                raise JHTTPBadRequest(e.args)

            except wrappers.ResourceNotFound as e:
                log.error('resource not found: %s', e)
                raise JHTTPNotFound()

            with trigger_events(view_obj):
                view_obj._response = action(**matchdict)
                return view_obj._response
开发者ID:oleduc,项目名称:nefertari,代码行数:35,代码来源:view.py


示例11: includeme

def includeme(config):
    from nefertari.resource import get_root_resource, get_resource_map
    from nefertari.renderers import (
        JsonRendererFactory, NefertariJsonRendererFactory)
    from nefertari.utils import dictset
    from nefertari.events import (
        ModelClassIs, FieldIsChanged, subscribe_to_events,
        add_field_processors)

    log.info("%s %s" % (APP_NAME, __version__))
    config.add_directive('get_root_resource', get_root_resource)
    config.add_directive('subscribe_to_events', subscribe_to_events)
    config.add_directive('add_field_processors', add_field_processors)
    config.add_renderer('json', JsonRendererFactory)
    config.add_renderer('nefertari_json', NefertariJsonRendererFactory)

    if not hasattr(config.registry, '_root_resources'):
        config.registry._root_resources = {}
    if not hasattr(config.registry, '_resources_map'):
        config.registry._resources_map = {}
    # Map of {ModelName: model_collection_resource}
    if not hasattr(config.registry, '_model_collections'):
        config.registry._model_collections = {}

    config.add_request_method(get_resource_map, 'resource_map', reify=True)

    config.add_tween('nefertari.tweens.cache_control')

    config.add_subscriber_predicate('model', ModelClassIs)
    config.add_subscriber_predicate('field', FieldIsChanged)

    Settings = dictset(config.registry.settings)
    root = config.get_root_resource()
    root.auth = Settings.asbool('auth')
开发者ID:geniusproject,项目名称:nefertari,代码行数:34,代码来源:__init__.py


示例12: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include("nefertari.engine")
    config.include("nefertari")
    config.include("nefertari.view")
    config.include("nefertari.elasticsearch")

    # Process nefertari settings
    if Settings.asbool("debug"):
        log.warning("*** DEBUG DEBUG DEBUG mode ***")
        config.add_tween("nefertari.tweens.get_tunneling")

    if Settings.asbool("cors.enable"):
        config.add_tween("nefertari.tweens.cors")

    if Settings.asbool("ssl_middleware.enable"):
        config.add_tween("nefertari.tweens.ssl")

    if Settings.asbool("request_timing.enable"):
        config.add_tween("nefertari.tweens.request_timing")

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool("ramses.auth", False)
    root.auth = ramses_auth

    log.info("Parsing RAML")
    parsed_raml = pyraml.parser.load(Settings["ramses.raml_schema"])

    log.info("Starting models generation")
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, "auth_model", None) is None:
            from nefertari.authentication.models import AuthUser

            config.registry.auth_model = AuthUser
        from .auth import setup_auth_policies

        setup_auth_policies(config, parsed_raml)

    log.info("Starting server generation")
    generate_server(parsed_raml, config)

    log.info("Running nefertari.engine.setup_database")
    from nefertari.engine import setup_database

    setup_database(config)

    from nefertari.elasticsearch import ES

    ES.setup_mappings()

    if ramses_auth:
        config.include("ramses.auth")

    log.info("Server succesfully generated\n")
开发者ID:mjhea0,项目名称:ramses,代码行数:60,代码来源:__init__.py


示例13: test_setup_aggregation_es_disabled

 def test_setup_aggregation_es_disabled(self, aggregator, mock_es):
     mock_es.settings = dictset(enable_aggregations=False)
     request = Mock(content_type='', method='', accept=[''])
     view = DummyBaseView(context={}, request=request,
                     _query_params={'foo': 'bar'})
     view.index = 1
     view._setup_aggregation()
     assert view.index == 1
开发者ID:geniusproject,项目名称:nefertari,代码行数:8,代码来源:test_view.py


示例14: test_setup_aggregation_index_not_defined

 def test_setup_aggregation_index_not_defined(self, aggregator, mock_es):
     mock_es.settings = dictset(enable_aggregations=True)
     request = Mock(content_type='', method='', accept=[''])
     view = DummyBaseView(context={}, request=request,
                     _query_params={'foo': 'bar'})
     assert view.index == view.not_allowed_action
     view._setup_aggregation()
     with pytest.raises(JHTTPMethodNotAllowed):
         view.index()
开发者ID:geniusproject,项目名称:nefertari,代码行数:9,代码来源:test_view.py


示例15: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include('nefertari.engine')
    config.include('nefertari')
    config.include('nefertari.view')

    # Process nefertari settings
    if Settings.asbool('debug'):
        log.warning('*** DEBUG DEBUG DEBUG mode ***')
        config.add_tween('nefertari.tweens.get_tunneling')

    if Settings.asbool('cors.enable'):
        config.add_tween('nefertari.tweens.cors')

    if Settings.asbool('ssl_middleware.enable'):
        config.add_tween('nefertari.tweens.ssl')

    if Settings.asbool('request_timing.enable'):
        config.add_tween('nefertari.tweens.request_timing')

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool('ramses.auth', False)
    root.auth = ramses_auth

    log.info('Parsing RAML')
    parsed_raml = pyraml.parser.load(Settings['ramses.raml_schema'])

    log.info('Starting models generation')
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, 'auth_model', None) is None:
            from nefertari.authentication.models import get_authuser_model
            config.registry.auth_model = get_authuser_model()
        from .auth import setup_auth_policies
        setup_auth_policies(config, parsed_raml)

    config.include('nefertari.elasticsearch')

    log.info('Starting server generation')
    generate_server(parsed_raml, config)

    log.info('Running nefertari.engine.setup_database')
    from nefertari.engine import setup_database
    setup_database(config)

    from nefertari.elasticsearch import ES
    ES.setup_mappings()

    if ramses_auth:
        config.include('ramses.auth')

    log.info('Server succesfully generated\n')
开发者ID:gitter-badger,项目名称:ramses,代码行数:57,代码来源:__init__.py


示例16: test_setup_aggregation

 def test_setup_aggregation(self, aggregator, mock_es):
     mock_es.settings = dictset(enable_aggregations=True)
     request = Mock(content_type='', method='', accept=[''])
     view = DummyBaseView(context={}, request=request,
                          _query_params={'foo': 'bar'})
     type(view).index = 1
     view._setup_aggregation()
     aggregator.assert_called_once_with(view)
     aggregator().wrap.assert_called_once_with(1)
     assert view.index == aggregator().wrap()
开发者ID:geniusproject,项目名称:nefertari,代码行数:10,代码来源:test_view.py


示例17: create_account

 def create_account(cls, params):
     user_params = dictset(params).subset(
         ['username', 'email', 'password', 'first_name', 'last_name'])
     try:
         user_params['status'] = 'inactive'
         return cls.get_or_create(
             email=user_params['email'],
             defaults=user_params)
     except JHTTPBadRequest as e:
         log.error(e)
         raise JHTTPBadRequest('Failed to create account.')
开发者ID:howaryoo,项目名称:nefertari-example,代码行数:11,代码来源:user.py


示例18: __init__

    def __init__(self, argv, log):
        parser = ArgumentParser(description=__doc__)

        parser.add_argument(
            '-c', '--config', help='config.ini (required)',
            required=True)
        parser.add_argument(
            '--quiet', help='Quiet mode', action='store_true',
            default=False)
        parser.add_argument(
            '--models',
            help=('Comma-separated list of model names to index '
                  '(required)'),
            required=True)
        parser.add_argument(
            '--params', help='Url-encoded params for each model')
        parser.add_argument('--index', help='Index name', default=None)
        parser.add_argument(
            '--chunk',
            help=('Index chunk size. If chunk size not provided '
                  '`elasticsearch.chunk_size` setting is used'),
            type=int)
        parser.add_argument(
            '--force',
            help=('Recreate ES mappings and reindex all documents of provided '
                  'models. By default, only documents that are missing from '
                  'index are indexed.'),
            action='store_true',
            default=False)

        self.options = parser.parse_args()
        if not self.options.config:
            return parser.print_help()

        # Prevent ES.setup_mappings running on bootstrap;
        # Restore ES._mappings_setup after bootstrap is over
        mappings_setup = getattr(ES, '_mappings_setup', False)
        try:
            ES._mappings_setup = True
            env = self.bootstrap[0](self.options.config)
        finally:
            ES._mappings_setup = mappings_setup

        registry = env['registry']
        # Include 'nefertari.engine' to setup specific engine
        config = Configurator(settings=registry.settings)
        config.include('nefertari.engine')

        self.log = log

        if not self.options.quiet:
            self.log.setLevel(logging.INFO)

        self.settings = dictset(registry.settings)
开发者ID:mbijon,项目名称:nefertari,代码行数:54,代码来源:es.py


示例19: get_by_ids

    def get_by_ids(self, ids, **params):
        if not ids:
            return _ESDocs()

        __raise_on_empty = params.pop('__raise_on_empty', False)
        fields = params.pop('_fields', [])

        _limit = params.pop('_limit', len(ids))
        _page = params.pop('_page', None)
        _start = params.pop('_start', None)
        _start, _limit = process_limit(_start, _page, _limit)

        docs = []
        for _id in ids:
            docs.append(
                dict(
                    _index=self.index_name,
                    _type=self.src2type(_id['_type']),
                    _id=_id['_id']
                )
            )

        params = dict(
            body=dict(docs=docs)
        )
        if fields:
            params['fields'] = fields

        data = ES.api.mget(**params)
        documents = _ESDocs()

        for _d in data['docs']:
            try:
                _d = _d['fields'] if fields else _d['_source']
            except KeyError:
                msg = "ES: '%s(%s)' resource not found" % (
                    _d['_type'], _d['_id'])
                if __raise_on_empty:
                    raise JHTTPNotFound(msg)
                else:
                    log.error(msg)
                    continue

            documents.append(dict2obj(dictset(_d)))

        documents._nefertari_meta = dict(
            total=len(documents),
            start=_start,
            fields=fields,
        )

        return documents
开发者ID:howaryoo,项目名称:nefertari,代码行数:52,代码来源:elasticsearch.py


示例20: prepare_request_params

    def prepare_request_params(self, _query_params, _json_params):
        """ Prepare query and update params. """
        self._query_params = dictset(
            _query_params or self.request.params.mixed())
        self._json_params = dictset(_json_params)

        ctype = self.request.content_type
        if self.request.method in ['POST', 'PUT', 'PATCH']:
            if ctype == 'application/json':
                try:
                    self._json_params.update(self.request.json)
                except simplejson.JSONDecodeError:
                    log.error(
                        "Expecting JSON. Received: '{}'. "
                        "Request: {} {}".format(
                            self.request.body, self.request.method,
                            self.request.url))

            self._json_params = BaseView.convert_dotted(self._json_params)
            self._query_params = BaseView.convert_dotted(self._query_params)

        self._params = self._query_params.copy()
        self._params.update(self._json_params)
开发者ID:oleduc,项目名称:nefertari,代码行数:23,代码来源:view.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dictset.dictset函数代码示例发布时间:2022-05-27
下一篇:
Python elasticsearch.ES类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap