added some simple validation to 'add account' dialog
[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
25     return True
26
27
28 def uid(uid):
29     """
30     validates an EVE Online uid, throws ValidationError exception if the
31     format is invalid.
32     """
33     #TODO: anything else we can do to validate the uid?
34
35     if not uid.isdigit():
36         raise ValidationError("UID must be a number")
37     if len(uid) < 1:
38         raise ValidationError("Missing UID")