<commit_before>import time
import threading

import synapse.crypto as s_crypto
import synapse.threads as s_threads

from synapse.eventbus import EventBus

class NoSuchProto(Exception):pass

class TooManyTries(Exception):pass
class ImplementMe(Exception):pass

class LinkRelay:

    proto = None

    def __init__(self, link):
        self.link = link
        self._reqValidLink()

    def _reqValidLink(self):
        pass

    def _prepLinkSock(self, sock):

        sock['relay'] = self

        sock['link'] = self.link

        timeout = self.link[1].get('timeout')
        if timeout != None:
            sock.settimeout(timeout)

        # must remain first!
        zerosig = self.link[1].get('zerosig')
        if zerosig != None:
            xform = s_crypto.Rc4Xform(b'')
            sock.addSockXform(xform)

        if sock.get('listen'):
            return

        rc4key = self.link[1].get('rc4key')
        if rc4key != None:
            xform = s_crypto.Rc4Xform(rc4key)
            sock.addSockXform(xform)

        sock['trans'] = self.link[1].get('trans')

        #FIXME support DH KEX

    def listen(self):
        '''
        Create and return a new server Socket()
        '''
        sock = self._listen()

        sock['listen'] = True
        self._prepLinkSock(sock)

        return sock

    def connect(self):
        '''
        Create, connect, and return a new client Socket()
        '''
        sock = self._connect()

        sock['connect'] = True
        self._prepLinkSock(sock)

        return sock
<commit_msg>cleanup socket setters to due without the setitem override and be cleaner<commit_after>import time
import threading

import synapse.crypto as s_crypto
import synapse.threads as s_threads

from synapse.eventbus import EventBus

class NoSuchProto(Exception):pass

class TooManyTries(Exception):pass
class ImplementMe(Exception):pass

class LinkRelay:

    proto = None

    def __init__(self, link):
        self.link = link
        self._reqValidLink()

    def _reqValidLink(self):
        pass

    def _prepLinkSock(self, sock):

        sock.set('relay', self)
        sock.set('link', self.link)

        timeout = self.link[1].get('timeout')
        if timeout != None:
            sock.settimeout(timeout)

        if sock.get('listen'):
            return

        rc4key = self.link[1].get('rc4key',b'')
        zerosig = self.link[1].get('zerosig')
        if rc4key or zerosig != None:
            xform = s_crypto.Rc4Xform(rc4key)
            sock.addSockXform(xform)

    def listen(self):
        '''
        Create and return a new server Socket()
        '''
        sock = self._listen()

        sock.set('listen',True)
        self._prepLinkSock(sock)

        return sock

    def connect(self):
        '''
        Create, connect, and return a new client Socket()
        '''
        sock = self._connect()

        sock.set('connect',True)
        self._prepLinkSock(sock)

        return sock

{'fraction_non_alphanumeric': 0.10680592991913747, 'fraction_numerical': 0.006064690026954178, 'mean_word_length': 2.155154091392136, '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': '6055515', 'n_tokens_mistral': 922, 'n_tokens_neox': 872, 'n_words': 214}