<commit_before>from gevent.server import StreamServer
from cryptokit.base58 import get_bcaddress_version

import datetime
import re
import socket


class GenericServer(StreamServer):
    def task_exc(self, name, *args, **kwargs):
        self.net_state['celery'].send_task(
            self.confg['celery_task_prefix'] + '.' + name, *args, **kwargs)

    def convert_username(self, username):
        # if the address they passed is a valid address,
        # use it. Otherwise use the pool address
        bits = username.split('.', 1)
        username = bits[0]
        worker = ''
        if len(bits) > 1:
            self.logger.debug("Registering worker name {}".format(bits[1]))
            worker = bits[1][:16]
        try:
            version = get_bcaddress_version(username)
        except Exception:
            version = False

        if version:
            address = username
        else:
            filtered = re.sub('[\W_]+', '', username).lower()
            self.logger.debug(
                "Invalid address passed in, checking aliases against {}"
                .format(filtered))
            if filtered in self.config['aliases']:
                address = self.config['aliases'][filtered]
                self.logger.debug("Setting address alias to {}".format(address))
            else:
                address = self.config['donate_address']
                self.logger.debug("Falling back to donate address {}".format(address))

        return address, worker


class GenericClient(object):

    def convert_username(self, username):
        # if the address they passed is a valid address,
        # use it. Otherwise use the pool address
        bits = username.split('.', 1)
        username = bits[0]
        worker = ''
        if len(bits) > 1:
            self.logger.debug("Registering worker name {}".format(bits[1]))
            worker = bits[1][:16]
        try:
            version = get_bcaddress_version(username)
        except Exception:
            version = False

        if version:
            address = username
        else:
            filtered = re.sub('[\W_]+', '', username).lower()
            self.logger.debug(
                "Invalid address passed in, checking aliases against {}"
                .format(filtered))
            if filtered in self.config['aliases']:
                address = self.config['aliases'][filtered]
                self.logger.debug("Setting address alias to {}".format(address))
            else:
                address = self.config['donate_address']
                self.logger.debug("Falling back to donate address {}".format(address))

        return address, worker<commit_msg>adds regex matching to try and replace spaces and special chars with dashes<commit_after>from gevent.server import StreamServer
from cryptokit.base58 import get_bcaddress_version

import datetime
import re
import socket


class GenericServer(StreamServer):
    def task_exc(self, name, *args, **kwargs):
        self.net_state['celery'].send_task(
            self.confg['celery_task_prefix'] + '.' + name, *args, **kwargs)


class GenericClient(object):

    def convert_username(self, username):
        # if the address they passed is a valid address,
        # use it. Otherwise use the pool address
        bits = username.split('.', 1)
        username = bits[0]
        worker = ''
        if len(bits) > 1:
            parsed_w = re.sub(r'[^a-zA-Z0-9\[\]_]+', '-', str(bits[1]))
            self.logger.debug("Registering worker name {}".format(parsed_w))
            worker = parsed_w[:16]
        try:
            version = get_bcaddress_version(username)
        except Exception:
            version = False

        if version:
            address = username
        else:
            filtered = re.sub('[\W_]+', '', username).lower()
            self.logger.debug(
                "Invalid address passed in, checking aliases against {}"
                .format(filtered))
            if filtered in self.config['aliases']:
                address = self.config['aliases'][filtered]
                self.logger.debug("Setting address alias to {}".format(address))
            else:
                address = self.config['donate_address']
                self.logger.debug("Falling back to donate address {}".format(address))

        return address, worker
{'fraction_non_alphanumeric': 0.11251725724804418, 'fraction_numerical': 0.005982512655315232, 'mean_word_length': 2.06558533145275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '7444454', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1109, 'n_words': 313}