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


Python munch.munchify方法代码示例

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


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

示例1: get_config

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def get_config(default_file):
    p = argparse.ArgumentParser(description='Learned Step Size Quantization')
    p.add_argument('config_file', metavar='PATH', nargs='+',
                   help='path to a configuration file')
    arg = p.parse_args()

    with open(default_file) as yaml_file:
        cfg = yaml.safe_load(yaml_file)

    for f in arg.config_file:
        if not os.path.isfile(f):
            raise FileNotFoundError('Cannot find a configuration file at', f)
        with open(f) as yaml_file:
            c = yaml.safe_load(yaml_file)
            cfg = merge_nested_dict(cfg, c)

    return munch.munchify(cfg) 
开发者ID:zhutmost,项目名称:lsq-net,代码行数:19,代码来源:config.py

示例2: test_fetch_got_data

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def test_fetch_got_data(self):
        queue_items = munchify({
            'items': [{
                'data': {
                    'id': 1
                },
                'meta': {
                    'type': 'user',
                    'sync': {
                        'event_type': 'created',
                        'ack_key': 'User-1234-1',
                        'revision': 1
                    }
                }
            }]
        })
        http_client = mock.create_autospec(basecrm.HttpClient)
        http_client.get.return_value = (200, {}, queue_items)

        sync = basecrm.SyncService(http_client)
        self.assertEquals(sync.fetch(self.device_uuid, self.session_id), queue_items['items'])
        http_client.get.assert_called_once_with("/sync/{session_id}/queues/main".format(session_id=self.session_id),
                                                params=None,
                                                headers={'X-Basecrm-Device-UUID': self.device_uuid},
                                                raw=True) 
开发者ID:zendesk,项目名称:basecrm-python,代码行数:27,代码来源:test_sync_service.py

示例3: disableEditorTracking

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def disableEditorTracking(self):
        """Disables editor tracking."""
        capabilities = self.get(CAPABILITIES, '').split(',')
        editorInfo = self.get(EDITOR_TRACKING_INFO, {
            "enableEditorTracking": False,
            "enableOwnershipAccessControl": False,
            "allowOthersToUpdate": True,
            "allowOthersToDelete": True,
            "allowOthersToQuery": True,
            "allowAnonymousToUpdate": True,
            "allowAnonymousToDelete": True
          })
        editorInfo["enableEditorTracking"] = False

        # enable editor tracking at Feature Service level
        result = {}
        if CHANGE_TRACKING in capabilities:
            capabilities.remove(CHANGE_TRACKING)
            capabilities = ','.join(capabilities)
            result['disabled_at_feature_service'] = self.updateDefinition({CAPABILITIES: capabilities, HAS_STATIC_DATA: self.get(HAS_STATIC_DATA), EDITOR_TRACKING_INFO: editorInfo})
        else:
            result['disabled_at_feature_service'] = {'status': 'already disabled'}

        return munch.munchify(result) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:26,代码来源:__init__.py

示例4: createNewDateFieldDefinition

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def createNewDateFieldDefinition(name, alias='', autoUpdate=False):
        """Creates a json definition for a new date field.

        Args
            name: Name of new date field.
            alias: Optional field name for alias.
            autoUpdate: Optional boolean to automatically populate the field 
                with the current date/time when a new record is added or updated 
                (like editor tracking). The default is False.
        """

        return munch.munchify({
            NAME: name,
            TYPE: DATE_FIELD,
            ALIAS: alias or name,
            SQL_TYPE: SQL_TYPE_OTHER,
            NULLABLE: FALSE,
            EDITABLE: TRUE,
            DOMAIN: NULL,
            DEFAULT_VALUE: SQL_AUTO_DATE_EXP if autoUpdate else NULL
        }) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:23,代码来源:__init__.py

示例5: getFeatureExtent

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def getFeatureExtent(in_features):
    """Gets the extent for a FeatureSet() or GeometryCollection(), must be convertible
    to a GeometryCollection().

    Arg:
        in_features: Input features (Feature|FeatureSet|GeometryCollection|json).
    
    Returns:
        An envelope json structure (extent).
    """

    if not isinstance(in_features, GeometryCollection):
        in_features = GeometryCollection(in_features)

    extents = [g.envelopeAsJSON() for g in iter(in_features)]
    full_extent = {SPATIAL_REFERENCE: extents[0].get(SPATIAL_REFERENCE)}
    for attr, op in {XMIN: min, YMIN: min, XMAX: max, YMAX: max}.iteritems():
        full_extent[attr] = op([e.get(attr) for e in extents])
    return munch.munchify(full_extent) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:21,代码来源:common_types.py

示例6: unqualify_fields

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def unqualify_fields(fs):
    """Removes fully qualified field names from a feature set.

    Arg:
        fs: restapi.FeatureSet() object or JSON.
    """

    if not isinstance(fs, FeatureSet):
        fs = FeatureSet(fs)

    clean_fields = {}
    for f in fs.fields:
        if f:
            clean = f.name.split('.')[-1]
            clean_fields[f.name] = clean
            f.name = clean

    for i,feature in enumerate(fs.features):
        feature_copy = {}
        for f, val in six.iteritems(feature.attributes):
            feature_copy[clean_fields.get(f, f)] = val
        fs.features[i].attributes = munch.munchify(feature_copy) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:24,代码来源:common_types.py

示例7: _spatialReference

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def _spatialReference(self):
        """Gets the spatial reference dict."""
        resp_d = {}
        if SPATIAL_REFERENCE in self.json:
            resp_d = self.json[SPATIAL_REFERENCE]
        elif self.json.get(EXTENT) and SPATIAL_REFERENCE in self.json[EXTENT]:
            resp_d = self.json[EXTENT][SPATIAL_REFERENCE]
        elif GEOMETRIES in self.json:
            try:
                first = self.json.get(GEOMETRIES, [])[0]
                resp_d = first.get(SPATIAL_REFERENCE) or {}
            except IndexError:
                pass
        elif CRS in self.json:
            resp_d = self.json.get(CRS, {})
        return munch.munchify(resp_d) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:18,代码来源:rest_utils.py

示例8: __init__

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def __init__(self, in_json):
        """Inits class with JSON as geo feature set.

        Arg:
            in_json: Input json response from request.
        """

        if isinstance(in_json, six.string_types):
            if not in_json.startswith('{') and os.path.isfile(in_json):
                with open(in_json, 'r') as f:
                    in_json = json.load(f)
            else:
                in_json = json.loads(in_json)
        if isinstance(in_json, self.__class__):
            self.json = in_json.json
        elif isinstance(in_json, dict):
            self.json = munch.munchify(in_json) 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:19,代码来源:rest_utils.py

示例9: _load_global_setting

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def _load_global_setting(self, candidate, variables):
        """
        Load and render global setting with variables.
        :param candidate: Global setting as a `dict`
        :param variables: variables from context to render setting
        :return: A `Munch` object
        """
        candidate = candidate or {}
        proxy_setting = self._load_proxy(candidate.get('proxy'), variables)
        log_setting = self._load_logging(candidate.get('logging'), variables)

        return munchify({'proxy': proxy_setting, 'logging': log_setting}) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:loader.py

示例10: _load_request

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def _load_request(self, request):
        options = self._load_options(request['request'])

        pre_process = self._load_processor(request.get('pre_process', {}))
        post_process = self._load_processor(request['post_process'])
        checkpoint = self._load_checkpoint(request.get('checkpoint'))
        iteration_mode = self._load_iteration_mode(request['iteration_mode'])

        return munchify({
            'request': options,
            'pre_process': pre_process,
            'post_process': post_process,
            'checkpoint': checkpoint,
            'iteration_mode': iteration_mode,
        }) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:loader.py

示例11: load

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def load(self, definition, schema_file, context):
        """Load cloud connect configuration from a `dict` and validate
        it with schema and global settings will be rendered.
        :param schema_file: Schema file location used to validate config.
        :param definition: A dictionary contains raw configs.
        :param context: variables to render template in global setting.
        :return: A `Munch` object.
        """
        try:
            validate(definition, self._get_schema_from_file(schema_file))
        except ValidationError:
            raise ConfigException(
                'Failed to validate interface with schema: {}'.format(
                    traceback.format_exc()))

        try:
            global_settings = self._load_global_setting(
                definition.get('global_settings'), context
            )

            requests = [self._load_request(item) for item in definition['requests']]

            return munchify({
                'meta': munchify(definition['meta']),
                'tokens': definition['tokens'],
                'global_settings': global_settings,
                'requests': requests,
            })
        except Exception as ex:
            error = 'Unable to load configuration: %s' % str(ex)
            _logger.exception(error)
            raise ConfigException(error) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:34,代码来源:loader.py

示例12: read_config

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def read_config():
    """Attempts to read the application configuration file and will raise a `FileNotFoundError` if the
    configuration file is not found. Returns the folder where the configuration file was loaded from, and
    a `Munch` (dict-like object) containing the configuration

    Configuration file paths searched, in order:
        * ~/.cinq/config.json'
        * ./config.json
        * /usr/local/etc/cloud-inquisitor/config.json

    Returns:
        `str`, `dict`
    """
    def __recursive_update(old, new):
        out = deepcopy(old)
        for k, v in new.items():
            if issubclass(type(v), dict):
                if k in old:
                    out[k] = __recursive_update(old[k], v)
                else:
                    out[k] = v
            else:
                out[k] = v

        return out

    for fpath in CONFIG_FILE_PATHS:
        if os.path.exists(fpath):
            data = munch.munchify(json.load(open(fpath, 'r')))

            # Our code expects a munch, so ensure that any regular dicts are converted
            return os.path.dirname(fpath), munch.munchify(__recursive_update(DEFAULT_CONFIG, data))

    raise FileNotFoundError('Configuration file not found') 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:36,代码来源:utils.py

示例13: new_build

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def new_build(profile='cbs', scratch=True):
    # Very ugly: some utilities are only available in koji CLI
    # and not in the koji module
    if not KOJI_AVAILABLE:
        raise ModuleNotAvailable(module='koji')
    if not RPM_AVAILABLE:
        raise RpmModuleNotAvailable()
    import imp
    kojibin = find_executable('koji')
    kojicli = imp.load_source('kojicli', kojibin)
    # Koji 1.13 moves client internal API into another path
    try:
        from koji_cli.lib import _unique_path, _progress_callback, watch_tasks
    except ImportError:
        from kojicli import _unique_path, _progress_callback, watch_tasks

    kojiclient = setup_kojiclient(profile)
    # Note: required to make watch_tasks work
    kojicli.options = opts = munchify(kojiclient.opts)
    build_target = guess_build()
    if not build_target:
        log.warn("failed to identify build tag from branch")
        return

    retrieve_sources()
    srpm = create_srpm()
    if not srpm:
        log.warn('No srpm available')
        return
    serverdir = _unique_path('cli-build')
    kojiclient.uploadWrapper(srpm, serverdir, callback=_progress_callback)
    source = "%s/%s" % (serverdir, os.path.basename(srpm))
    task_id = kojiclient.build(source, build_target, {'scratch': scratch})
    print("Created task:", task_id)

    print("Task info: {}/taskinfo?taskID={}".format(opts['weburl'], task_id))
    kojiclient.logout()
    watch_tasks(kojiclient, [task_id]) 
开发者ID:softwarefactory-project,项目名称:rdopkg,代码行数:40,代码来源:cbsbuild.py

示例14: unwrap_envelope

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def unwrap_envelope(body):
        return [munchify(item['data']) for item in body['items']] if 'items' in body else munchify(body['data']) 
开发者ID:zendesk,项目名称:basecrm-python,代码行数:4,代码来源:http_client.py

示例15: __init__

# 需要导入模块: import munch [as 别名]
# 或者: from munch import munchify [as 别名]
def __init__(self, http_status, errors_payload):
        """
        :param int http_status: Http status code.
        :param dict errors_payload: Json decoded payload from the errors response.
        """
        self.http_status = http_status
        self.errors = [munchify(error_envelope['error'])
                       for error_envelope in errors_payload['errors']]
        self.logref = errors_payload['meta']['logref']

        message = "\n".join([str(error) for error in self.errors])
        super(BaseError, self).__init__(message) 
开发者ID:zendesk,项目名称:basecrm-python,代码行数:14,代码来源:errors.py


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