我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用bson._make_c_string()。
def insert(collection_name, docs, check_keys, safe, last_error_args, continue_on_error, opts): """Get an **insert** message.""" options = 0 if continue_on_error: options += 1 data = struct.pack("<i", options) data += bson._make_c_string(collection_name) encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs] if not encoded: raise InvalidOperation("cannot do an empty bulk insert") max_bson_size = max(map(len, encoded)) data += _EMPTY.join(encoded) if safe: (_, insert_message) = __pack_message(2002, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, insert_message + error_message, max_bson_size) else: (request_id, insert_message) = __pack_message(2002, data) return (request_id, insert_message, max_bson_size)
def update(collection_name, upsert, multi, spec, doc, safe, last_error_args, check_keys, opts): """Get an **update** message. """ options = 0 if upsert: options += 1 if multi: options += 2 data = _ZERO_32 data += bson._make_c_string(collection_name) data += struct.pack("<i", options) data += bson.BSON.encode(spec, False, opts) encoded = bson.BSON.encode(doc, check_keys, opts) data += encoded if safe: (_, update_message) = __pack_message(2001, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, update_message + error_message, len(encoded)) else: (request_id, update_message) = __pack_message(2001, data) return (request_id, update_message, len(encoded))
def query(options, collection_name, num_to_skip, num_to_return, query, field_selector, opts, check_keys=False): """Get a **query** message. """ data = struct.pack("<I", options) data += bson._make_c_string(collection_name) data += struct.pack("<i", num_to_skip) data += struct.pack("<i", num_to_return) encoded = bson.BSON.encode(query, check_keys, opts) data += encoded max_bson_size = len(encoded) if field_selector is not None: encoded = bson.BSON.encode(field_selector, False, opts) data += encoded max_bson_size = max(len(encoded), max_bson_size) (request_id, query_message) = __pack_message(2004, data) return (request_id, query_message, max_bson_size)
def delete(collection_name, spec, safe, last_error_args, opts, flags=0): """Get a **delete** message. `opts` is a CodecOptions. `flags` is a bit vector that may contain the SingleRemove flag or not: http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-delete """ data = _ZERO_32 data += bson._make_c_string(collection_name) data += struct.pack("<I", flags) encoded = bson.BSON.encode(spec, False, opts) data += encoded if safe: (_, remove_message) = __pack_message(2006, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, remove_message + error_message, len(encoded)) else: (request_id, remove_message) = __pack_message(2006, data) return (request_id, remove_message, len(encoded))
def update(collection_name, upsert, multi, spec, doc, safe, last_error_args, check_keys, uuid_subtype): """Get an **update** message. """ options = 0 if upsert: options += 1 if multi: options += 2 data = _ZERO_32 data += bson._make_c_string(collection_name) data += struct.pack("<i", options) data += bson.BSON.encode(spec, False, uuid_subtype) encoded = bson.BSON.encode(doc, check_keys, uuid_subtype) data += encoded if safe: (_, update_message) = __pack_message(2001, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, update_message + error_message, len(encoded)) else: (request_id, update_message) = __pack_message(2001, data) return (request_id, update_message, len(encoded))
def query(options, collection_name, num_to_skip, num_to_return, query, field_selector=None, uuid_subtype=OLD_UUID_SUBTYPE): """Get a **query** message. """ data = struct.pack("<I", options) data += bson._make_c_string(collection_name) data += struct.pack("<i", num_to_skip) data += struct.pack("<i", num_to_return) encoded = bson.BSON.encode(query, False, uuid_subtype) data += encoded max_bson_size = len(encoded) if field_selector is not None: encoded = bson.BSON.encode(field_selector, False, uuid_subtype) data += encoded max_bson_size = max(len(encoded), max_bson_size) (request_id, query_message) = __pack_message(2004, data) return (request_id, query_message, max_bson_size)
def delete(collection_name, spec, safe, last_error_args, uuid_subtype, options=0): """Get a **delete** message. """ data = _ZERO_32 data += bson._make_c_string(collection_name) data += struct.pack("<I", options) encoded = bson.BSON.encode(spec, False, uuid_subtype) data += encoded if safe: (_, remove_message) = __pack_message(2006, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, remove_message + error_message, len(encoded)) else: (request_id, remove_message) = __pack_message(2006, data) return (request_id, remove_message, len(encoded))
def get_more(collection_name, num_to_return, cursor_id): """Get a **getMore** message. """ data = _ZERO_32 data += bson._make_c_string(collection_name) data += struct.pack("<i", num_to_return) data += struct.pack("<q", cursor_id) return __pack_message(2005, data)
def insert(collection_name, docs, check_keys, safe, last_error_args, continue_on_error, uuid_subtype): """Get an **insert** message. .. note:: As of PyMongo 2.6, this function is no longer used. It is being kept (with tests) for backwards compatibility with 3rd party libraries that may currently be using it, but will likely be removed in a future release. """ options = 0 if continue_on_error: options += 1 data = struct.pack("<i", options) data += bson._make_c_string(collection_name) encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs] if not encoded: raise InvalidOperation("cannot do an empty bulk insert") max_bson_size = max(map(len, encoded)) data += _EMPTY.join(encoded) if safe: (_, insert_message) = __pack_message(2002, data) (request_id, error_message, _) = __last_error(collection_name, last_error_args) return (request_id, insert_message + error_message, max_bson_size) else: (request_id, insert_message) = __pack_message(2002, data) return (request_id, insert_message, max_bson_size)