<commit_before># -*- coding: utf-8 -*-
import uwsgi
from datetime import datetime, timedelta 
import gevent.select
from ws4redis.exceptions import WebSocketError
from ws4redis.wsgi_server import WebsocketWSGIServer


class uWSGIWebsocket(object):
    def __init__(self, user):
        self._closed = False
        self._user = user
        self._last_seen = None

    def get_file_descriptor(self):
        """Return the file descriptor for the given websocket"""
        try:
            return uwsgi.connection_fd()
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    @property
    def closed(self):
        return self._closed

    def receive(self):
        if self._closed:
            raise WebSocketError("Connection is already closed")
        try:
            return uwsgi.websocket_recv_nb()
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    def flush(self):
        try:
            uwsgi.websocket_recv_nb()
        except IOError:
            self.close()

    def send(self, message, binary=None):
        try:
            uwsgi.websocket_send(message)
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    def close(self, code=1000, message=''):
        self._closed = True
        try:
            # If a handler has been defined in the settings, call it
            # to notify disconnection of user
            settings.DISCONNECTION_HANDLER(self.user)<commit_msg>Fix bug for prod with uwsgi<commit_after># -*- coding: utf-8 -*-
import uwsgi
from datetime import datetime, timedelta 
import gevent.select
from ws4redis.exceptions import WebSocketError
from ws4redis.wsgi_server import WebsocketWSGIServer
from django.conf import settings


class uWSGIWebsocket(object):
    def __init__(self, user):
        self._closed = False
        self._user = user
        self._last_seen = None

    def get_file_descriptor(self):
        """Return the file descriptor for the given websocket"""
        try:
            return uwsgi.connection_fd()
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    @property
    def closed(self):
        return self._closed

    def receive(self):
        if self._closed:
            raise WebSocketError("Connection is already closed")
        try:
            return uwsgi.websocket_recv_nb()
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    def flush(self):
        try:
            uwsgi.websocket_recv_nb()
        except IOError:
            self.close()

    def send(self, message, binary=None):
        try:
            uwsgi.websocket_send(message)
        except IOError, e:
            self.close()
            raise WebSocketError(e)

    def close(self, code=1000, message=''):
        self._closed = True
        try:
            # If a handler has been defined in the settings, call it
            # to notify disconnection of user
            settings.DISCONNECTION_HANDLER(self._user)
{'fraction_non_alphanumeric': 0.07946370176586004, 'fraction_numerical': 0.004578155657292348, 'mean_word_length': 2.049850448654038, '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': '7220375', 'n_tokens_mistral': 875, 'n_tokens_neox': 837, 'n_words': 240}