Replaces %%%NAMESPACE%%% for all files and ___NAMESPACE___ in all
        filenames in the zip with the either '' if no namespace is provided
        or 'namespace__' if provided.
343328
def zip_inject_namespace(
    zip_src,
    namespace=None,
    managed=None,
    filename_token=None,
    namespace_token=None,
    namespaced_org=None,
    logger=None,
):
    

    # Handle namespace and filename tokens
    if not filename_token:
        filename_token = "___NAMESPACE___"
    if not namespace_token:
        namespace_token = "%%%NAMESPACE%%%"
    if managed is True and namespace:
        namespace_prefix = namespace + "__"
    else:
        namespace_prefix = ""

    # Handle tokens %%%NAMESPACED_ORG%%% and ___NAMESPACED_ORG___
    namespaced_org_token = "%%%NAMESPACED_ORG%%%"
    namespaced_org_file_token = "___NAMESPACED_ORG___"
    namespaced_org = namespace_prefix if namespaced_org else ""

    # Handle token %%%NAMESPACE_OR_C%%% for lightning components
    namespace_or_c_token = "%%%NAMESPACE_OR_C%%%"
    namespace_or_c = namespace if managed and namespace else "c"

    # Handle token %%%NAMESPACED_ORG_OR_C%%%
    namespaced_org_or_c_token = "%%%NAMESPACED_ORG_OR_C%%%"
    namespaced_org_or_c = namespace if namespaced_org else "c"

    zip_dest = zipfile.ZipFile(io.BytesIO(), "w", zipfile.ZIP_DEFLATED)

    for name in zip_src.namelist():
        orig_name = str(name)
        content = zip_src.read(name)
        try:
            content = content.decode("utf-8")
        except UnicodeDecodeError:
            # if we cannot decode the content, don't try and replace it.
            pass
        else:
            prev_content = content
            content = content.replace(namespace_token, namespace_prefix)
            if logger and content != prev_content:
                logger.info(
                    '  {}: Replaced %%%NAMESPACE%%% with "{}"'.format(name, namespace)
                )

            prev_content = content
            content = content.replace(namespace_or_c_token, namespace_or_c)
            if logger and content != prev_content:
                logger.info(
                    '  {}: Replaced %%%NAMESPACE_OR_C%%% with "{}"'.format(
                        name, namespace_or_c
                    )
                )

            prev_content = content
            content = content.replace(namespaced_org_token, namespaced_org)
            if logger and content != prev_content:
                logger.info(
                    '  {}: Replaced %%%NAMESPACED_ORG%%% with "{}"'.format(
                        name, namespaced_org
                    )
                )

            prev_content = content
            content = content.replace(namespaced_org_or_c_token, namespaced_org_or_c)
            if logger and content != prev_content:
                logger.info(
                    '  {}: Replaced %%%NAMESPACED_ORG_OR_C%%% with "{}"'.format(
                        name, namespaced_org_or_c
                    )
                )

            content = content.encode("utf-8")

        # Replace namespace token in file name
        name = name.replace(filename_token, namespace_prefix)
        name = name.replace(namespaced_org_file_token, namespaced_org)
        if logger and name != orig_name:
            logger.info("  {}: renamed to {}".format(orig_name, name))
        zip_dest.writestr(name, content)

    return zip_dest
843318
def prefixed_to_namespaced(C, prefixed_name, namespaces):
        
        if ':' not in prefixed_name:
            return prefixed_name
        else:
            prefix, name = prefixed_name.split(':')
            namespace = namespaces[prefix]
            return "{%s}%s" % (namespace, name)
942796
def namespace(self):
        
        if self.prefix is None:
            return Namespace.default
        else:
            return self.resolvePrefix(self.prefix)
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);
  }
}
105096
def method_or_name(namespace, x):
    '''
    
    '''
    if not isinstance(x, str):
        return x

    if hasattr(namespace, x):
        return getattr(namespace, x)

    attrs = [y for y in dir(namespace) if not y.startswith('_')]
    msg = '''"%s" is not available in %s.
These attributes are available: %s.''' % (x, namespace.__name__, attrs)
    raise AttributeError(msg)
747788
def replace_in_file(workspace, src_file_path, from_str, to_str):
  
  from_bytes = from_str.encode('ascii')
  to_bytes = to_str.encode('ascii')
  data = read_file(os.path.join(workspace, src_file_path), binary_mode=True)
  if from_bytes not in data and from_str not in src_file_path:
    return None

  dst_file_path = src_file_path.replace(from_str, to_str)
  safe_file_dump(os.path.join(workspace, dst_file_path),
                 data.replace(from_bytes, to_bytes),
                 mode='wb')
  if src_file_path != dst_file_path:
    os.unlink(os.path.join(workspace, src_file_path))
  return dst_file_path
369452
def add_namespace(self, module):
        
        uri = module.search_one("namespace").arg
        prefix = module.search_one("prefix").arg
        if uri in self.namespaces: return self.namespaces[uri]
        end = 1
        new = prefix
        while new in list(self.namespaces.values()):
            new = "%s%x" % (prefix,end)
            end += 1
        self.namespaces[uri] = new
        self.module_prefixes[module.arg] = new
        for inc in module.search("include"):
            self.module_prefixes[inc.arg] = new
        return new
253123
private function apply_namespace_filters( $namespace, $class, $dir )
    {
        foreach( $this->filters[$namespace] as $filter )
        {
            if( is_callable( $filter ) )
            {
                $file = call_user_func_array( $filter, array( $class, $namespace, $dir ) );
                if ( file_exists( $file ) ) 
                {
                    return $file;
                }
            }
        }
    }
64181
def expand_namespace(nsmap, string):
    
    for ns in nsmap:
        if isinstance(string, str) and isinstance(ns, str) and string.startswith(ns+":"):
            return string.replace(ns+":", nsmap[ns])
    return string
995865
def lookup(self, plain_src_ns):
        
        # Ignore the namespace if it is excluded.
        if plain_src_ns in self._ex_namespace_set:
            return None
        # Include all namespaces if there are no included namespaces.
        if not self._regex_map and not self._plain:
            return Namespace(
                dest_name=plain_src_ns,
                source_name=plain_src_ns,
                include_fields=self._include_fields,
                exclude_fields=self._exclude_fields,
            )
        # First, search for the namespace in the plain namespaces.
        try:
            return self._plain[plain_src_ns]
        except KeyError:
            # Search for the namespace in the wildcard namespaces.
            for regex, namespace in self._regex_map:
                new_name = match_replace_regex(regex, plain_src_ns, namespace.dest_name)
                if not new_name:
                    continue
                # Save the new target Namespace in the plain namespaces so
                # future lookups are fast.
                new_namespace = namespace.with_options(
                    dest_name=new_name, source_name=plain_src_ns
                )
                self._add_plain_namespace(new_namespace)
                return new_namespace

        # Save the not included namespace to the excluded namespaces so
        # that future lookups of the same namespace are fast.
        self._ex_namespace_set.add(plain_src_ns)
        return None
1241041
def add_namespaces(metadata, namespaces):
    # type: (Mapping[Text, Any], MutableMapping[Text, Text]) -> None
    """"""
    for key, value in metadata.items():
        if key not in namespaces:
            namespaces[key] = value
        elif namespaces[key] != value:
            raise validate.ValidationException(
                "Namespace prefix '{}' has conflicting definitions '{}'"
                " and '{}'.".format(key, namespaces[key], value))
434404
def _fixNS(self, namespace):
        
        if namespace == OPENID_NS:
            if self._openid_ns_uri is None:
                raise UndefinedOpenIDNamespace('OpenID namespace not set')
            else:
                namespace = self._openid_ns_uri

        if namespace != BARE_NS and type(namespace) not in [str, unicode]:
            raise TypeError(
                "Namespace must be BARE_NS, OPENID_NS or a string. got %r"
                % (namespace,))

        if namespace != BARE_NS and ':' not in namespace:
            fmt = 'OpenID 2.0 namespace identifiers SHOULD be URIs. Got %r'
            warnings.warn(fmt % (namespace,), DeprecationWarning)

            if namespace == 'sreg':
                fmt = 'Using %r instead of "sreg" as namespace'
                warnings.warn(fmt % (SREG_URI,), DeprecationWarning,)
                return SREG_URI

        return namespace
346142
def namespace(self, prefix=None):
        
        ns = self.schema.tns
        if ns[0] is None:
            ns = (prefix, ns[1])
        return ns
616941
function update_srcmap_namespace(code, options) {
    let srcNode = srcmap.getNodeFromCode(code);
    return srcmap.getCodeFromNode(srcNode, options.srcmapRename, { multiline: options.multiline });
}
174185
def namespace_bindings_from_defs(ns_defs)
      (ns_defs||[]).reduce({}) do |h,ns_def|
        h[ns_def.prefix||""] = ns_def.href
        h
      end
    end
210197
def apply_namespace(qname, apply_prefix, apply_uri)
      local_part, prefix, uri = qname
      
      if !prefix
        prefix = apply_prefix
        uri = apply_uri
      end

      [local_part, prefix, uri].compact
    end
1171414
def remove_namespace(self, ns_uri):
        """"""
        if not self.contains_namespace(ns_uri):
            return

        ni = self.__ns_uri_map.pop(ns_uri)
        for prefix in ni.prefixes:
            del self.__prefix_map[prefix]