<commit_before>import socket

from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import User


class GooglebotMiddleware(object):
    """
    Middleware to automatically log in the Googlebot with the user account 'googlebot'
    """
    def process_request(self, request):
        request.is_googlebot = False # Assume false, until proven
        if request.user == AnonymousUser():
            if request.META.get('HTTP_USER_AGENT'):
                if 'Googlebot' in request.META['HTTP_USER_AGENT']:
                    try:
                        remote_ip = request.META['REMOTE_ADDR']
                        hostname = socket.gethostbyaddr(remote_ip)[0]

                        if hostname.endswith('googlebot.com'):
                            request.user = User.objects.get_or_create(username='googlebot') # login our googlebot user :)
                            request.is_googlebot = True
                        else:
                            # FAKE googlebot!!!!
                            request.is_googlebot = False

                    except Exception, e:
                        pass # Don't bring down the site
        return None<commit_msg>Correct way to use get or create<commit_after>import socket

from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import User


class GooglebotMiddleware(object):
    """
    Middleware to automatically log in the Googlebot with the user account 'googlebot'
    """
    def process_request(self, request):
        request.is_googlebot = False # Assume false, until proven
        if request.user == AnonymousUser():
            if request.META.get('HTTP_USER_AGENT'):
                if 'Googlebot' in request.META['HTTP_USER_AGENT']:
                    try:
                        remote_ip = request.META['REMOTE_ADDR']
                        hostname = socket.gethostbyaddr(remote_ip)[0]

                        if hostname.endswith('googlebot.com'):
                            request.user, created = User.objects.get_or_create(username='googlebot') # login our googlebot user :)
                            request.is_googlebot = True
                        else:
                            # FAKE googlebot!!!!
                            request.is_googlebot = False

                    except Exception, e:
                        pass # Don't bring down the site
        return None
{'fraction_non_alphanumeric': 0.07847165160230074, 'fraction_numerical': 0.0008216926869350862, 'mean_word_length': 1.6758241758241759, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5864978', 'n_tokens_mistral': 604, 'n_tokens_neox': 572, 'n_words': 152}