76cfb9edc965cd1150633d7da8b37e3842bf5c0b
[mevemon] / package / src / validation.py
1 """ This module contains all our input validation functions """
2
3 KEY_SIZE = 64
4
5 class ValidationError(StandardError):
6     """ Exception that is raised if input validation fails
7     """
8     def __init__(self, message):
9         StandardError.__init__(self)
10         self.message = message
11
12     def __str__(self):
13         return repr(self.message)
14
15
16
17 def validate_api_key(api_key):
18     """ Validates an EVE api key. throws ValidationError exception if the
19         format is invalid.
20     """
21     #TODO: anything else we can do to validate the api key?
22     
23     if len(api_key) != KEY_SIZE:
24         raise ValidationError("API Key must be %s characters" % KEY_SIZE)
25     elif not api_key.isalnum():
26         raise ValidationError("API Key must only contain alphanumeric " +\
27                               "characters")
28
29
30 def validate_uid(uid):
31     """ Validates an EVE Online uid, throws ValidationError exception if the
32         format is invalid.
33     """
34     #TODO: anything else we can do to validate the uid?
35
36     if not uid.isdigit():
37         raise ValidationError("UID must be a number")
38     if len(uid) < 1:
39         raise ValidationError("Missing UID")