4 400: ("Bad Request", "Invalid HTTP request."),
5 401: ("Unauthorized", "Authentication must be provided for the requested resource."),
6 403: ("Forbidden", "You are not authorized to request the requested resource."),
7 404: ("Not Found", "The requested resource was not found."),
8 405: ("Method Not Allowed", "The request method is not recognized or permitted by the requested resource."),
9 500: ("Server Error", "An internal error occurred."),
10 501: ("Not Implemented", "The requested functionality has not been implemented."),
11 503: ("Service Unavailable", "Service is being denied at this time."),
15 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(ts))
20 if tz[0] != " " or (tz[1] != "+" and tz[1] != "-") or not tz[2:].isdigit():
23 tz = (((tz / 100) * 60) + (tz % 100)) * 60
24 return time.mktime(time.strptime(dstr, "%a, %d %b %Y %H:%M:%S")) - tz - time.altzone
28 while p < len(hstr) and hstr[p].isspace():
59 return buf.strip(), pws(p)
61 val, p = token(p, ";")
68 if k == "" or hstr[p:p + 1] != '=':
91 if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32):
92 ret += "%%%02X" % ord(c)
97 class urlerror(ValueError):
103 raise urlerror("Protocol not found in absolute URL `%s'" % url)
105 l = url.find("/", p + 3)
107 raise urlerror("Local part not found in absolute URL `%s'" % url)
114 query = local[q + 1:]
116 return proto, host, local, query
118 def consurl(proto, host, local, query=""):
119 if len(local) < 1 and local[0] != '/':
120 raise urlerror("Local part of URL must begin with a slash")
121 ret = "%s://%s%s" % (proto, host, local)
126 def appendurl(url, other):
129 proto, host, local, query = parseurl(url)
130 if len(other) > 0 and other[0] == '/':
131 return consurl(proto, host, other)
134 return consurl(proto, host, local[:p + 1] + other)
137 host = req.ihead.get("Host", None)
139 raise Exception("Could not reconstruct URL because no Host header was sent")
143 if req.uri[0] != '/':
144 raise Exception("Malformed local part when reconstructing URL")
145 return "%s://%s%s" % (proto, host, req.uri)
147 def parstring(pars={}, **augment):
155 if buf != "": buf += "&"
156 buf += urlq(key) + "=" + urlq(str(val))
158 if buf != "": buf += "&"
159 buf += urlq(key) + "=" + urlq(str(augment[key]))
162 def parurl(url, pars={}, **augment):
163 qs = parstring(pars, **augment)
165 return url + "?" + qs