Embed metadata using blockcypher's API.

    This is not embedded into the bitcoin (or other) blockchain,
    and is only stored on blockcypher's servers.
331866
def put_metadata(metadata_dict, address=None, tx_hash=None, block_hash=None, api_key=None, private=True, coin_symbol='btc'):
    '''
    
    '''
    assert is_valid_coin_symbol(coin_symbol), coin_symbol
    assert api_key
    assert metadata_dict and isinstance(metadata_dict, dict), metadata_dict

    kwarg = get_valid_metadata_identifier(
        coin_symbol=coin_symbol,
        address=address,
        tx_hash=tx_hash,
        block_hash=block_hash,
        )

    url = make_url(coin_symbol, meta=True, **kwarg)

    params = {'token': api_key}
    if private:
        params['private'] = 'true'

    r = requests.put(url, json=metadata_dict, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r, allow_204=True)
804513
def embedgroupdata(extract_func, fname, debug):
    """"""
    
    astr = _readfname(fname)
    
    # fname is exhausted by the above read
    # reconstitute fname as a StringIO
    fname = StringIO(astr)

    try:
        astr = astr.decode('ISO-8859-2')
    except Exception as e:
        pass # for python 3
    glist = iddgroups.iddtxt2grouplist(astr)
    
    
    blocklst, commlst, commdct = extract_func(fname)
    # add group information to commlst and commdct
    # glist = getglist(fname)
    commlst = iddgroups.group2commlst(commlst, glist)
    commdct = iddgroups.group2commdct(commdct, glist)
    return blocklst, commlst, commdct
908351
@Override
    public void endMetaData(MetaData metadata)
    {
        this.builder.addBlock(new MetaDataBlock(this.builder.endBlockList(), metadata));
    }
890684
def metadata(dataset, node, entityids, extended=False, api_key=None):
    
    api_key = _get_api_key(api_key)

    url = '{}/metadata'.format(USGS_API)
    payload = {
        "jsonRequest": payloads.metadata(dataset, node, entityids, api_key=api_key)
    }
    r = requests.post(url, payload)
    response = r.json()

    _check_for_usgs_error(response)

    if extended:
        metadata_urls = map(_get_metadata_url, response['data'])
        results = _async_requests(metadata_urls)
        data = map(lambda idx: _get_extended(response['data'][idx], results[idx]), range(len(response['data'])))

    return response
684255
def _serialize(self, uri, node):
        
        meta = self._decode_meta(node['meta'], is_published=bool(node['is_published']))
        return {
            'uri': uri.clone(ext=node['plugin'], version=node['version']),
            'content': node['content'],
            'meta': meta
        }
1082765
def infuse_metadata(graph_def, info):
  
  temp_graph = tf.Graph()
  with temp_graph.as_default():
    tf.constant(json.dumps(info, cls=NumpyJSONEncoder), name=metadata_node_name)
  meta_node = temp_graph.as_graph_def().node[0]
  graph_def.node.extend([meta_node])
176463
def _finalize_block_blob(self, ud, metadata):
        # type: (Uploader, blobxfer.models.upload.Descriptor, dict) -> None
        
        if not ud.entity.is_encrypted and ud.must_compute_md5:
            digest = blobxfer.util.base64_encode_as_string(ud.md5.digest())
        else:
            digest = None
        blobxfer.operations.azure.blob.block.put_block_list(
            ud.entity, ud.last_block_num, digest, metadata)
        if blobxfer.util.is_not_empty(ud.entity.replica_targets):
            for ase in ud.entity.replica_targets:
                blobxfer.operations.azure.blob.block.put_block_list(
                    ase, ud.last_block_num, digest, metadata)
897725
def set_metadata_for_node(self, node, metadata):
        
        return self.manager.set_metadata(self, metadata, node=node)
369878
def raw(self, tag, raw, metadata):
        
        raw = base64.b64encode(raw)
        return {
            'type': 'raw',
            'tag': tag,
            'raw': raw,
            'metadata': metadata
        }
1338695
def encode_metadata_request(cls, client_id, correlation_id, topics=None,
                                payloads=None):
        
        if payloads is None:
            topics = [] if topics is None else topics
        else:
            topics = payloads

        message = []
        message.append(cls._encode_message_header(client_id, correlation_id,
                                                  KafkaProtocol.METADATA_KEY))

        message.append(struct.pack('>i', len(topics)))

        for topic in topics:
            message.append(struct.pack('>h%ds' % len(topic), len(topic), topic))

        msg = b''.join(message)
        return write_int_string(msg)
1290512
def _make_meta(self, tracker_url, root_name, private, progress):
        
        # Calculate piece size
        if self._fifo:
            # TODO we need to add a (command line) param, probably for total data size
            # for now, always 1MB
            piece_size_exp = 20
        else:
            total_size = self._calc_size()
            if total_size:
                piece_size_exp = int(math.log(total_size) / math.log(2)) - 9
            else:
                piece_size_exp = 0

        piece_size_exp = min(max(15, piece_size_exp), 24)
        piece_size = 2 ** piece_size_exp

        # Build info hash
        info, totalhashed = self._make_info(piece_size, progress, self.walk() if self._fifo else sorted(self.walk()))

        # Enforce unique hash per tracker
        info["x_cross_seed"] = hashlib.md5(tracker_url).hexdigest()

        # Set private flag
        if private:
            info["private"] = 1

        # Freely chosen root name (default is basename of the data path)
        if root_name:
            info["name"] = root_name

        # Torrent metadata
        meta = {
            "info": info,
            "announce": tracker_url.strip(),
        }

        #XXX meta["encoding"] = "UTF-8"

        # Return validated meta dict
        return check_meta(meta), totalhashed
785963
def raw(self) -> str:
        
        doc = """Version: {0}
Type: Peer
Currency: {1}
PublicKey: {2}
Block: {3}
Endpoints:
""".format(self.version, self.currency, self.pubkey, self.blockUID)

        for _endpoint in self.endpoints:
            doc += "{0}\n".format(_endpoint.inline())

        return doc
413311
function MetaData() {

    // the key for the storing
    this.key = null;
    // data to store
    this.value = null;
    // temporary filename for the cached file because filenames cannot represend urls completely
    this.filename = null;
    // expirydate of the entry
    this.expires = null;
    // size of the current entry
    this.size = null;
}
104148
def generate_metadata(self):
        # type: (Descriptor) -> dict
        
        genmeta = {}
        encmeta = {}
        # page align md5
        if (self.must_compute_md5 and
                self._ase.mode == blobxfer.models.azure.StorageModes.Page):
            aligned = blobxfer.util.page_align_content_length(self._offset)
            diff = aligned - self._offset
            if diff > 0:
                with self._hasher_lock:
                    self.md5.update(b'\0' * diff)
        # generate encryption metadata
        if self._ase.is_encrypted:
            if self.must_compute_md5:
                md5digest = blobxfer.util.base64_encode_as_string(
                    self.md5.digest())
            else:
                md5digest = None
            if self.hmac is not None:
                hmacdigest = blobxfer.util.base64_encode_as_string(
                    self.hmac.digest())
            else:
                hmacdigest = None
            encmeta = self._ase.encryption_metadata.convert_to_json_with_mac(
                md5digest, hmacdigest)
        # generate file attribute metadata
        if self._store_file_attr and not self.local_path.use_stdin:
            merged = blobxfer.models.metadata.generate_fileattr_metadata(
                self.local_path, genmeta)
            if merged is not None:
                genmeta = merged
        # generate vectored io metadata
        if self.local_path.view.mode == VectoredIoDistributionMode.Stripe:
            merged = blobxfer.models.metadata.\
                generate_vectored_io_stripe_metadata(self.local_path, genmeta)
            if merged is not None:
                genmeta = merged
        if len(encmeta) > 0:
            metadata = encmeta
        else:
            metadata = {}
        if len(genmeta) > 0:
            metadata[blobxfer.models.metadata.JSON_KEY_BLOBXFER_METADATA] = \
                json.dumps(genmeta, ensure_ascii=False, sort_keys=True)
        if len(metadata) == 0:
            return None
        return metadata
8843
def build_result_metadata(self, data=None, args=None):
        
        data = data if data else self._build_result_metainfo(args)
        if data.get("build_branch"):
            self.build_branch = data.get("build_branch")
        if data.get("buildcommit"):
            self.buildcommit = data.get("buildcommit")
        if data.get("build_git_url"):
            self.build_git_url = data.get("build_git_url")
        if data.get("build_url"):
            self.build_url = data.get("build_url")
        if data.get("campaign"):
            self.campaign = data.get("campaign")
        if data.get("job_id"):
            self.job_id = data.get("job_id")
        if data.get("toolchain"):
            self.toolchain = data.get("toolchain")
        if data.get("build_date"):
            self.build_date = data.get("build_date")
711404
@Override
    public PutObjectResult putObjectSecurely(PutObjectRequest req) {
        // TODO: consider cloning req before proceeding further to reduce side
        // effects
        appendUserAgent(req, USER_AGENT);
        return cryptoConfig.getStorageMode() == InstructionFile
               ? putObjectUsingInstructionFile(req)
               : putObjectUsingMetadata(req);
    }
467260
def to_json(self, include_id: bool = False):
        
        result = {
            METADATA_NAME: self.name,
            METADATA_VERSION: self.version,
        }

        if self.created:
            result['created'] = str(self.created)

        if include_id:
            result['id'] = self.id

        if self.authors:
            result[METADATA_AUTHORS] = self.authors

        if self.contact:
            result[METADATA_CONTACT] = self.contact

        if self.description:
            result[METADATA_DESCRIPTION] = self.description

        if self.copyright:
            result[METADATA_COPYRIGHT] = self.copyright

        if self.disclaimer:
            result[METADATA_DISCLAIMER] = self.disclaimer

        if self.licenses:
            result[METADATA_LICENSES] = self.licenses

        return result