Insert the namespace file at the given location to the cache.

        :raises: pybel.resources.exc.ResourceError
546712
def get_or_create_annotation(self, url: str) -> Namespace:
        
        result = self.get_namespace_by_url(url)

        if result is not None:
            return result

        t = time.time()

        bel_resource = get_bel_resource(url)

        result = Namespace(
            url=url,
            is_annotation=True,
            **_get_annotation_insert_values(bel_resource)
        )
        result.entries = [
            NamespaceEntry(name=name, identifier=label)
            for name, label in bel_resource['Values'].items()
            if name
        ]

        self.session.add(result)
        self.session.commit()

        log.info('inserted annotation: %s (%d terms in %.2f seconds)', url, len(bel_resource['Values']),
                 time.time() - t)

        return result
1356504
def skip_storing_namespace(self, namespace: Optional[str]) -> bool:
        
        return (
            namespace is not None and
            namespace in self.namespace_url and
            self.namespace_url[namespace] in self.uncached_namespaces
        )
788301
def insert(self, context):
	
		
		
		script_path = context.resolve(self.__script_path)
		buf = io.StringIO()
		self.__preprocess(script_path, buf)
		buf.seek(0)
		self.__conn.execute(buf.read())
1269630
function (namespaces) {
    _.forEach(namespaces, function (level, namespace) {
      cache.add(namespace, level);
    });
    return this;
  }
200928
public void addNamespace(String prefix, String namespaceURI) {
        if (prefix == null || namespaceURI == null) {
            throw new IllegalArgumentException("null arguments not allowed.");
        }
        if (namespaceURI.equals(XMLConstants.XML_NS_URI)) {
            throw new IllegalArgumentException("Adding a new namespace for " +
                XMLConstants.XML_NS_URI + "not allowed.");
        } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
            throw new IllegalArgumentException("Adding a new namespace for " +
                XMLConstants.XMLNS_ATTRIBUTE_NS_URI + "not allowed.");
        }
        prefix2ns.put(prefix, namespaceURI);
    }
188411
def addAlias(self, namespace_uri, desired_alias, implicit=False):
        
        if isinstance(namespace_uri, bytes):
            namespace_uri = str(namespace_uri, encoding="utf-8")
        # Check that desired_alias is not an openid protocol field as
        # per the spec.
        assert desired_alias not in OPENID_PROTOCOL_FIELDS, \
               "%r is not an allowed namespace alias" % (desired_alias,)

        # Check that desired_alias does not contain a period as per
        # the spec.
        if isinstance(desired_alias, str):
            assert '.' not in desired_alias, \
                   "%r must not contain a dot" % (desired_alias,)

        # Check that there is not a namespace already defined for
        # the desired alias
        current_namespace_uri = self.alias_to_namespace.get(desired_alias)
        if (current_namespace_uri is not None and
                current_namespace_uri != namespace_uri):

            fmt = ('Cannot map %r to alias %r. '
                   '%r is already mapped to alias %r')

            msg = fmt % (namespace_uri, desired_alias, current_namespace_uri,
                         desired_alias)
            raise KeyError(msg)

        # Check that there is not already a (different) alias for
        # this namespace URI
        alias = self.namespace_to_alias.get(namespace_uri)
        if alias is not None and alias != desired_alias:
            fmt = ('Cannot map %r to alias %r. '
                   'It is already mapped to alias %r')
            raise KeyError(fmt % (namespace_uri, desired_alias, alias))

        assert (desired_alias == NULL_NAMESPACE or
                type(desired_alias) in [str, str]), repr(desired_alias)
        assert namespace_uri not in self.implicit_namespaces
        self.alias_to_namespace[desired_alias] = namespace_uri
        self.namespace_to_alias[namespace_uri] = desired_alias
        if implicit:
            self.implicit_namespaces.append(namespace_uri)
        return desired_alias
460085
def set(self, prefix, url, obj):
        
        if not self.cache_dir:
            return

        filename = self._get_cache_file(prefix, url)

        try:
            os.makedirs(os.path.join(self.cache_dir, prefix))
        except OSError:
            pass

        with open(filename, 'wb') as file:
            pickle.dump(obj, file)
1279097
def insert(self, crc, toc):
        
        if self._rw_cache:
            try:
                filename = '%s/%08X.json' % (self._rw_cache, crc)
                cache = open(filename, 'w')
                cache.write(json.dumps(toc, indent=2,
                                       default=self._encoder))
                cache.close()
                logger.info('Saved cache to [%s]', filename)
                self._cache_files += [filename]
            except Exception as exp:
                logger.warning('Could not save cache to file [%s]: %s',
                               filename, str(exp))
        else:
            logger.warning('Could not save cache, no writable directory')
228551
def add(self, root):
        
        node = Element('import', ns=self.xsdns)
        node.set('namespace', self.ns)
        if self.location is not None:
            node.set('schemaLocation', self.location)
        log.debug('%s inserted', node)
        root.insert(node)
1117297
def _add_namespaces(self):
        
        self.doc.add_namespace(NIDM)
        self.doc.add_namespace(NIIRI)
        self.doc.add_namespace(CRYPTO)
        self.doc.add_namespace(DCT)
        self.doc.add_namespace(DC)
        self.doc.add_namespace(NFO)
        self.doc.add_namespace(OBO)
        self.doc.add_namespace(SCR)
        self.doc.add_namespace(NIF)
1304214
def add_resource(self, name, file_path, ind_obj):
        """"""
        new_resource = Resource(name=name, individual=ind_obj, path=file_path)
        self.session.add(new_resource)
        self.save()
        return new_resource
368341
private void load() throws IOException
   {
      if (PrivilegedFileHelper.exists(storage))
      {
         InputStream in = PrivilegedFileHelper.fileInputStream(storage);
         try
         {
            Properties props = new Properties();
            log.debug("loading namespace mappings...");
            props.load(in);

            // read mappings from properties
            Iterator<Object> iter = props.keySet().iterator();
            while (iter.hasNext())
            {
               String prefix = (String)iter.next();
               String uri = props.getProperty(prefix);
               log.debug(prefix + " -> " + uri);
               prefixToURI.put(prefix, uri);
               uriToPrefix.put(uri, prefix);
            }
            prefixCount = props.size();
            log.debug("namespace mappings loaded.");
         }
         finally
         {
            in.close();
         }
      }
   }
41066
def put(self, namespacePrefix):
        """"""
        self.reqparse.add_argument('name', type=str, required=True)
        self.reqparse.add_argument('sortOrder', type=int, required=True)
        args = self.reqparse.parse_args()

        ns = db.ConfigNamespace.find_one(ConfigNamespace.namespace_prefix == namespacePrefix)
        if not ns:
            return self.make_response('No such namespace: {}'.format(namespacePrefix), HTTP.NOT_FOUND)

        ns.name = args['name']
        ns.sort_order = args['sortOrder']
        db.session.add(ns)
        db.session.commit()

        self.dbconfig.reload_data()
        auditlog(event='configNamespace.update', actor=session['user'].username, data=args)

        return self.make_response('Namespace updated')
982307
private void addToCache(BundleInfo bInfo) {
        List<Resource> info = _cacheBySymbolicName.get(bInfo.symbolicName);
        if (info == null) {
            info = new ArrayList<Resource>();
            info.add(bInfo);
        }

        info = _cacheBySymbolicName.putIfAbsent(bInfo.symbolicName, info);

        if (info != null) {
            synchronized (info) {
                info.add(bInfo);
            }
        }

        _bundleLocations.add(bInfo.file);
    }
898844
public void registerCachedFile(String filePath, String name) throws IOException {
		if (!this.cacheFile.containsKey(name)) {
			try {
				URI u = new URI(filePath);
				if (!u.getPath().startsWith("/")) {
					u = new URI(new File(filePath).getAbsolutePath());
				}
				FileSystem fs = FileSystem.get(u);
				if (fs.exists(new Path(u.getPath()))) {
					this.cacheFile.put(name, u.toString());
				} else {
					throw new RuntimeException("File " + u.toString() + " doesn't exist.");
				}
			} catch (URISyntaxException ex) {
				throw new RuntimeException("Invalid path: " + filePath, ex);
			}
		} else {
			throw new RuntimeException("cache file " + name + "already exists!");
		}
	}
390300
def cache_add(self, resource_url, cache_id):
        
        # Add entry to cache index
        self.cache[resource_url] = cache_id
        # Write cache index content to database file
        with open(self.db_file, 'w') as f:
            for resource in self.cache:
                f.write(resource + '\t' + self.cache[resource] + '\n')
23469
public void addNamespaces(Map<String, String> namespaceMap) throws RepositoryException
   {
      if (!started)
      {
         log.warn("Unable save namespaces in to the storage. Storage not initialized");
         return;
      }

      PlainChangesLog changesLog = new PlainChangesLogImpl();
      for (Map.Entry<String, String> entry : namespaceMap.entrySet())
      {
         String prefix = entry.getKey();
         String uri = entry.getValue();

         if (prefix != null)
         {
            if (log.isDebugEnabled())
               log.debug("Namespace " + uri + ":" + prefix);
            internallAdd(changesLog, prefix, uri);
         }
      }
      dataManager.save(new TransactionChangesLog(changesLog));

   }