def raw(self):
     r = self.__dict__["data"]
     if isinstance(r, list):
         ret = []
         for x in r:
             ret += [x.raw() if isinstance(x, JSONObject) else x]
         return ret
     else:
         ret = {}
         for x in r:
             ret[str(x)] = r[x].raw() if isinstance(r[x], JSONObject) else u(r[x])
             if isinstance(ret[x], unicode):
                 ret[str(x)] = u(str(ret[x]))
         return ret
    def parse(self, data, clock):
        if not data:  # nothing received or nothing in the history -> nothing to parse
            return None

        if self.lenNames > len(data):
            raise Exception("CSVParser: not enough data fields")

        result = JOb()
        sd = self.wrapper.getSensorDescription()
        result.fields = sd.fields
        # print data
        for i in range(0, self.lenNames):
            n = self.names[i]
            if n in sd.fields:
                result[n] = JOb()
                result[n].propertyName = sd.field[n].propertyName
                result[n].propertyURI = sd.field[n].propertyURI
                if "unit" in sd.field[n]:
                    result[n].unit = sd.field[n].unit
                result[n].observationSamplingTime = clock.timeAsString()
                result[n].sensorID = sd.fullSensorID
                if self.timestampcell >= 0:
                    result[n].observationResultTime = sd.parseTimestamp(data[self.timestampcell]).strftime(AbstractClock.format)
                else:
                    result[n].observationResultTime = result[n].observationSamplingTime

                if sd.field[n].dataType == "datetime.datetime":
                    result[n].value = dt.datetime.strptime(data[i], sd.field[n].format)
                else:
                    result[n].value = str2Type(u(data[i]), sd.field[n].dataType)

        return result
    def __repr__(self):

        if isinstance(self.data, list):
            return self.data.__repr__()
        else:
            r = []
            for d in self.data:
                _d = self.data[d]
                if isinstance(_d, str) or isinstance(_d, unicode):
                    r.append(u": ".join([d, u(_d)]))
                else:
                    r.append(u": ".join([d, unicode(_d)]))
            return self.__class__.__name__ + u"<" + u", ".join(r) + u">"
    def parse(self, data, clock):
        if not data:  # nothing received or nothing in the history -> nothing to parse
            return None

        if isinstance(data, str) or isinstance(data, unicode):
            data = JOb(u(data))

        result = JOb()
        sd = self.wrapper.getSensorDescription()
        result.fields = sd.fields
        for fieldname in sd.fields:
            result[fieldname] = JOb()
            result[fieldname].propertyName = sd.field[fieldname].propertyName
            result[fieldname].propertyURI = sd.field[fieldname].propertyURI
            if "unit" in sd.field[fieldname]:
                result[fieldname].unit = sd.field[fieldname].unit
            result[fieldname].sensorID = sd.fullSensorID
            result[fieldname].observationSamplingTime = clock.timeAsString()
            if self.timestampfield and self.timestampfield in data:
                result[fieldname].observationResultTime = sd.parseTimestamp(data[self.timestampfield]).strftime(
                    AbstractClock.format
                )
            else:
                result[fieldname].observationResultTime = result[fieldname].observationSamplingTime

            if sd.field[fieldname].dataType == "datetime.datetime":
                if sd.field[fieldname].format.startswith("UNIX"):
                    result[fieldname].value = sd.parseTimestamp(data[fieldname]) if fieldname in data else None
                else:
                    result[fieldname].value = (
                        dt.datetime.strptime(data[fieldname], sd.field[fieldname].format) if fieldname in data else None
                    )
            else:
                result[fieldname].value = (
                    str2Type(u(data[fieldname]), sd.field[fieldname].dataType) if fieldname in data else None
                )

        return result