from colander import MappingSchema, SchemaNode, SequenceSchema
from colander import Decimal, Integer, String, OneOf


class CellSchema(MappingSchema):
    mcc = SchemaNode(Integer(), location="body", type='int')
    mnc = SchemaNode(Integer(), location="body", type='int')
    lac = SchemaNode(Integer(), location="body", type='int')
    cid = SchemaNode(Integer(), location="body", type='int')
    signal = SchemaNode(Integer(), location="body", type='int', missing=0)


class CellsSchema(SequenceSchema):
    cell = CellSchema()


class WifiSchema(MappingSchema):
    mac = SchemaNode(String(), location="body", type='str')
    channel = SchemaNode(Integer(), location="body", type='int', missing=0)
    noise = SchemaNode(Integer(), location="body", type='int', missing=0)
    signal = SchemaNode(Integer(), location="body", type='int', missing=0)


class WifisSchema(SequenceSchema):
    wifi = WifiSchema()


class SearchSchema(MappingSchema):
    radio = SchemaNode(String(), location="body", type='str',
                       validator=OneOf(['gsm', 'cdma']), missing='gsm')
    cell = CellsSchema(missing=())
    wifi = WifisSchema(missing=())


class MeasureSchema(MappingSchema):
    lat = SchemaNode(Decimal(quant="1.000000"), location="path")
    lon = SchemaNode(Decimal(quant="1.000000"), location="path")
    radio = SchemaNode(String(), location="body", type='str',
                       validator=OneOf(['gsm', 'cdma']), missing='gsm')
    cell = CellsSchema(missing=())
    wifi = WifisSchema(missing=())

@@ -108,17 +108,24 @@
 g, OneOf
+, Range
 %0A
-
 %0A%0Aclass 
@@ -174,32 +174,53 @@
 aNode(Integer(),
+%0A                    
  location=%22body%22
@@ -227,24 +227,50 @@
 , type='int'
+, validator=Range(0, 1000)
 )%0A    mnc = 
@@ -282,32 +282,53 @@
 aNode(Integer(),
+%0A                    
  location=%22body%22
@@ -335,24 +335,51 @@
 , type='int'
+, validator=Range(0, 32767)
 )%0A    lac = 

validate mcc/mnc ranges on input