<commit_before>import xml.etree.ElementTree as ET

from pprint import pprint

def build(name, data):
    type = globals()[name]
    return type(data)

class Error(Exception):
    def __init__(self, message, data = {}):
        self.message = message
        self.data = data
    def __str__(self):
        return self.message + ": " + repr(self.data)

class Response:
    nsmap = {
        'epp':      'urn:ietf:params:xml:ns:epp-1.0',
        'domain':   'urn:ietf:params:xml:ns:domain-1.0',
    }

    okcodes = {
        '1000':     'completed',
        '1001':     'pending',
        '1300':     'no messages',
        '1301':     'ack to dequeue',
        '1500':     'ending session',
    }

    def __init__(self, xml):
        self.data       = {}
        self.root       = ET.fromstring(xml)
        self.response   = self.find(self.root,      'epp:response')
        self.result     = self.find(self.response,  'epp:result')
        self.trID       = self.find(self.response,  'epp:trID');
        self.resultMsg  = self.find(self.result,    'epp:msg')
        self.data['resultCode']     = self.result.attrib['code']
        self.data['resultLang']     = self.resultMsg.attrib['lang']
        self.data['resultMessage']  = self.resultMsg.text;
        self.data['cltrid']         = self.find(self.trID, 'epp:clTRID').text;
        self.data['svtrid']         = self.find(self.trID, 'epp:svTRID').text;
        if not self.data['resultCode'] in self.okcodes:
            raise Error(self.data['resultMessage'], self.data)
        self.resData    = self.find(self.response, 'epp:resData');

    def find(self, el, name):
        return el.find(name, namespaces=self.nsmap)

    def findall(self, el, name):
        return el.findall(name, self.nsmap)

class DomainCheck(Response):
    def __init__(self, xml):
        Response.__init__(self, xml)
        self.chkData        = self.find(self.resData, 'domain:chkData')<commit_msg>+ proper Login error processing<commit_after>import xml.etree.ElementTree as ET

from pprint import pprint

def build(name, data):
    type = globals()[name]
    return type(data)

class Error(Exception):
    def __init__(self, message, data = {}):
        self.message = message
        self.data = data
    def __str__(self):
        return self.message + ": " + repr(self.data)

class Response:
    nsmap = {
        'epp':      'urn:ietf:params:xml:ns:epp-1.0',
        'domain':   'urn:ietf:params:xml:ns:domain-1.0',
        'oxrs':     'urn:afilias:params:xml:ns:oxrs-1.1',
    }

    okcodes = {
        '1000':     'completed',
        '1001':     'pending',
        '1300':     'no messages',
        '1301':     'ack to dequeue',
        '1500':     'ending session',
    }

    def __init__(self, xml):
        self.data       = {}
        self.root       = ET.fromstring(xml)
        self.response   = self.find(self.root,      'epp:response')
        self.result     = self.find(self.response,  'epp:result')
        self.trID       = self.find(self.response,  'epp:trID')
        self.resultMsg  = self.find(self.result,    'epp:msg')
        self.value      = self.find(self.result,    'epp:value')
        self.xcp        = self.find(self.value,     'oxrs:xcp')
        self.data['resultCode']     = self.result.attrib['code']
        self.data['resultLang']     = self.resultMsg.attrib['lang']
        self.data['resultMessage']  = self.resultMsg.text
        if self.trID is not None:
            self.data['cltrid']     = self.find(self.trID, 'epp:clTRID').text
            self.data['svtrid']     = self.find(self.trID, 'epp:svTRID').text
        if self.xcp is not None:
            self.data['resultMessage']  = self.xcp.text
        if not self.data['resultCode'] in self.okcodes:
            raise Error(self.data['resultMessage'], self.data)
        self.resData    = self.find(self.response, 'epp:resData')

    def find(self, el, name):
        return el.find(name, namespaces=self.nsmap)

    def findall(self, el, name):
        return el.findall(name, self.nsmap)

class Login(Response):
    def __init__(self, xml):
        Response.__init__(self, xml)

class DomainCheck(Response):
    def __init__(self, xml):
        Response.__init__(self, xml)
        self.chkData        = self.find(self.resData, 'domain:chkData')
{'fraction_non_alphanumeric': 0.1491493824283384, 'fraction_numerical': 0.011652295502213935, 'mean_word_length': 2.286370597243492, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 17}, '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': '1256826', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1426, 'n_words': 264}