2 400: ("Bad Request", "Your issued HTTP request is invalid."),
3 403: ("Forbidden", "You are not authorized to view the requested resource."),
4 404: ("Not Found", "The requested resource was not found."),
5 500: ("Server Error", "An internal error occurred.")
9 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(ts))
14 if tz[0] != " " or (tz[1] != "+" and tz[1] != "-") or not tz[2:].isdigit():
17 tz = (((tz / 100) * 60) + (tz % 100)) * 60
18 return time.mktime(time.strptime(dstr, "%a, %d %b %Y %H:%M:%S")) - tz - time.altzone
22 while p < len(hstr) and hstr[p].isspace():
53 return buf.strip(), pws(p)
55 val, p = token(p, ";")
62 if k == "" or hstr[p:p + 1] != '=':
85 if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32):
86 ret += "%%%02X" % ord(c)
91 class urlerror(ValueError):
97 raise urlerror("Protocol not found in absolute URL `%s'" % url)
99 l = url.find("/", p + 3)
101 raise urlerror("Local part not found in absolute URL `%s'" % url)
108 query = local[q + 1:]
110 return proto, host, local, query
112 def consurl(proto, host, local, query = ""):
113 if len(local) < 1 and local[0] != '/':
114 raise urlerror("Local part of URL must begin with a slash")
115 ret = "%s://%s%s" % (proto, host, local)
120 def appendurl(url, other):
123 proto, host, local, query = parseurl(url)
124 if len(other) > 0 and other[0] == '/':
125 return consurl(proto, host, other)
128 return consurl(proto, host, local[:p + 1] + other)
131 host = req.ihead.get("Host", None)
133 raise Exception("Could not reconstruct URL because no Host header was sent")
137 if req.uri[0] != '/':
138 raise Exception("Malformed local part when reconstructing URL")
139 return "%s://%s%s" % (proto, host, req.uri)
141 def parstring(pars = {}, **augment):
149 if buf != "": buf += "&"
150 buf += urlq(key) + "=" + urlq(str(val))
152 if buf != "": buf += "&"
153 buf += urlq(key) + "=" + urlq(str(augment[key]))