<commit_before>#! /usr/bin/env python
"""
Copyright (C) 2014 CompleteDB LLC.

This program is free software: you can redistribute it and/or modify
it under the terms of the Apache License Version 2.0 http://www.apache.org/licenses.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

"""

import json
from pubsubsql.net.helper import Helper as NetHelper
from pubsubsql.net.response import Response as ResponseData

class Client:
    """Client."""
    
    def __nvl(self, string):
        if string:
            return string
        else:
            return ""
    
    def __reset(self):
        self.__rawJson = ""
        self.__response.reset()
        self.__record = -1
    
    def __hardDisconnect(self):
        self.__net.close()
        self.__reset()
    
    def __write(self, message):
        try:
            if self.__net.isClosed():
                raise IOError("Not connected")
            else:
                self.__requestId += 1
                self.__net.writeWithHeader(self.__requestId, message.encode("utf-8"))
        except:
            self.__hardDisconnect()
            raise
                
    def __readTimeout(self, timeoutSec):
        try:
            if self.__net.isClosed():
                raise IOError("Not connected")
            else:
                return self.__net.readTimeout(timeoutSec)
        except:
            self.__hardDisconnect()
            raise

    def __invalidRequestIdError(self):
        raise Exception("Protocol error invalid request id")

    def __setColumns(self):
        self.__columns.clear()
        columns = self.__response.getColumns()
        if columns:
            for index, column in enumerate(columns):
                self.__columns[column] = index

    def __unmarshallJson(self, messageBytes):
        self.__rawJson = messageBytes.decode("utf-8")
        self.__response.setParsedJson(json.loads(self.__rawJson))
        if self.__response.getStatus() == "ok":
            self.__setColumns()
        else:
            raise ValueError(self.__response.getMsg())

    def __getColumn(self, column):
        pass

    def __getValueByColumnName(self, column):
        print self.__response.getData()
        print self.__response.getColumns()
        return ""

    def __getValueByColumnOrdinal(self, ordinal):
        print self.__response.getData()<commit_msg>add __getColumnIndex<commit_after>#! /usr/bin/env python
"""
Copyright (C) 2014 CompleteDB LLC.

This program is free software: you can redistribute it and/or modify
it under the terms of the Apache License Version 2.0 http://www.apache.org/licenses.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

"""

import json
from pubsubsql.net.helper import Helper as NetHelper
from pubsubsql.net.response import Response as ResponseData

class Client:
    """Client."""
    
    def __nvl(self, string):
        if string:
            return string
        else:
            return ""
    
    def __reset(self):
        self.__rawJson = ""
        self.__response.reset()
        self.__record = -1
    
    def __hardDisconnect(self):
        self.__net.close()
        self.__reset()
    
    def __write(self, message):
        try:
            if self.__net.isClosed():
                raise IOError("Not connected")
            else:
                self.__requestId += 1
                self.__net.writeWithHeader(self.__requestId, message.encode("utf-8"))
        except:
            self.__hardDisconnect()
            raise
                
    def __readTimeout(self, timeoutSec):
        try:
            if self.__net.isClosed():
                raise IOError("Not connected")
            else:
                return self.__net.readTimeout(timeoutSec)
        except:
            self.__hardDisconnect()
            raise

    def __invalidRequestIdError(self):
        raise Exception("Protocol error invalid request id")

    def __setColumns(self):
        self.__columns.clear()
        columns = self.__response.getColumns()
        if columns:
            for index, column in enumerate(columns):
                self.__columns[column] = index

    def __unmarshallJson(self, messageBytes):
        self.__rawJson = messageBytes.decode("utf-8")
        self.__response.setParsedJson(json.loads(self.__rawJson))
        if self.__response.getStatus() == "ok":
            self.__setColumns()
        else:
            raise ValueError(self.__response.getMsg())

    def __getColumnIndex(self, column):
        return self.__columns.get(column, -1)

    def __getValueByColumnName(self, column):
        print self.__response.getData()
        print self.__response.getColumns()
        return ""

    def __getValueByColumnOrdinal(self, ordinal):
        print self.__response.getData()
{'fraction_non_alphanumeric': 0.09049232609128961, 'fraction_numerical': 0.004185768387482559, 'mean_word_length': 2.150031387319523, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4518527', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1286, 'n_words': 360}