コード例 #1
0
ファイル: message.py プロジェクト: chenxu10/price_alert_app
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)
    if check_keys:
        # Temporarily remove $clusterTime to avoid an error from the $-prefix.
        cluster_time = query.pop('$clusterTime', None)
        encoded = bson.BSON.encode(query, True, opts)
        if cluster_time is not None:
            extra = bson._name_value_to_bson(b"$clusterTime\x00", cluster_time,
                                             False, opts)
            encoded = (bson._PACK_INT(len(encoded) + len(extra)) +
                       encoded[4:-1] + extra + b'\x00')
            query['$clusterTime'] = cluster_time
    else:
        encoded = bson.BSON.encode(query, False, 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)
コード例 #2
0
ファイル: message.py プロジェクト: rashed-bishal/IoT
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)
    if check_keys:
        # Temporarily remove $clusterTime to avoid an error from the $-prefix.
        cluster_time = query.pop('$clusterTime', None)
        encoded = bson.BSON.encode(query, True, opts)
        if cluster_time is not None:
            extra = bson._name_value_to_bson(
                b"$clusterTime\x00", cluster_time, False, opts)
            encoded = (
                bson._PACK_INT(len(encoded) + len(extra))
                + encoded[4:-1] + extra + b'\x00')
            query['$clusterTime'] = cluster_time
    else:
        encoded = bson.BSON.encode(query, False, 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)