Mock for #pkg_resources.declare_namespace() which calls
    #pkgutil.extend_path() afterwards as the original implementation doesn't
    seem to properly find all available namespace paths.
480050
def _declare_namespace(self, package_name):
    '''
    
    '''

    self.state['declare_namespace'](package_name)
    mod = sys.modules[package_name]
    mod.__path__ = pkgutil.extend_path(mod.__path__, package_name)
1355815
def add_namespace(self, namespace, interface=None, check_extras=True,
                      load_now=False):
        
        tempo = self._namespaces.get(namespace)

        if tempo is None:
            tempo = _Plugins(namespace, interface, check_extras)
            self._namespaces[namespace] = tempo

        if load_now:
            tempo.load()

        return tempo
666928
def parse_localnamespacepath(parser, event, node):
    #pylint: disable=unused-argument
    

    (next_event, next_node) = six.next(parser)

    namespaces = []

    if not _is_start(next_event, next_node, 'NAMESPACE'):
        print(next_event, next_node)
        raise ParseError('Expecting NAMESPACE')

    namespaces.append(parse_namespace(parser, next_event, next_node))

    while 1:

        (next_event, next_node) = six.next(parser)

        if _is_end(next_event, next_node, 'LOCALNAMESPACEPATH'):
            break

        if _is_start(next_event, next_node, 'NAMESPACE'):
            namespaces.append(parse_namespace(parser, next_event, next_node))
        else:
            raise ParseError('Expecting NAMESPACE')

    return '/'.join(namespaces)
520526
def _fake_openenumerateinstances(self, namespace, **params):
        
        self._validate_namespace(namespace)
        self._validate_open_params(**params)

        result_t = self._fake_enumerateinstances(namespace, **params)

        return self._open_response(result_t[0][2], namespace,
                                   'PullInstancesWithPath', **params)
79684
def _fake_openassociatorinstancepaths(self, namespace, **params):
        # pylint: disable=invalid-name
        
        self._validate_namespace(namespace)
        self._validate_open_params(**params)
        params['ObjectName'] = params['InstanceName']
        del params['InstanceName']

        result = self._fake_associatornames(namespace, **params)

        objects = [] if result is None else [x[2] for x in result[0][2]]

        return self._open_response(objects, namespace,
                                   'PullInstancePaths', **params)
408266
def ensure_namespace(self, name):
        # type: (str) -> ApiNamespace
        
        if name not in self.namespaces:
            self.namespaces[name] = ApiNamespace(name)
        return self.namespaces[name]
1321901
def register_namespace(self, namespace_handler):
        
        if not isinstance(namespace_handler, namespace.Namespace):
            raise ValueError('Not a namespace instance')
        if self.is_asyncio_based() != namespace_handler.is_asyncio_based():
            raise ValueError('Not a valid namespace class for this server')
        namespace_handler._set_server(self)
        self.namespace_handlers[namespace_handler.namespace] = \
            namespace_handler
1241467
@SuppressWarnings("resource")
	public ISynchronizationPoint<Exception> registerNamespace(String namespace, String path, ClassLoader classLoader) {
		Namespace ns;
		SynchronizationPoint<Exception> sp = new SynchronizationPoint<>();
		synchronized (namespaces) {
			ns = namespaces.get(namespace);
			if (ns == null) {
				ns = new Namespace();
				ns.loading = sp;
				namespaces.put(namespace, ns);
			} else {
				ns.loading.cancel(new CancelException("Namespace overriden"));
				ns.loading = sp;
				ns.languages = null;
			}
		}
		ns.classLoader = classLoader;
		ns.path = path;
		IOProvider.Readable provider = new IOProviderFromPathUsingClassloader(classLoader).get(path + ".languages");
		IO.Readable input;
		try { input = provider == null ? null : provider.provideIOReadable(Task.PRIORITY_RATHER_IMPORTANT); }
		catch (IOException e) {
			sp.error(new Exception("Localized properties for namespace " + namespace
				+ " cannot be loaded because the file " + path + ".languages does not exist", e));
			logger.error(sp.getError().getMessage());
			return sp;
		}
		if (input == null) {
			sp.error(new Exception("Localized properties for namespace " + namespace
				+ " cannot be loaded because the file " + path + ".languages does not exist"));
			logger.error(sp.getError().getMessage());
			return sp;
		}
		AsyncWork<UnprotectedStringBuffer, IOException> read = IOUtil.readFullyAsString(
			input, StandardCharsets.US_ASCII, Task.PRIORITY_RATHER_IMPORTANT);
		Namespace toLoad = ns;
		read.listenAsyncSP(new Task.Cpu.FromRunnable("Read localized properties namespace file", Task.PRIORITY_RATHER_IMPORTANT, () -> {
			List<Namespace.Language> languages = new LinkedList<>();
			UnprotectedStringBuffer str = read.getResult();
			for (UnprotectedStringBuffer s : str.split(',')) {
				s.trim().toLowerCase();
				if (s.length() == 0) continue;
				Namespace.Language l = new Namespace.Language();
				List<UnprotectedStringBuffer> list = s.split('-');
				l.tag = new String[list.size()];
				int i = 0;
				for (UnprotectedStringBuffer us : list) l.tag[i++] = us.asString();
				languages.add(l);
			}
			languages.sort(new Comparator<Namespace.Language>() {
				@Override
				public int compare(Namespace.Language l1, Namespace.Language l2) {
					/* Order:
					 *  tags are alphabetically ordered
					 *  but tags xx-yy are before tag xx
					 */
					int i = 0;
					do {
						if (i == l1.tag.length) return 1;
						if (i == l2.tag.length) return -1;
						int c = l1.tag[i].compareTo(l2.tag[i]);
						if (c != 0) return c;
						i++;
					} while (true);
				}
			});
			toLoad.languages = languages.toArray(new Namespace.Language[languages.size()]);
			// set parents
			for (int i = 0; i < toLoad.languages.length; ++i) {
				// they are ordered, so the parent is after
				int nbI = toLoad.languages[i].tag.length;
				for (int j = i + 1; j < toLoad.languages.length; ++j) {
					int nbJ = toLoad.languages[j].tag.length;
					if (nbJ >= nbI) continue;
					if (ArrayUtil.equals(toLoad.languages[i].tag, 0, toLoad.languages[j].tag, 0, nbJ))
						toLoad.languages[i].parent = toLoad.languages[j];
					break;
				}
			}
			sp.unblock();
			logger.info("Namespace " + namespace + " loaded with " + languages.size() + " languages from " + path);
		}), sp);
		sp.listenInline(() -> { input.closeAsync(); });
		sp.onError((error) -> {
			logger.error("Error loading localized properties namespace file " + path + ".languages", error);
		}
1271868
def activate(self, path=None, replace=False):
        """"""
        if path is None:
            path = sys.path
        self.insert_on(path, replace=replace)
        if path is sys.path:
            fixup_namespace_packages(self.location)
            for pkg in self._get_metadata('namespace_packages.txt'):
                if pkg in sys.modules:
                    declare_namespace(pkg)
626256
def GET_namespace_info( self, path_info, namespace_id ):
        
        if not check_namespace(namespace_id):
            return self._reply_json({'error': 'Invalid namespace'}, status_code=400)

        blockstackd_url = get_blockstackd_url()
        namespace_rec = blockstackd_client.get_namespace_record(namespace_id, hostport=blockstackd_url)
        if json_is_error(namespace_rec):
            # error
            status_code = namespace_rec.get('http_status', 502)
            return self._reply_json({'error': namespace_rec['error']}, status_code=status_code)

        self._reply_json(namespace_rec)
        return
224874
def add_namespace(image, path)
      namespace path.to_sym do |_args|
        require 'rspec/core/rake_task'
        ::RSpec::Core::RakeTask.new(:spec) do |task|
          task.pattern = "#{path}/spec/*_spec.rb"
        end

        docker_image = Vtasks::Docker::Image.new(image, path, args)

        lint_image(path)

        desc 'Build and tag docker image'
        task :build do
          docker_image.build_with_tags
        end

        desc 'Publish docker image'
        task :push do
          docker_image.push
        end
      end
    end
1315100
def declares_namespace_package(filename):
  """"""

  import ast

  with open(filename) as fp:
    init_py = ast.parse(fp.read(), filename)
  calls = [node for node in ast.walk(init_py) if isinstance(node, ast.Call)]
  for call in calls:
    if len(call.args) != 1:
      continue
    if isinstance(call.func, ast.Attribute) and call.func.attr != 'declare_namespace':
      continue
    if isinstance(call.func, ast.Name) and call.func.id != 'declare_namespace':
      continue
    if isinstance(call.args[0], ast.Name) and call.args[0].id == '__name__':
      return True
  return False
939088
public void extendWith(Namespace ns) {
	if (ns==null) return;
	if (ns.getDefaultNamespace()!=null) {
	    registerDefault(ns.getDefaultNamespace());
	}
	for (String prefix: ns.prefixes.keySet()) {
	    register(prefix, ns.prefixes.get(prefix));
	}
    }
47699
function(name, config) {
            config = config || {};
            config = _.defaults(config, {
                loader: configs.resources.loader
            });
            config = _.extend(config, {
                namespace: name
            });
            Resources.namespaces[name] = config;
        }
600870
function nameSpacedDefine(nameSpace, id, deps, callback) {
  // only add name space for modules in user space
  // also skip any ext: plugin (a dumber-module-loader feature)
  if (currentSpace === userSpace && id.slice(0, 4) !== 'ext:') {
    const parsed = parse(id);
    userSpace.define(parsed.prefix + nameSpace + '/' + parsed.bareId, deps, callback);
  } else {
    currentSpace.define(id, deps, callback);
  }
}
391296
private boolean isInZkWathcedNamespacePaths(String path) {
        if (StringUtil.isEmpty(path)) {
            return false;
        }
        for (String watchNamespacePath : RpcClientConf.ZK_WATCH_NAMESPACE_PATHS) {
            if (StringUtil.isEmpty(watchNamespacePath)) {
                continue;
            }
            if (path.contains(watchNamespacePath)) {
                return true;
            }
        }
        return false;
    }
841899
def undeclared_namespace_bindings(ns_stack, ns_explicit)
      Hash[ns_explicit.map do |prefix,uri|
             [prefix, uri] if !find_namespace_uri(ns_stack, prefix, uri)
           end.compact]
    end