当前位置: 首页>>代码示例>>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;未经允许,请勿转载。