<commit_before>import os

from flask.ext.restful import Resource
from flask.ext.restful.reqparse import RequestParser

from smbus import SMBus


class BusConfig(Resource):

    def get(self):
        lDevFiles = os.listdir('/dev')
        lI2cDevs = [
            dev.replace('i2c-', '')
            for dev in lDevFiles if dev.find('i2c') == 0
            ]
        lI2cDevs.sort()
        return {
            'i2c': {
                'buses': lI2cDevs,
                #'status': 'online',
                }
            }


class Get(Resource):

    def __init__(self):
        super(Get, self).__init__()
        self.__mParser = RequestParser()
        self.__mParser.add_argument('bus_id', type=int, required=True)
        self.__mParser.add_argument('address', type=str, required=True)
        self.__mParser.add_argument('cmd', type=str)

    def get(self):
        lStatus = "ok"
        lCommand = ""
        lValue = ""
        lArgs = self.__mParser.parse_args()
        lBusId = lArgs['bus_id']
        lBus = SMBus(lBusId)

        lAddress = int(lArgs['address'], 0)
        try:
            if lArgs['cmd'] is None:
                lValue = lBus.read_byte(lAddress)
            else:
                lCommand = int(lArgs['cmd'], 0)
                lValue = lBus.read_byte_data(lAddress, lCommand)
        except IOError, pExc:
            lStatus = "Error reading from bus: " + str(pExc)

        return {
            'bus_id': lBusId,
            'address': lAddress,
            'cmd': lCommand,
            'value': lValue,
            'status': lStatus
            }


class Set(Resource):

    def __init__(self):
        super(Set, self).__init__()
        self.__mParser = RequestParser()
        self.__mParser.add_argument('bus_id', type=str, required=True)
        self.__mParser.add_argument('address', type=int, required=True)
        self.__mParser.add_argument('value', type=int, required=True)
        self.__mParser.add_argument('cmd', type=int)

    def get(self):
        lStatus = 'ok'
        lArgs = self.__mParser.parse_args()
        lBusId = lArgs['bus_id']
        lAddress = int(lArgs['address'], 0)
        lValue = int(lArgs['value'], 0)
        lBus = SMBus(lBusId)

        try:
            if lArgs['cmd'] is None:
                lBus.write_byte(lAddress, lValue)
            else:
                lCommand = int(lArgs['cmd'], 0)<commit_msg>data types considered correctly<commit_after>import os

from flask.ext.restful import Resource
from flask.ext.restful.reqparse import RequestParser

from smbus import SMBus


class BusConfig(Resource):

    def get(self):
        lDevFiles = os.listdir('/dev')
        lI2cDevs = [
            dev.replace('i2c-', '')
            for dev in lDevFiles if dev.find('i2c') == 0
            ]
        lI2cDevs.sort()
        return {
            'i2c': {
                'buses': lI2cDevs,
                #'status': 'online',
                }
            }


class Get(Resource):

    def __init__(self):
        super(Get, self).__init__()
        self.__mParser = RequestParser()
        self.__mParser.add_argument('bus_id', type=str, required=True)
        self.__mParser.add_argument('address', type=str, required=True)
        self.__mParser.add_argument('cmd', type=str)

    def get(self):
        lStatus = "ok"
        lCommand = ""
        lValue = ""
        lArgs = self.__mParser.parse_args()
        lBusId = int(lArgs['bus_id'], 0)
        lBus = SMBus(lBusId)

        lAddress = int(lArgs['address'], 0)
        try:
            if lArgs['cmd'] is None:
                lValue = lBus.read_byte(lAddress)
            else:
                lCommand = int(lArgs['cmd'], 0)
                lValue = lBus.read_byte_data(lAddress, lCommand)
        except IOError, pExc:
            lStatus = "Error reading from bus: " + str(pExc)

        return {
            'bus_id': lBusId,
            'address': lAddress,
            'cmd': lCommand,
            'value': lValue,
            'status': lStatus
            }


class Set(Resource):

    def __init__(self):
        super(Set, self).__init__()
        self.__mParser = RequestParser()
        self.__mParser.add_argument('bus_id', type=str, required=True)
        self.__mParser.add_argument('address', type=str, required=True)
        self.__mParser.add_argument('value', type=str, required=True)
        self.__mParser.add_argument('cmd', type=str)

    def get(self):
        lStatus = 'ok'
        lArgs = self.__mParser.parse_args()
        lBusId = int(lArgs['bus_id'], 0)
        lAddress = int(lArgs['address'], 0)
        lValue = int(lArgs['value'], 0)
        lBus = SMBus(lBusId)

        try:
            if lArgs['cmd'] is None:
                lBus.write_byte(lAddress, lValue)
            else:
                lCommand = int(lArgs['cmd'], 0)
{'fraction_non_alphanumeric': 0.1259351620947631, 'fraction_numerical': 0.005403158769742311, 'mean_word_length': 1.8889555822328932, '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': '4892932', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1488, 'n_words': 298}