<commit_before># session.py

import random
import xmltodict

# try python 3 imports, fall back to python 2
try:
    from urllib.parse import urlencode
    from urllib.request import urlopen, Request
    from urllib.error import URLError, HTTPError
except ImportError:
    from urllib import urlencode
    from urllib2 import urlopen, Request, URLError, HTTPError

class Session:
    def __init__(self, user, pw, host='localhost', port=8834):
        self.host = host
        self.port = port

    def __enter__(self):
        self.token = self.get('login', login=user,password=pw)['token']

    def __exit__(self, type, value, traceback):
        self.close()

    def close(self):
        self.get('logout')['contents'] == 'OK'
    
    def get(self, path, **kwargs):
        if 'token' not in kwargs and hasattr(self, 'token'):
            kwargs['token'] = self.token
        kwargs['seq'] = random.randrange(1000000)
        url = 'https://{0}:{1}/{2}'.format(self.host,self.port,path)
        request = Request(url, urlencode(kwargs))
        try:
            response = urlopen(request)
            response_data = xmltodict.parse(response.read())
            if response_data['seq'] != kwargs['seq']:
                raise Exception("Unique number did not match!")
            elif response_data['status'] != 'OK':
                raise AuthenticationError("Invalid credentials")
            return response_data
        except HTTPError as e:
            raise AuthenticationError
        except URLError as e:
            raise ConnectionError

class ConnectionError(Exception):
    pass

class AuthenticationError(Exception):
    pass

<commit_msg>Make things work properly<commit_after># session.py

import random
import xmltodict

# try python 3 imports, fall back to python 2
try:
    from urllib.parse import urlencode
    from urllib.request import urlopen, Request
    from urllib.error import URLError, HTTPError
except ImportError:
    from urllib import urlencode
    from urllib2 import urlopen, Request, URLError, HTTPError

class Session:
    def __init__(self, user, pw, host='localhost', port=8834):
        self.host = host
        self.port = port
        self.token = self.get('login', login=user,password=pw)['token']

    def close(self):
        return self.get('logout') == 'OK'
    
    def get(self, path, **kwargs):
        if 'token' not in kwargs and hasattr(self, 'token'):
            kwargs['token'] = self.token
        kwargs['seq'] = random.randrange(1000000)
        url = 'https://{0}:{1}/{2}'.format(self.host,self.port,path)
        request = Request(url, urlencode(kwargs))
        try:
            response = urlopen(request)
            response_data = xmltodict.parse(response.read())['reply']
            if int(response_data['seq']) != kwargs['seq']:
                raise Exception("Unique number did not match!")
            elif response_data['status'] != 'OK':
                raise AuthenticationError("Invalid credentials")
            return response_data['contents']
        except HTTPError as e:
            raise AuthenticationError
        except URLError as e:
            raise ConnectionError

class ConnectionError(Exception):
    pass

class AuthenticationError(Exception):
    pass


{'fraction_non_alphanumeric': 0.10882262526898248, 'fraction_numerical': 0.01045189056255764, 'mean_word_length': 2.706150341685649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2317205', 'n_tokens_mistral': 947, 'n_tokens_neox': 923, 'n_words': 258}