# Path: cb_util.py
# def tag_user_data(value):
#     '''Adds tags to user data so that it can be redacted later'''
#     return f'<ud>{str(value)}</ud>'


import json
import logging
import re
import socket
import struct
import sys
import time
import snappy  # pylint: disable=import-error
import cb_bin_client
import couchbaseConstants
import pump
    import ctypes
        import ctypes
from typing import Any, Dict, List, Optional, Tuple
from cb_util import tag_user_data
            # get the key for the xattr object
            xattr_key = ''
            while ix + len(xattr_key) < len(xattrs) and xattrs[ix + len(xattr_key)] != 0:
                xattr_key += chr(xattrs[ix + len(xattr_key)])

            # check if the key is txn if it matches create a marker and break
            if xattr_key == 'txn':
                txn_marker = txnMarker(ix, pair_len, xattrs
                                       [ix + len(xattr_key) + 1: pair_len + ix - len(xattr_key) + 2])
                break

            # otherwise skip body and move on to next xattr
            ix += pair_len

        if txn_marker is None:
            return False, val, cas, exp, revid, data_type

        # check if txn is valid JSON if not let the server handle it
        try:
            txn_xattr = json.loads(txn_marker.body.decode())
        except Exception:
            logging.debug('(TXN) txn is invalid json')
            return False, val, cas, exp, revid, data_type

        # get op type from the txn
        if 'op' not in txn_xattr or 'type' not in txn_xattr['op']:
            logging.info('(TXN) Transaction extended attributes is missing required field "op"')
            return False, val, cas, exp, revid, data_type

        if txn_xattr['op']['type'] == 'insert':

# Path: cb_util.py
# def tag_user_data(value):
#     '''Adds tags to user data so that it can be redacted later'''
#     return f'<ud>{str(value)}</ud>'


# Path: pump_mc.py
import json
import logging
import re
import socket
import struct
import sys
import time
import snappy  # pylint: disable=import-error
import cb_bin_client
import couchbaseConstants
import pump
    import ctypes
        import ctypes
from typing import Any, Dict, List, Optional, Tuple
from cb_util import tag_user_data

            # get the key for the xattr object
            xattr_key = ''
            while ix + len(xattr_key) < len(xattrs) and xattrs[ix + len(xattr_key)] != 0:
                xattr_key += chr(xattrs[ix + len(xattr_key)])

            # check if the key is txn if it matches create a marker and break
            if xattr_key == 'txn':
                txn_marker = txnMarker(ix, pair_len, xattrs
                                       [ix + len(xattr_key) + 1: pair_len + ix - len(xattr_key) + 2])
                break

            # otherwise skip body and move on to next xattr
            ix += pair_len

        if txn_marker is None:
            return False, val, cas, exp, revid, data_type

        # check if txn is valid JSON if not let the server handle it
        try:
            txn_xattr = json.loads(txn_marker.body.decode())
        except Exception:
            logging.debug('(TXN) txn is invalid json')
            return False, val, cas, exp, revid, data_type

        # get op type from the txn
        if 'op' not in txn_xattr or 'type' not in txn_xattr['op']:
            logging.info('(TXN) Transaction extended attributes is missing required field "op"')
            return False, val, cas, exp, revid, data_type

        if txn_xattr['op']['type'] == 'insert':

            logging.info(f'(TXN) Skip document with key {tag_user_data(str_key)} as it is a TXN insert')