Beispiel #1
0
        class SequenceItem(OptionalMappingSchema):

            macAddress = OptionalNode(colander.String(), to_name='bssid')
            channel = OptionalNode(colander.Integer())
            frequency = OptionalNode(colander.Integer())
            signalStrength = OptionalNode(colander.Integer(), to_name='signal')
            signalToNoiseRatio = OptionalNode(colander.Integer())
Beispiel #2
0
        class SequenceItem(OptionalMappingSchema):

            macAddress = OptionalNode(colander.String())
            age = OptionalNode(colander.Integer())
            channel = OptionalNode(colander.Integer())
            signalStrength = OptionalNode(colander.Integer())
            signalToNoiseRatio = OptionalNode(colander.Integer())
Beispiel #3
0
        class SequenceItem(OptionalMappingSchema):

            mac = OptionalNode(colander.String(), internal_name='macAddress')
            channel = OptionalNode(colander.Integer(), internal_name='channel')
            signal = OptionalNode(colander.Integer(),
                                  internal_name='signalStrength')
            snr = OptionalNode(colander.Integer(),
                               internal_name='signalToNoiseRatio')
            ssid = OptionalNode(colander.String())
Beispiel #4
0
        class SequenceItem(OptionalMappingSchema):

            radioType = OptionalNode(colander.String())
            mobileCountryCode = OptionalNode(colander.Integer())
            mobileNetworkCode = OptionalNode(colander.Integer())
            locationAreaCode = OptionalNode(colander.Integer())
            cellId = OptionalNode(colander.Integer())
            primaryScramblingCode = OptionalNode(colander.Integer())
            age = OptionalNode(colander.Integer())
            signalStrength = OptionalNode(colander.Integer())
            timingAdvance = OptionalNode(colander.Integer())
Beispiel #5
0
        class SequenceItem(OptionalMappingSchema):

            radioType = OptionalNode(colander.String(), to_name="radio")
            locationAreaCode = OptionalNode(colander.Integer(), to_name="lac")
            cellId = OptionalNode(colander.Integer(), to_name="cid")
            mobileCountryCode = OptionalNode(colander.Integer(), to_name="mcc")
            mobileNetworkCode = OptionalNode(colander.Integer(), to_name="mnc")
            signalStrength = OptionalNode(colander.Integer(), to_name="signal")
            timingAdvance = OptionalNode(colander.Integer(), to_name="tA")
            primaryScramblingCode = OptionalNode(colander.Integer(), to_name="psc")
            asu = OptionalNode(colander.Integer())
Beispiel #6
0
        class SequenceItem(OptionalMappingSchema):

            radioType = OptionalNode(colander.String(), to_name='radio')
            locationAreaCode = OptionalNode(colander.Integer(), to_name='lac')
            cellId = OptionalNode(colander.Integer(), to_name='cid')
            mobileCountryCode = OptionalNode(colander.Integer(), to_name='mcc')
            mobileNetworkCode = OptionalNode(colander.Integer(), to_name='mnc')
            signalStrength = OptionalNode(colander.Integer(), to_name='signal')
            timingAdvance = OptionalNode(colander.Integer(), to_name='tA')
            primaryScramblingCode = OptionalNode(colander.Integer(),
                                                 to_name='psc')
            asu = OptionalNode(colander.Integer())
Beispiel #7
0
        class SequenceItem(OptionalMappingSchema):

            radio = OptionalNode(RadioStringType(), to_name='radioType')
            mcc = OptionalNode(colander.Integer(), to_name='mobileCountryCode')
            mnc = OptionalNode(colander.Integer(), to_name='mobileNetworkCode')
            lac = OptionalNode(colander.Integer(), to_name='locationAreaCode')
            cid = OptionalNode(colander.Integer(), to_name='cellId')
            psc = OptionalNode(colander.Integer(),
                               to_name='primaryScramblingCode')
            age = OptionalNode(colander.Integer())
            signal = OptionalNode(colander.Integer(), to_name='signalStrength')
            ta = OptionalNode(colander.Integer(), to_name='timingAdvance')
Beispiel #8
0
class ReportSchema(OptionalMappingSchema):

    carrier = OptionalStringNode()
    homeMobileCountryCode = OptionalIntNode()
    homeMobileNetworkCode = OptionalIntNode()
    radioType = OptionalStringVocabularyNode(vocabulary=RADIO_STRINGS)
    timestamp = OptionalNode(UnixTimeFromInteger())

    bluetoothBeacons = BluetoothBeaconsSchema(missing=())
    wifiAccessPoints = WifiAccessPointsSchema(missing=())

    def deserialize(self, data):
        data = super(ReportSchema, self).deserialize(data)
        if (data is colander.drop
                or data is colander.null):  # pragma: no cover
            return colander.drop

        if not (data.get('bluetoothBeacons') or data.get('cellTowers')
                or data.get('wifiAccessPoints')):
            return colander.drop

        top_radio = data.get('radioType', None)
        for cell in data.get('cellTowers', ()):
            if top_radio and ('radioType' not in cell
                              or not cell['radioType']):
                cell['radioType'] = top_radio
            if cell.get('radioType') == 'umts':
                cell['radioType'] = 'wcdma'

        if 'radioType' in data:
            del data['radioType']

        return data
Beispiel #9
0
class ReportSchema(OptionalMappingSchema):

    carrier = OptionalStringNode()
    homeMobileCountryCode = OptionalIntNode()
    homeMobileNetworkCode = OptionalIntNode()
    radioType = OptionalStringVocabularyNode(vocabulary=RADIO_STRINGS)
    timestamp = OptionalNode(UnixTimeFromInteger())

    bluetoothBeacons = BluetoothBeaconsSchema(missing=())
    wifiAccessPoints = WifiAccessPointsSchema(missing=())

    def deserialize(self, data):
        data = super(ReportSchema, self).deserialize(data)
        if data is colander.drop or data is colander.null:
            return colander.drop

        if not (
            data.get("bluetoothBeacons")
            or data.get("cellTowers")
            or data.get("wifiAccessPoints")
        ):
            return colander.drop

        top_radio = data.get("radioType", None)
        for cell in data.get("cellTowers", ()):
            if top_radio and ("radioType" not in cell or not cell["radioType"]):
                cell["radioType"] = top_radio
            if cell.get("radioType") == "umts":
                cell["radioType"] = "wcdma"

        if "radioType" in data:
            del data["radioType"]

        return data
Beispiel #10
0
class BaseReportV1Schema(OptionalMappingSchema):

    lat = OptionalBoundedFloatNode(internal_name='latitude')
    lon = OptionalBoundedFloatNode(internal_name='longitude')

    time = OptionalNode(UnixTimeFromString(), internal_name='timestamp')
    accuracy = OptionalBoundedFloatNode()
    age = OptionalIntNode()
    altitude = OptionalBoundedFloatNode()
    altitude_accuracy = OptionalBoundedFloatNode(
        internal_name='altitudeAccuracy')
    heading = OptionalBoundedFloatNode()
    pressure = OptionalBoundedFloatNode()
    radio = OptionalStringNode(internal_name='radioType')
    speed = OptionalBoundedFloatNode()
    source = OptionalStringNode()
Beispiel #11
0
class BaseReportV0Schema(OptionalMappingSchema):

    lat = OptionalBoundedFloatNode(to_name="latitude")
    lon = OptionalBoundedFloatNode(to_name="longitude")

    time = OptionalNode(UnixTimeFromString(), to_name="timestamp")
    accuracy = OptionalBoundedFloatNode()
    age = OptionalIntNode()
    altitude = OptionalBoundedFloatNode()
    altitude_accuracy = OptionalBoundedFloatNode(to_name="altitudeAccuracy")
    heading = OptionalBoundedFloatNode()
    pressure = OptionalBoundedFloatNode()
    radio = OptionalStringVocabularyNode(vocabulary=RADIO_STRINGS,
                                         to_name="radioType")
    speed = OptionalBoundedFloatNode()
    source = OptionalStringVocabularyNode(
        vocabulary=SOURCE_STRINGS, validator=colander.OneOf(SOURCE_STRINGS))
Beispiel #12
0
class UnwiredlabsV1ResultSchema(RenamingMappingSchema):

    status = colander.SchemaNode(colander.String())
    message = colander.SchemaNode(colander.String(), missing=None)
    lat = colander.SchemaNode(BoundedFloat(), missing=None)
    lon = colander.SchemaNode(BoundedFloat(), missing=None)
    accuracy = colander.SchemaNode(colander.Float(), missing=None)
    fallback = OptionalNode(colander.String(), missing=None)

    def deserialize(self, data):
        data = super(UnwiredlabsV1ResultSchema, self).deserialize(data)

        # The API always returns 200 Ok responses, but uses the
        # status/message fields to indicate failures.
        status = data.get('status', None)
        if status != 'ok':
            message = data.get('message', None)
            if message == 'No matches found':
                # Fabricate a not found
                return {
                    'accuracy': None,
                    'fallback': None,
                    'lat': None,
                    'lon': None,
                }

            raise colander.Invalid('Error response, message: %s' % message)

        # Check required fields for status==ok responses
        for field in ('lat', 'lon', 'accuracy'):
            if data.get(field, None) is None:
                raise colander.Invalid('Missing required field: %s' % field)

        fallback = data.get('fallback', None)
        if fallback != 'lacf':
            fallback = None

        return {
            'accuracy': data['accuracy'],
            'fallback': fallback,
            'lat': data['lat'],
            'lon': data['lon'],
        }
Beispiel #13
0
class UnwiredlabsV1ResultSchema(RenamingMappingSchema):

    status = colander.SchemaNode(colander.String())
    message = colander.SchemaNode(colander.String(), missing=None)
    lat = colander.SchemaNode(BoundedFloat(), missing=None)
    lon = colander.SchemaNode(BoundedFloat(), missing=None)
    accuracy = colander.SchemaNode(colander.Float(), missing=None)
    fallback = OptionalNode(colander.String(), missing=None)

    def deserialize(self, data):
        data = super(UnwiredlabsV1ResultSchema, self).deserialize(data)

        # The API always returns 200 Ok responses, but uses the
        # status/message fields to indicate failures.
        status = data.get("status", None)
        if status != "ok":
            message = data.get("message", None)
            if message == "No matches found":
                # Fabricate a not found
                return {
                    "accuracy": None,
                    "fallback": None,
                    "lat": None,
                    "lon": None
                }

            raise colander.Invalid("Error response, message: %s" % message)

        # Check required fields for status==ok responses
        for field in ("lat", "lon", "accuracy"):
            if data.get(field, None) is None:
                raise colander.Invalid("Missing required field: %s" % field)

        fallback = data.get("fallback", None)
        if fallback != "lacf":
            fallback = None

        return {
            "accuracy": data["accuracy"],
            "fallback": fallback,
            "lat": data["lat"],
            "lon": data["lon"],
        }
Beispiel #14
0
class IchnaeaV1ResultSchema(RenamingMappingSchema):
    @colander.instantiate()
    class location(RenamingMappingSchema):

        lat = colander.SchemaNode(BoundedFloat())
        lng = colander.SchemaNode(BoundedFloat(), to_name="lon")

    accuracy = colander.SchemaNode(colander.Float())
    fallback = OptionalNode(colander.String(), missing=None)

    def deserialize(self, data):
        data = super(IchnaeaV1ResultSchema, self).deserialize(data)
        fallback = data.get("fallback", None)
        if fallback != "lacf":
            fallback = None
        return {
            "accuracy": data["accuracy"],
            "fallback": fallback,
            "lat": data["location"]["lat"],
            "lon": data["location"]["lon"],
        }
Beispiel #15
0
class IchnaeaV1ResultSchema(RenamingMappingSchema):
    @colander.instantiate()
    class location(RenamingMappingSchema):  # NOQA

        lat = colander.SchemaNode(BoundedFloat())
        lng = colander.SchemaNode(BoundedFloat(), to_name='lon')

    accuracy = colander.SchemaNode(colander.Float())
    fallback = OptionalNode(colander.String(), missing=None)

    def deserialize(self, data):
        data = super(IchnaeaV1ResultSchema, self).deserialize(data)
        fallback = data.get('fallback', None)
        if fallback != 'lacf':
            fallback = None
        return {
            'accuracy': data['accuracy'],
            'fallback': fallback,
            'lat': data['location']['lat'],
            'lon': data['location']['lon'],
        }
Beispiel #16
0
        class SequenceItem(OptionalMappingSchema):

            macAddress = OptionalNode(colander.String())
            age = OptionalNode(colander.Integer())
            name = OptionalNode(colander.String())
            signalStrength = OptionalNode(colander.Integer())
Beispiel #17
0
    class fallbacks(OptionalMappingSchema):  # NOQA

        lacf = OptionalNode(colander.Boolean())