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


Python bson.dumps方法代碼示例

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


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

示例1: test_json_parser

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def test_json_parser(self):
        factory = RequestFactory()
        with self.subTest(src_text='mixed'):
            data = {
                'name': 'John Doe',
                'mail': 'example.gmail.com',
                'themes': ['1', '2', '4'],
            }
            request = factory.post(
                '/some/url/',
                data=json.dumps(data),
                content_type='application/json',
            )
            p = djburger.parsers.JSON()
            parsed_data = p(request)
            self.assertEqual(parsed_data, data) 
開發者ID:orsinium-archive,項目名稱:djburger,代碼行數:18,代碼來源:parsers.py

示例2: test_bson_parser

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def test_bson_parser(self):
        factory = RequestFactory()
        with self.subTest(src_text='mixed'):
            data = {
                'name': 'John Doe',
                'mail': 'example.gmail.com',
                'themes': ['1', '2', '4'],
            }
            request = factory.post(
                '/some/url/',
                data=bson.dumps(data),
                content_type='application/json',
            )
            p = djburger.parsers.BSON()
            parsed_data = p(request)
            self.assertEqual(parsed_data, data) 
開發者ID:orsinium-archive,項目名稱:djburger,代碼行數:18,代碼來源:parsers.py

示例3: load_bson

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def load_bson():
        global BSON
        if BSON is None:
            try:
                from pymongo.bson import BSON
            except ImportError:
                from bson import dumps
                class BSON(object):
                    @staticmethod
                    def encode(obj, *args, **kwargs):
                        return dumps(obj)


    #-------------------------------------------------------------------------- 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:16,代碼來源:bson.py

示例4: __init__

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def __init__(self, custom_codec_implementation=None):
        if custom_codec_implementation is not None:
            self._loads = custom_codec_implementation.loads
            self._dumps = custom_codec_implementation.dumps
        else:
            # Use implementation from pymongo or from pybson
            import bson
            if hasattr(bson, 'BSON'):
                # pymongo
                self._loads = lambda raw: bson.BSON.decode(bson.BSON(raw))
                self._dumps = lambda msg: bytes(bson.BSON.encode(msg))
            else:
                # pybson
                self._loads = bson.loads
                self._dumps = bson.dumps 
開發者ID:seprich,項目名稱:py-bson-rpc,代碼行數:17,代碼來源:socket_queue.py

示例5: dumps

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def dumps(self, msg):
        try:
            return self._dumps(msg)
        except Exception as e:
            raise EncodingError(e) 
開發者ID:seprich,項目名稱:py-bson-rpc,代碼行數:7,代碼來源:socket_queue.py

示例6: put

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def put(self, item):
        '''
        Put item to queue -> codec -> socket.

        :param item: Message object.
        :type item: dict, list or None
        '''
        if self._closed:
            raise BsonRpcError('Attempt to put items to closed queue.')
        msg_bytes = self.codec.into_frame(self.codec.dumps(item))
        with self._lock:
            self.socket.sendall(msg_bytes) 
開發者ID:seprich,項目名稱:py-bson-rpc,代碼行數:14,代碼來源:socket_queue.py

示例7: __init__

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def __init__(self, extractor, framer, custom_codec_implementation=None):
        self._extractor = extractor
        self._framer = framer
        if custom_codec_implementation is not None:
            self._loads = custom_codec_implementation.loads
            self._dumps = custom_codec_implementation.dumps
        else:
            import json
            self._loads = json.loads
            self._dumps = json.dumps 
開發者ID:seprich,項目名稱:py-bson-rpc,代碼行數:12,代碼來源:socket_queue.py

示例8: test_initialize_file

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def test_initialize_file(self):
        shard_set = ShardSet(self.interface)
        shard_set.config.shards_file = 'shards file'

        with patch("builtins.open", mock_open()) as mock_file:
            shard_set.initialize_file()
            mock_file.assert_called_with('shards file', 'wb')
            mock_file().write.called_with(bson.dumps({})) 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:10,代碼來源:test_shard_set.py

示例9: _ensure_shards

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def _ensure_shards(self, shards_expected: bool = True) -> None:
        if not self._shards_loaded:
            bdata = None

            # If the shards dont exist at the place where they
            # are expected to by, try to restore them with the externally
            # configured getPersistedShards command.
            if not os.path.exists(self.config.shards_file):
                try:
                    os.system(self.config.commands['getPersistedShards'])
                except TypeError:
                    pass

            # If for some reason the persistence layer failed to  create the
            # the shards file, we assume that we just need to initialize
            # it as an empty bson object.
            if not os.path.exists(self.config.shards_file):
                with open(self.config.shards_file, 'wb') as f:
                    f.write(bson.dumps({}))

            with open(self.config.shards_file, 'rb') as f:
                bdata = bson.loads(f.read())

            for name, shard_bytes in bdata.items():
                self.shards[name] = Shard(
                    name, shamir_share.mnemonic_from_bytes(shard_bytes))

            self._shards_loaded = True

        if len(self.shards) == 0 and shards_expected:
            raise HermitError("No shards found.  Create some by entering 'shards' mode.") 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:33,代碼來源:shard_set.py

示例10: initialize_file

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def initialize_file(self) -> None:
        if self.interface.confirm_initialize_file():
            with open(self.config.shards_file, 'wb') as f:
                f.write(bson.dumps({})) 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:6,代碼來源:shard_set.py

示例11: to_bytes

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def to_bytes(self):
        data = {name: shard.to_bytes()
                for (name, shard) in self.shards.items()}
        return bson.dumps(data) 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:6,代碼來源:shard_set.py

示例12: to_qr_bson

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def to_qr_bson(self) -> bytes:
        """Serialize this shard as BSON, suitable for a QR code"""
        return bson.dumps({self.name: self.to_bytes()}) 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:5,代碼來源:shard.py

示例13: fetch

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def fetch():
    # Hit local flask server
    conn = HTTPConnection(fetcher_service, 8888)
    options = []
    for conf in fetch_options.values():
        options.append(conf["key"] + "=" + str(conf["value"]).lower())
    params = bson.dumps({
        "options": options
    })
    conn.request("POST", "/?url=" + url_to_fetch, params)
    response = conn.getresponse()
    print("Stats:")
    print(response.read().decode())
    print() 
開發者ID:InsecurityAsso,項目名稱:inshack-2018,代碼行數:16,代碼來源:wrapper.py

示例14: __init__

# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dumps [as 別名]
def __init__(self, flat=True, **kwargs):
        if not _yaml:
            raise ImportError('BSON is not installed yet')
        self.http_kwargs = {}
        super(BSON, self).__init__(
            renderer=_bson.dumps,
            content_name='obj',
            flat=flat,
            **kwargs) 
開發者ID:orsinium-archive,項目名稱:djburger,代碼行數:11,代碼來源:renderers.py


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