removed main.cfg, not used anywhere
[limo.git] / errors.py
blob25747eab7c87d0c7aba06bbece6a2bf965c114a6
1 import datetime
3 class HTTPStatusError(Exception):
4 def __init__(self, code, msg=""):
5 self.status = "%s %s" % (str(code), str(msg))
6 # no new lines allowed
7 self.status = self.status.replace('\n','').replace('\r','')
8 self.headers = [('Content-Type', 'text/plain')]
9 def __str__(self):
10 return self.status
11 def __repr__(self):
12 return self.status
14 class FileNotFoundError(Exception):
15 def __init__(self, file):
16 self.file = file
17 def __str__(self):
18 return "File Not Found: %s" % self.file
19 def __repr__(self):
20 return str(self)
22 class HTTPRedirect(HTTPStatusError):
23 def __init__(self, url=None, headers=None, status="303 Other"):
24 self.status = status
25 self.headers = [('Content-Type','text/plain')]
26 if url is not None:
27 # do not allow newlines in the url, to prevent header injection
28 url = url.replace('\n','').replace('\r', '')
29 self.headers = self.headers + [('Location',url),]
30 if headers is not None:
31 self.headers = self.headers + headers
33 class DeleteCookie(HTTPRedirect):
34 def __init__(self, name):
35 expires = "%s=; expires=%s" % (name, (datetime.datetime.utcnow()-datetime.timedelta(days=1)).strftime("%a, %d-%b-%Y %H:%M:%S %Z GMT"))
36 HTTPRedirect.__init__(self, headers=[('Set-Cookie',expires)])
39 class NoSuchSessionException(Exception):
40 pass
42 class LoginError(Exception):
43 pass