Don't automatically convert API key to uppercase
[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     # apparently the api key CAN contain lower case characters...
25     #elif not api_key.isupper():
26     #    raise ValidationError("API Key must only contain upper-case characters")
27
28     return True
29
30
31 def uid(uid):
32     """
33     validates an EVE Online uid, throws ValidationError exception if the
34     format is invalid.
35     """
36     #TODO: anything else we can do to validate the uid?
37
38     if not uid.isdigit():
39         raise ValidationError("UID must be a number")
40     if len(uid) < 1:
41         raise ValidationError("Missing UID")