2 400: ("Bad Request", "Invalid HTTP request."),
3 401: ("Unauthorized", "Authentication must be provided for the requested resource."),
4 403: ("Forbidden", "You are not authorized to request the requested resource."),
5 404: ("Not Found", "The requested resource was not found."),
6 405: ("Method Not Allowed", "The request method is not recognized or permitted by the requested resource."),
7 500: ("Server Error", "An internal error occurred."),
8 501: ("Not Implemented", "The requested functionality has not been implemented."),
9 503: ("Service Unavailable", "Service is being denied at this time."),
13 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(ts))
18 if tz[0] != " " or (tz[1] != "+" and tz[1] != "-") or not tz[2:].isdigit():
21 tz = (((tz / 100) * 60) + (tz % 100)) * 60
22 return time.mktime(time.strptime(dstr, "%a, %d %b %Y %H:%M:%S")) - tz - time.altzone
26 while p < len(hstr) and hstr[p].isspace():
57 return buf.strip(), pws(p)
59 val, p = token(p, ";")
66 if k == "" or hstr[p:p + 1] != '=':
89 if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32):
90 ret += "%%%02X" % ord(c)
95 class urlerror(ValueError):
101 raise urlerror("Protocol not found in absolute URL `%s'" % url)
103 l = url.find("/", p + 3)
105 raise urlerror("Local part not found in absolute URL `%s'" % url)
112 query = local[q + 1:]
114 return proto, host, local, query
116 def consurl(proto, host, local, query=""):
117 if len(local) < 1 and local[0] != '/':
118 raise urlerror("Local part of URL must begin with a slash")
119 ret = "%s://%s%s" % (proto, host, local)
124 def appendurl(url, other):
127 proto, host, local, query = parseurl(url)
128 if len(other) > 0 and other[0] == '/':
129 return consurl(proto, host, other)
132 return consurl(proto, host, local[:p + 1] + other)
135 host = req.ihead.get("Host", None)
137 raise Exception("Could not reconstruct URL because no Host header was sent")
141 if req.uri[0] != '/':
142 raise Exception("Malformed local part when reconstructing URL")
143 return "%s://%s%s" % (proto, host, req.uri)
145 def parstring(pars={}, **augment):
153 if buf != "": buf += "&"
154 buf += urlq(key) + "=" + urlq(str(val))
156 if buf != "": buf += "&"
157 buf += urlq(key) + "=" + urlq(str(augment[key]))
160 def parurl(url, pars={}, **augment):
161 qs = parstring(pars, **augment)
163 return url + "?" + qs