當前位置: 首頁>>代碼示例>>Python>>正文


Python bson.Binary方法代碼示例

本文整理匯總了Python中bson.Binary方法的典型用法代碼示例。如果您正苦於以下問題:Python bson.Binary方法的具體用法?Python bson.Binary怎麽用?Python bson.Binary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bson的用法示例。


在下文中一共展示了bson.Binary方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: from_artifact

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def from_artifact(cls, artifact):
        '''Upsert logic to generate an ArtifactReference object from an artifact'''
        obj = cls.query.get(_id=artifact.index_id())
        if obj is not None:
            return obj
        try:
            obj = cls(
                _id=artifact.index_id(),
                artifact_reference=dict(
                    cls=bson.Binary(dumps(artifact.__class__)),
                    project_id=artifact.app_config.project_id,
                    app_config_id=artifact.app_config._id,
                    artifact_id=artifact._id))
            session(obj).flush(obj)
            return obj
        except pymongo.errors.DuplicateKeyError:  # pragma no cover
            session(obj).expunge(obj)
            return cls.query.get(_id=artifact.index_id()) 
開發者ID:apache,項目名稱:allura,代碼行數:20,代碼來源:index.py

示例2: checksum

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def checksum(self, from_idx, to_idx):
        if self._checksum is None:
            self._lazy_init()
            total_sha = None
            for chunk_bytes, dtype in self.generator_bytes(from_idx=from_idx, to_idx=to_idx):
                # TODO: what about compress_array here in batches?
                compressed_chunk = compress(chunk_bytes)
                total_sha = incremental_checksum(compressed_chunk, curr_sha=total_sha, is_bytes=True)
            self._checksum = Binary(total_sha.digest())
        return self._checksum 
開發者ID:man-group,項目名稱:arctic,代碼行數:12,代碼來源:incremental.py

示例3: checksum

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def checksum(symbol, doc):
    """
    Checksum the passed in dictionary
    """
    sha = hashlib.sha1()
    sha.update(symbol.encode('ascii'))
    for k in sorted(iter(doc.keys()), reverse=True):
        v = doc[k]
        if isinstance(v, six.binary_type):
            sha.update(doc[k])
        else:
            sha.update(str(doc[k]).encode('ascii'))
    return Binary(sha.digest()) 
開發者ID:man-group,項目名稱:arctic,代碼行數:15,代碼來源:_version_store_utils.py

示例4: get_symbol_alive_shas

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def get_symbol_alive_shas(symbol, versions_coll):
    return set(Binary(x) for x in versions_coll.distinct(FW_POINTERS_REFS_KEY, {'symbol': symbol})) 
開發者ID:man-group,項目名稱:arctic,代碼行數:4,代碼來源:_version_store_utils.py

示例5: _binary_buffers

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def _binary_buffers(self, rec):
        for key in ('buffers', 'result_buffers'):
            if rec.get(key, None):
                rec[key] = map(Binary, rec[key])
        return rec 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:mongodb.py

示例6: to_dict

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def to_dict(self, convert_numpy_arrays_to=None, fields_to_ignore=None, nan_to_none=False,
                use_decimal=False):
        result = {}
        if fields_to_ignore is None:
            fields_to_ignore = tuple()
        for k, v in self.get_fields_data():
            if k in fields_to_ignore:
                continue
            if isinstance(v, Model):
                result[k] = v.to_dict(convert_numpy_arrays_to=convert_numpy_arrays_to,
                                      fields_to_ignore=fields_to_ignore,
                                      nan_to_none=nan_to_none,
                                      use_decimal=use_decimal)
            elif isinstance(v, list):
                result[k] = [el.to_dict(convert_numpy_arrays_to=convert_numpy_arrays_to,
                                        fields_to_ignore=fields_to_ignore,
                                        nan_to_none=nan_to_none,
                                        use_decimal=use_decimal) for el in v]
            elif isinstance(v, np.ndarray) and convert_numpy_arrays_to is not None:
                if convert_numpy_arrays_to == 'list':
                    if use_decimal:
                        result[k] = [decimal.Decimal("%f" % a) if isinstance(a, float) else a for a in v.tolist()]
                    else:
                        result[k] = v.tolist()
                elif convert_numpy_arrays_to == 'bytes':
                    result[k] = bson.Binary(v.tostring())
                else:
                    raise ValueError('convert_numpy_arrays_to must be "list" or "bytes"')
            elif nan_to_none and isinstance(v, float) and not np.isfinite(v):
                result[k] = None
            elif use_decimal and isinstance(v, float):
                result[k] = decimal.Decimal("%f" % v)
            else:
                result[k] = v
        return result 
開發者ID:XENON1T,項目名稱:pax,代碼行數:37,代碼來源:data_model.py

示例7: refresh_commit_repos

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def refresh_commit_repos(all_commit_ids, repo):
    '''Refresh the list of repositories within which a set of commits are
    contained'''
    for oids in utils.chunked_iter(all_commit_ids, QSIZE):
        for ci in CommitDoc.m.find(dict(
                _id={'$in': list(oids)},
                repo_ids={'$ne': repo._id})):
            oid = ci._id
            ci.repo_ids.append(repo._id)
            index_id = 'allura.model.repository.Commit#' + oid
            ref = ArtifactReferenceDoc(dict(
                _id=index_id,
                artifact_reference=dict(
                    cls=bson.Binary(dumps(Commit)),
                    project_id=repo.app.config.project_id,
                    app_config_id=repo.app.config._id,
                    artifact_id=oid),
                references=[]))
            link0 = ShortlinkDoc(dict(
                _id=bson.ObjectId(),
                ref_id=index_id,
                project_id=repo.app.config.project_id,
                app_config_id=repo.app.config._id,
                link=repo.shorthand_for_commit(oid)[1:-1],
                url=repo.url_for_commit(oid)))
            # Always create a link for the full commit ID
            link1 = ShortlinkDoc(dict(
                _id=bson.ObjectId(),
                ref_id=index_id,
                project_id=repo.app.config.project_id,
                app_config_id=repo.app.config._id,
                link=oid,
                url=repo.url_for_commit(oid)))
            ci.m.save(validate=False)
            ref.m.save(validate=False)
            link0.m.save(validate=False)
            link1.m.save(validate=False) 
開發者ID:apache,項目名稱:allura,代碼行數:39,代碼來源:repo_refresh.py

示例8: set_value

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def set_value(self, key, value, expiretime=None):
        self._clear_expired()

        expiration = None
        if expiretime is not None:
            expiration = time.time() + expiretime

        value = pickle.dumps(value)
        self.db.backer_cache.update_one({'_id': self._format_key(key)},
                                        {'$set': {'value': bson.Binary(value),
                                                  'expiration': expiration}},
                                        upsert=True) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:14,代碼來源:mongodb.py

示例9: details

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def details(self, request, system_id):
        """@description-title Get system details
        @description Returns system details -- for example, LLDP and
        ``lshw`` XML dumps.

        Returns a ``{detail_type: xml, ...}`` map, where
        ``detail_type`` is something like "lldp" or "lshw".

        Note that this is returned as BSON and not JSON. This is for
        efficiency, but mainly because JSON can't do binary content without
        applying additional encoding like base-64. The example output below is
        represented in ASCII using ``bsondump example.bson`` and is for
        demonstrative purposes.

        @param (string) "{system_id}" [required=true] The node's system_id.

        @success (http-status-code) "200" 200

        @success (content) "success-content" A BSON object represented here in
        ASCII using ``bsondump example.bson``.
        @success-example "success-content" [exkey=details] placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested node is not found.
        @error-example "not-found"
            Not Found
        """
        node = get_object_or_404(self.model, system_id=system_id)
        probe_details = get_single_probed_details(node)
        probe_details_report = {
            name: None if data is None else bson.Binary(data)
            for name, data in probe_details.items()
        }
        return HttpResponse(
            bson.BSON.encode(probe_details_report),
            # Not sure what media type to use here.
            content_type="application/bson",
        ) 
開發者ID:maas,項目名稱:maas,代碼行數:40,代碼來源:nodes.py

示例10: docify

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def docify(self, df):
        """
        Convert a Pandas DataFrame to SON.

        Parameters
        ----------
        df:  DataFrame
            The Pandas DataFrame to encode
        """
        dtypes = {}
        masks = {}
        lengths = {}
        columns = []
        data = Binary(b'')
        start = 0

        arrays = []
        for c in df:
            try:
                columns.append(str(c))
                arr, mask = self._convert_types(df[c].values)
                dtypes[str(c)] = arr.dtype.str
                if mask is not None:
                    masks[str(c)] = Binary(compress(mask.tostring()))
                arrays.append(arr.tostring())
            except Exception as e:
                typ = infer_dtype(df[c], skipna=False)
                msg = "Column '{}' type is {}".format(str(c), typ)
                logging.warning(msg)
                raise e

        arrays = compress_array(arrays)
        for index, c in enumerate(df):
            d = Binary(arrays[index])
            lengths[str(c)] = (start, start + len(d) - 1)
            start += len(d)
            data += d

        doc = SON({DATA: data, METADATA: {}})
        doc[METADATA] = {COLUMNS: columns,
                         MASK: masks,
                         LENGTHS: lengths,
                         DTYPE: dtypes
                         }

        return doc 
開發者ID:man-group,項目名稱:arctic,代碼行數:48,代碼來源:numpy_arrays.py

示例11: set_value

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import Binary [as 別名]
def set_value(self, key, value, expiretime=None):
        log.debug("[MongoDB %s] Set Key: %s (Expiry: %s) ... " %
                  (self.mongo, key, expiretime))

        _id = {}
        doc = {}

        if self._pickle or key == 'session':
            try:
                value = pickle.dumps(value)
            except:
                log.exception("Failed to pickle value.")
        else:
            value = {
                'stored': value[0],
                'expires': value[1],
                'value': value[2],
                'pickled': False
            }
            try:
                bson.BSON.encode(value)
            except:
                log.warning("Value is not bson serializable, pickling inner value.")
                value['value'] = pickle.dumps(value['value'])
                value['pickled'] = True



        if self._sparse:
            _id = {
                'namespace': self.namespace,
                'key': key
            }

            doc['data'] = bson.Binary(value)
            doc['_id'] = _id
            if expiretime:
                # TODO - What is the datatype of this? it should be instantiated as a datetime instance
                doc['valid_until'] = expiretime
        else:
            _id = self.namespace
            doc['$set'] = {'data.' + key: bson.Binary(value)}
            if expiretime:
                # TODO - What is the datatype of this? it should be instantiated as a datetime instance
                doc['$set']['valid_until'] = expiretime

        log.debug("Upserting Doc '%s' to _id '%s'" % (doc, _id))
        self.mongo.update({"_id": _id}, doc, upsert=True, safe=True) 
開發者ID:ip-tools,項目名稱:patzilla,代碼行數:50,代碼來源:beaker_mongodb.py


注:本文中的bson.Binary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。