List existing config namespaces and their items
199246
def get(self):
        """"""
        namespaces = db.ConfigNamespace.order_by(
            ConfigNamespace.sort_order,
            ConfigNamespace.name
        ).all()

        return self.make_response({
            'message': None,
            'namespaces': namespaces
        }, HTTP.OK)
867743
def from_namespace(cls, namespace):
        """"""
        config = cls()
        for slot in cls.__slots__:
            if slot.startswith('_'):
                slot = slot[1:]
            if not hasattr(namespace, slot):
                continue
            setattr(config, slot, getattr(namespace, slot))

        return config
593061
def list(self):
    '''
    '''
    if not self._list:
      self._list = map(Namespace, self._string.split('/'))
    return self._list
1212036
def _filter_namespaces_by_route_whitelist(self):
        
        assert self._routes is not None, "Missing route whitelist"
        assert 'route_whitelist' in self._routes
        assert 'datatype_whitelist' in self._routes

        # Get route whitelist in canonical form
        route_whitelist = {}
        for namespace_name, route_reprs in self._routes['route_whitelist'].items():
            new_route_reprs = []
            if route_reprs == ['*']:
                namespace = self.api.namespaces[namespace_name]
                new_route_reprs = [route.name_with_version() for route in namespace.routes]
            else:
                for route_repr in route_reprs:
                    route_name, version = parse_route_name_and_version(route_repr)
                    if version > 1:
                        new_route_reprs.append('{}:{}'.format(route_name, version))
                    else:
                        new_route_reprs.append(route_name)
            route_whitelist[namespace_name] = new_route_reprs

        # Parse the route whitelist and populate any starting data types
        route_data_types = []
        for namespace_name, route_reprs in route_whitelist.items():
            # Error out if user supplied nonexistent namespace
            if namespace_name not in self.api.namespaces:
                raise AssertionError('Namespace %s is not defined!' % namespace_name)
            namespace = self.api.namespaces[namespace_name]

            # Parse namespace doc refs and add them to the starting data types
            if namespace.doc is not None:
                route_data_types.extend(
                    parse_data_types_from_doc_ref(self.api, namespace.doc, namespace_name))

            # Parse user-specified routes and add them to the starting data types
            # Note that this may add duplicates, but that's okay, as the recursion
            # keeps track of visited data types.
            assert '*' not in route_reprs
            for routes_repr in route_reprs:
                route_name, version = parse_route_name_and_version(routes_repr)
                if route_name not in namespace.routes_by_name or \
                        version not in namespace.routes_by_name[route_name].at_version:
                    raise AssertionError('Route %s at version %d is not defined!' %
                                         (route_name, version))

                route = namespace.routes_by_name[route_name].at_version[version]
                route_data_types.extend(namespace.get_route_io_data_types_for_route(route))
                if route.doc is not None:
                    route_data_types.extend(
                        parse_data_types_from_doc_ref(self.api, route.doc, namespace_name))

        # Parse the datatype whitelist and populate any starting data types
        for namespace_name, datatype_names in self._routes['datatype_whitelist'].items():
            if namespace_name not in self.api.namespaces:
                raise AssertionError('Namespace %s is not defined!' % namespace_name)

            # Parse namespace doc refs and add them to the starting data types
            namespace = self.api.namespaces[namespace_name]
            if namespace.doc is not None:
                route_data_types.extend(
                    parse_data_types_from_doc_ref(self.api, namespace.doc, namespace_name))

            for datatype_name in datatype_names:
                if datatype_name not in self.api.namespaces[namespace_name].data_type_by_name:
                    raise AssertionError('Datatype %s is not defined!' % datatype_name)
                data_type = self.api.namespaces[namespace_name].data_type_by_name[datatype_name]
                route_data_types.append(data_type)

        # Recurse on dependencies
        output_types_by_ns, output_routes_by_ns = self._find_dependencies(route_data_types)

        # Update the IR representation. This involves editing the data types and
        # routes for each namespace.
        for namespace in self.api.namespaces.values():
            data_types = list(set(output_types_by_ns[namespace.name]))  # defaults to empty list
            namespace.data_types = data_types
            namespace.data_type_by_name = {d.name: d for d in data_types}

            output_route_reprs = [output_route.name_with_version()
                                  for output_route in output_routes_by_ns[namespace.name]]
            if namespace.name in route_whitelist:
                whitelisted_route_reprs = route_whitelist[namespace.name]
                route_reprs = list(set(whitelisted_route_reprs + output_route_reprs))
            else:
                route_reprs = output_route_reprs

            routes = []
            for route_repr in route_reprs:
                route_name, version = parse_route_name_and_version(route_repr)
                route = namespace.routes_by_name[route_name].at_version[version]
                routes.append(route)

            namespace.routes = []
            namespace.route_by_name = {}
            namespace.routes_by_name = {}
            for route in routes:
                namespace.add_route(route)
85521
def _updateNamespace(item, new_namespace):
    '''
    
    '''
    temp_item = ''
    i = item.tag.find('}')
    if i >= 0:
        temp_item = item.tag[i+1:]
    else:
        temp_item = item.tag
    item.tag = '{{{0}}}{1}'.format(new_namespace, temp_item)
    for child in item.getiterator():
        if isinstance(child.tag, six.string_types):
            temp_item = ''
            i = child.tag.find('}')
            if i >= 0:
                temp_item = child.tag[i+1:]
            else:
                temp_item = child.tag
            child.tag = '{{{0}}}{1}'.format(new_namespace, temp_item)
    return item
1274181
def config(self):
        """"""
        conf = config.Configuration()
        for namespace in self.namespaces:

            if not hasattr(conf, namespace):

                if not self._strict:

                    continue

                raise exc.NamespaceNotRegistered(
                    "The namespace {0} is not registered.".format(namespace)
                )

            name = getattr(conf, namespace)

            for item, value in compat.iteritems(self.items(namespace)):

                if not hasattr(name, item):

                    if not self._strict:

                        continue

                    raise exc.OptionNotRegistered(
                        "The option {0} is not registered.".format(item)
                    )

                setattr(name, item, value)

        return conf
909514
def config_list(args):
    
    verbose = fcconfig.verbosity
    if args.workspace:
        if verbose:
            print("Retrieving method configs from space {0}".format(args.workspace))
        if not args.project:
            eprint("No project given, and no default project configured")
            return 1
        r = fapi.list_workspace_configs(args.project, args.workspace)
        fapi._check_response_code(r, 200)
    else:
        if verbose:
            print("Retrieving method configs from method repository")
        r = fapi.list_repository_configs(namespace=args.namespace,
                                         name=args.config,
                                         snapshotId=args.snapshot_id)
        fapi._check_response_code(r, 200)

    # Parse the JSON for the workspace + namespace
    methods = r.json()
    results = []
    for m in methods:
        ns = m['namespace']
        if not ns:
            ns = '__EMPTYSTRING__'
        name = m['name']
        # Ugh: configs in workspaces look different from configs in methodRepo
        mver = m.get('methodRepoMethod', None)
        if mver:
            mver = mver.get('methodVersion', 'unknown')     # space config
        else:
            mver = m.get('snapshotId', 'unknown')           # repo  config
        results.append('{0}\t{1}\tsnapshotId:{2}'.format(ns, name, mver))

    # Sort for easier viewing, ignore case
    return sorted(results, key=lambda s: s.lower())
596936
def get_namespace(self, name_seq):
        
        namespaces = self.namespaces
        result = []
        for name in name_seq:
            namespaces = namespaces.get(name)
            if not namespaces:
                break
            result.append(name)
        return result
1201873
def get_config_items(self):
        
        return (
            ('settings', self.settings),
            ('context_class', self.context_class),
            ('interfaces', self.interfaces),
            ('logging', self.logging),
            ('name', self.name),
            ('init_handler', self.init_handler),
            ('sigusr1_handler', self.sigusr1_handler),
            ('sigusr2_handler', self.sigusr2_handler),
        )
735036
def _merge_namespace_options(
    namespace_set=None,
    ex_namespace_set=None,
    gridfs_set=None,
    dest_mapping=None,
    namespace_options=None,
    include_fields=None,
    exclude_fields=None,
):
    
    namespace_set = set(namespace_set or [])
    ex_namespace_set = set(ex_namespace_set or [])
    gridfs_set = set(gridfs_set or [])
    dest_mapping = dest_mapping or {}
    namespace_options = namespace_options or {}
    include_fields = set(include_fields or [])
    exclude_fields = set(exclude_fields or [])
    namespaces = {}

    for source_name, options_or_str in namespace_options.items():
        if isinstance(options_or_str, dict):
            namespace_set.add(source_name)
            if options_or_str.get("gridfs"):
                gridfs_set.add(source_name)
            namespaces[source_name] = Namespace(
                dest_name=options_or_str.get("rename"),
                include_fields=options_or_str.get("includeFields"),
                exclude_fields=options_or_str.get("excludeFields"),
                gridfs=options_or_str.get("gridfs", False),
            )
        elif isinstance(options_or_str, str):
            namespace_set.add(source_name)
            namespaces[source_name] = Namespace(dest_name=options_or_str)
        elif options_or_str:
            namespace_set.add(source_name)
        else:
            ex_namespace_set.add(source_name)

    # Add namespaces that are renamed but not in namespace_options
    for source_name, target_name in dest_mapping.items():
        namespaces[source_name] = namespaces.get(source_name, Namespace()).with_options(
            dest_name=target_name
        )

    # Add namespaces that are included but not in namespace_options
    for included_name in namespace_set:
        if included_name not in namespaces:
            namespaces[included_name] = Namespace()

    # Add namespaces that are excluded but not in namespace_options
    for gridfs_name in gridfs_set:
        namespaces[gridfs_name] = namespaces.get(gridfs_name, Namespace()).with_options(
            gridfs=True
        )

    # Add source, destination name, and globally included and excluded fields
    for included_name in namespaces:
        namespace = namespaces[included_name]
        namespace = namespace.with_options(
            source_name=included_name,
            include_fields=validate_include_fields(
                include_fields, namespace.include_fields
            ),
            exclude_fields=validate_exclude_fields(
                exclude_fields, namespace.exclude_fields
            ),
        )
        # The default destination name is the same as the source.
        if not namespace.dest_name:
            namespace = namespace.with_options(dest_name=included_name)
        namespaces[included_name] = namespace

    return ex_namespace_set, namespaces
1012952
def _get_existing_conf(config):
    
    try:
        with open(os.path.join(config, 'local.conf'), 'r') as f:
            lines = [line for line in f.readlines()
                     if not (line.startswith('service_id') or line.startswith('client_secret'))]
    except IOError:
        lines = []
    return lines
293545
def rpc_get_all_namespaces( self, **con_info ):
        
        db = get_db_state(self.working_dir)
        all_namespaces = db.get_all_namespace_ids()
        db.close()

        return self.success_response( {'namespaces': all_namespaces} )
520106
def GET_namespaces( self, path_info ):
        
        qs_values = path_info['qs_values']
        offset = qs_values.get('offset', None)
        count = qs_values.get('count', None)

        blockstackd_url = get_blockstackd_url()
        namespaces = blockstackd_client.get_all_namespaces(offset=offset, count=count, hostport=blockstackd_url)
        if json_is_error(namespaces):
            # error
            status_code = namespaces.get('http_status', 502)
            return self._reply_json({'error': namespaces['error']}, status_code=status_code)

        self._reply_json(namespaces)
        return
1171279
def named_config(name: str, config_dict: typing.Mapping) -> None:
    
    names = (
        name
        if isinstance(name, Iterable) and not isinstance(name, (str, bytes))
        else [name]
    )
    for each in names:
        _config_registry[each] = Config(**config_dict)
608705
def get_namespace(name):
    
    if name not in configuration_namespaces:
        configuration_namespaces[name] = ConfigNamespace(name)
    return configuration_namespaces[name]
192005
def has_enumerated_namespace_name(self, namespace: str, name: str) -> bool:
        """"""
        return self.has_enumerated_namespace(namespace) and name in self.namespace_to_terms[namespace]
893350
def cmd_list(unused_conf: Config):
    """"""
    for name, builder in sorted(Plugin.builders.items()):
        if builder.func:
            print('+- {0:16s} implemented in {1.__module__}.{1.__name__}()'
                  .format(name, builder.func))
        else:
            print('+- {0:16s} loaded with no builder function'.format(name))
        for hook_name, hook_func in sorted(Plugin.get_hooks_for_builder(name)):
            print('  +- {0} hook implemented in '
                  '{1.__module__}.{1.__name__}()'
                  .format(hook_name, hook_func))