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
36 if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32):
37 ret += "%%%02X" % ord(c)
42 class urlerror(ValueError):
48 raise urlerror("Protocol not found in absolute URL `%s'" % url)
50 l = url.find("/", p + 3)
52 raise urlerror("Local part not found in absolute URL `%s'" % url)
61 return proto, host, local, query
63 def consurl(proto, host, local, query = ""):
64 if len(local) < 1 and local[0] != '/':
65 raise urlerror("Local part of URL must begin with a slash")
66 ret = "%s://%s%s" % (proto, host, local)
71 def appendurl(url, other):
74 proto, host, local, query = parseurl(url)
75 if len(other) > 0 and other[0] == '/':
76 return consurl(proto, host, other)
79 return consurl(proto, host, local[:p + 1] + other)
82 host = req.ihead.get("Host", None)
84 raise Exception("Could not reconstruct URL because no Host header was sent")
89 raise Exception("Malformed local part when reconstructing URL")
90 return "%s://%s%s" % (proto, host, req.uri)
92 def parstring(pars = {}, **augment):
100 if buf != "": buf += "&"
101 buf += urlq(key) + "=" + urlq(str(val))
103 if buf != "": buf += "&"
104 buf += urlq(key) + "=" + urlq(str(augment[key]))