Removed legacy key support, added custom key support
[mevemon] / package / src / validation.py
1 """ This module contains all our input validation functions """
2 from constants import MIN_VER_CODE_SIZE, MAX_VER_CODE_SIZE
3
4 class ValidationError(StandardError):
5     """ Exception that is raised if input validation fails
6     """
7     def __init__(self, message):
8         StandardError.__init__(self)
9         self.message = message
10
11     def __str__(self):
12         return repr(self.message)
13
14
15 def validate_key_id(key_id):
16
17     """ Validates an EVE key ID. throws ValidationError exception if
18     the format is invalid.
19     """
20
21     #TODO: anything else we can do to validate the api key?
22
23     # I don't know enough about the keyID yet. seems to be only
24     # numeric.  The 2 I made were 705 and 706 respectively. I think
25     # they are just incrementing numbers. But I won't assume that
26     # yet...
27     
28     pass
29
30
31 def validate_ver_code(ver_code):
32
33     """ Validates an EVE Online verification code, throws
34     ValidationError exception if the format is invalid.
35
36      """
37
38     # What we DO know about the verification code is that it has to be
39     # at least 20 digits and at most 64. Seems to be alphanumeric
40     # only.
41
42
43     if len(ver_code) < MIN_VER_CODE_SIZE or len(ver_code) > MAX_VER_CODE_SIZE:
44         raise ValidationError("Verification code must be from 20 to 64 "
45                               "characters.")
46