<commit_before>""" /**
 * Python BaseXClient for BaseX 6.0.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-10, ISC License
 * @author <NAME>
 */ """

import hashlib, socket, sys, getopt, atexit

class BaseXClient6(object):
    def __init__(self,host,port):
        self.host = host
        self.port = port
        print 'BaseX 6.01 [Client]'
        print 'Try "help" to get some information.'
    
    # connects to the server    
    def connect(self):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect((self.host,self.port))
        return self.login()              
    
    # login of user at the server
    def login(self):
        ts = self.receive()
        user = raw_input('Username: ');
        pw = raw_input('Password: ');
        pwmd5 = hashlib.md5(pw).hexdigest()
        m = hashlib.md5()
        m.update(pwmd5)
        m.update(ts)
        complete = m.hexdigest()
        self.sendCommand(user)
        self.sendCommand(complete)
        data = self.s.recv(1)
        return "\0" == data
    
    # sends command to the server        
    def sendCommand(self,com):
        self.s.send(str.encode(com))
        self.s.send("\0")        
    
    # receives data    
    def receive(self):
        com = ""
        while True:
            data = self.s.recv(1)
            if(data == "\0"):
                return com
                break
            else:
                com += data
    
    # reads commands from the console    
    def readCommand(self):
        self.com = raw_input('> ')
        return self.com
    
    # runs the console
    def console(self):
        if self.connect() == True:
            self.sendCommand("SET INFO ON")
            self.s.recv(1024)
            while self.readCommand() != "exit":
                self.sendCommand(self.com)
                data = self.receive()
                if data != "":
                    print data
                else:
                    print self.receive()
            try: 
                self.sendCommand("exit")
            except:
                self.close()
            print "See you."
        else:
            print "Access denied."
            self.close()
    
    # closes the connection        
    def close(self):
        self.s.close()

# reads arguments -p and -h
def opts():
        try:
            opts, args = getopt.getopt(sys.argv[1:], "-p:-h", ["port", "host"])
        except getopt.GetoptError, err:
            print str(err)<commit_msg>Python Client bugfixes<commit_after>""" /**
 * Python BaseXClient for BaseX 6.0.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-10, ISC License
 * @author <NAME>
 */ """

import hashlib, socket, sys, getopt

class BaseXClient6(object):
    def __init__(self,host,port):
        self.host = host
        self.port = port
        print 'BaseX 6.01 [Client]'
        print 'Try "help" to get some information.'
    
    # connects to the server    
    def connect(self):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect((self.host,self.port))
        return self.login()              
    
    # login of user at the server
    def login(self):
        ts = self.getIt()
        user = raw_input('Username: ');
        pw = raw_input('Password: ');
        pwmd5 = hashlib.md5(pw).hexdigest()
        m = hashlib.md5()
        m.update(pwmd5)
        m.update(ts)
        complete = m.hexdigest()
        self.sendCommand(user)
        self.sendCommand(complete)
        data = self.s.recv(1)
        return "\0" == data
    
    # sends command to the server        
    def sendCommand(self,com):
        self.s.send(str.encode(com))
        self.s.send("\0")
        
    def getIt(self):
        com = ""
        while True:
            data = self.s.recv(1)
            if(data == "\0"):
                return com
            else:
                com += data
                      
    # receives data    
    def receive(self):
        part1 = self.getIt()
        part2 = self.getIt()
        part3 = self.s.recv(1)
        recv = ""
        if part1 != "\0":
            recv += part1 + part2
        else:
            recv = part2
        return recv      
    
    # reads commands from the console    
    def readCommand(self):
        self.com = raw_input('> ')
        return self.com
    
    # runs the console
    def console(self):
        if self.connect() == True:
            self.sendCommand("SET INFO ON")
            self.s.recv(1024)
            while self.readCommand() != "exit":
                self.sendCommand(self.com)
                data = self.receive()
                print data
            try: 
                self.sendCommand("exit")
            except:
                self.close()
            print "See you."
        else:
            print "Access denied."
            self.close()
    
    # closes the connection        
    def close(self):
        self.s.close()

# reads arguments -p and -h
def opts():
        try:
            opts, args = getopt.getopt(sys.argv[1:], "-p:-h", ["port", "host"])
        except getopt.GetoptError, err:
            print str(err)
{'fraction_non_alphanumeric': 0.11903381642512077, 'fraction_numerical': 0.01178743961352657, 'mean_word_length': 1.4600760456273765, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, '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': '4191158', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1503, 'n_words': 378}