<commit_before>import gevent
import bottle
import uuid

class NeutronApiContext(object):
    def __init__(self, request=None, user_token=None):
        self.request = request
        self.user_token = user_token
        self.request_id = str(uuid.uuid4())
    # end __init__
# end class NeutronApiContext

def get_context():
    return gevent.getcurrent().neutron_api_context

def set_context(api_ctx):
    gevent.getcurrent().neutron_api_context = api_ctx

def clear_context():
    gevent.getcurrent().neutron_api_context = None

def have_context():
    return (hasattr(gevent.getcurrent(), 'neutron_api_context') and
            gevent.getcurrent().neutron_api_context is not None)

def use_context(fn):
    def wrapper(*args, **kwargs):
        if not have_context():
            context_created = True
            user_token = bottle.request.headers.get('X_AUTH_TOKEN',
                'no user token for %s %s' %(bottle.request.method,
                                            bottle.request.url))
            set_context(NeutronApiContext(
                request=bottle.request, user_token=user_token))
        else:
            context_created = False

        try:
            return fn(*args, **kwargs)
        finally:
            if context_created:
                clear_context()
    # end wrapper
    return wrapper
<commit_msg>Use request_id forwarded by neutron plugin<commit_after>import gevent
import bottle
import uuid

class NeutronApiContext(object):
    def __init__(self, request=None, user_token=None):
        self.request = request
        self.user_token = user_token
        self.request_id = request.json['context'].get('request_id', str(uuid.uuid4()))
    # end __init__
# end class NeutronApiContext

def get_context():
    return gevent.getcurrent().neutron_api_context

def set_context(api_ctx):
    gevent.getcurrent().neutron_api_context = api_ctx

def clear_context():
    gevent.getcurrent().neutron_api_context = None

def have_context():
    return (hasattr(gevent.getcurrent(), 'neutron_api_context') and
            gevent.getcurrent().neutron_api_context is not None)

def use_context(fn):
    def wrapper(*args, **kwargs):
        if not have_context():
            context_created = True
            user_token = bottle.request.headers.get('X_AUTH_TOKEN',
                'no user token for %s %s' %(bottle.request.method,
                                            bottle.request.url))
            set_context(NeutronApiContext(
                request=bottle.request, user_token=user_token))
        else:
            context_created = False

        try:
            return fn(*args, **kwargs)
        finally:
            if context_created:
                clear_context()
    # end wrapper
    return wrapper

{'fraction_non_alphanumeric': 0.09298118668596238, 'fraction_numerical': 0.000723589001447178, 'mean_word_length': 2.5044359949302915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038126', 'n_tokens_mistral': 792, 'n_tokens_neox': 783, 'n_words': 172}