3 class HTTPStatusError(Exception):
4 def __init__(self
, code
, msg
=""):
5 self
.status
= "%s %s" % (str(code
), str(msg
))
7 self
.status
= self
.status
.replace('\n','').replace('\r','')
8 self
.headers
= [('Content-Type', 'text/plain')]
14 class FileNotFoundError(Exception):
15 def __init__(self
, file):
18 return "File Not Found: %s" % self
.file
22 class HTTPRedirect(HTTPStatusError
):
23 def __init__(self
, url
=None, headers
=None, status
="303 Other"):
25 self
.headers
= [('Content-Type','text/plain')]
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):
42 class LoginError(Exception):