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