<commit_before>from couchbase import Couchbase, FMT_PICKLE

cb = Couchbase.connect('127.0.0.1', 8091, '', '', 'default')
#cb.default_format = FMT_PICKLE

for i in range(0, 10):
    key = 'please-' + str(i)
    value = {"it": "works-" + str(i)}
    cb.set(key, value)

got = cb.get('please-5')
print(got)<commit_msg>Extend the basic example<commit_after>from couchbase import Couchbase, FMT_PICKLE
from couchbase.exceptions import KeyExistsError

# Connect to the default bucket on local host
cb = Couchbase.connect('127.0.0.1', 8091, '', '', 'default')

# If you want to store the Python objects pickled and not as JSON
#cb.default_format = FMT_PICKLE

# Store a document
cas = cb.set('first', {'hello': 'world'})
print(cas)

# Get the document
item = cb.get('first')
print(item)

# Overwrite the existing document only if the CAS value matched
try:
    # An exception will be raised if the CAS doesn't match
    wrong_cas = cas + 123
    cb.set('first', {'hello': 'world', 'additional': True}, cas=wrong_cas)
except KeyExistsError:
    # Get the correct current CAS value
    item, flags, correct_cas = cb.get('first', extended=True)
    # Set it again, this time with the correct CAS value
    cas = cb.set('first', {'hello': 'world', 'additional': True},
                 cas=correct_cas)
    print(cas)

# Delete the document only if the CAS value matches (it would also
# work without a cas value)
cb.delete('first', cas=cas)

# Make sure the document really got deleted
assert cb.get('first', quiet=True) is None
{'fraction_non_alphanumeric': 0.1297760210803689, 'fraction_numerical': 0.017786561264822136, 'mean_word_length': 4.131756756756757, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7399343', 'n_tokens_mistral': 515, 'n_tokens_neox': 485, 'n_words': 172}