# Create the filters that we'll need mode_validate = Factory.create('mode', 'mode') history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test(plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result Factory.register(PlanValidator) class FilterValidator(BasicTypeValidator): label = 'filter' def __init__(self, fieldName, forbidNone=False): super(FilterValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int')
def _raiseError(self): raise BadType('', self.fieldName, self.label) class ListValidator(BasicTypeValidator): label = 'list' def __init__(self, fieldName, forbidNone=False): super(ListValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(ListValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, list): self._raiseError() return valueToTest Factory.register(ListValidator) class DictValidator(BasicTypeValidator): label = 'dict' def __init__(self, fieldName, forbidNone=False): super(DictValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(DictValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, dict): self._raiseError() return valueToTest Factory.register(DictValidator) class IntegerValidator(BasicTypeValidator):
history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test( plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result Factory.register(PlanValidator) class FilterValidator(BasicTypeValidator): label = 'filter' def __init__(self, fieldName, forbidNone=False): super(FilterValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int')
class ListValidator(BasicTypeValidator): label = 'list' def __init__(self, fieldName, forbidNone=False): super(ListValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(ListValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, list): self._raiseError() return valueToTest Factory.register(ListValidator) class DictValidator(BasicTypeValidator): label = 'dict' def __init__(self, fieldName, forbidNone=False): super(DictValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(DictValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, dict): self._raiseError() return valueToTest
def __init__(self, fieldName, forbidNone=False): super(ModeValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No mode provided") # Parse mode to string str_validate = Factory.create('string', 'string') mode = str_validate.test(valueToTest) # Verify that it is a valid value if mode != 'Instant' and mode != 'Bid': raise ValidationError('Mode must be Instant or Bid') return mode Factory.register(ModeValidator) class FeatureValidator(BasicTypeValidator): label = 'feature' def __init__(self, fieldName, forbidNone=False): super(FeatureValidator, self).__init__(fieldName, forbidNone) self.features = ['ItemID', 'ItemType', 'ItemRarity', 'ItemLevel', 'NumBuyOrders', 'NumSellOrders', 'BuyPrice', 'SellPrice', 'ZScoreBuyPrice', 'ZScoreSellPrice', 'MeanBuyPrice', 'MeanSellPrice', 'VarBuyPrice', 'VarSellPrice', 'MedianBuyPrice', 'MedianSellPrice', 'SlopeBuyPrice', 'SlopeSellPrice', 'CurrentFlipProfit', 'MeanProfit', 'VarProfit', 'MedianProfit', 'OurBuyPrice', 'NumConsidered'] def test(self, valueToTest): if valueToTest is None: