From: <bel...@us...> - 2003-03-29 00:54:19
|
Update of /cvsroot/btplusplus/BT++/src/core In directory sc8-pr-cvs1:/tmp/cvs-serv24784/src/core Modified Files: zurllib.py Log Message: Implementation of UpdateManager. Makes sure updates don't happen too fast if two automatic updaters collide (aka TimedUpdate and HTTP refreshs). Implemented FancyZURLOpener with zlib compression (used for InfoManager). Some fixes Index: zurllib.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/core/zurllib.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** zurllib.py 28 Mar 2003 12:44:28 -0000 1.1 --- zurllib.py 29 Mar 2003 00:54:15 -0000 1.2 *************** *** 18,21 **** --- 18,80 ---- DEBUG=0 + # BEGIN - Added by Tobias Minich 3/28/2003 + class FancyZURLopener(FancyURLopener): + def open_http(self, url, data=None): + """Use HTTP protocol.""" + import httplib + user_passwd = None + if type(url) is types.StringType: + host, selector = splithost(url) + if host: + user_passwd, host = splituser(host) + host = unquote(host) + realhost = host + else: + host, selector = url + urltype, rest = splittype(selector) + url = rest + user_passwd = None + if urltype.lower() != 'http': + realhost = None + else: + realhost, rest = splithost(rest) + if realhost: + user_passwd, realhost = splituser(realhost) + if user_passwd: + selector = "%s://%s%s" % (urltype, realhost, rest) + if proxy_bypass(realhost): + host = realhost + + #print "proxy via http:", host, selector + if not host: raise IOError, ('http error', 'no host given') + if user_passwd: + import base64 + auth = base64.encodestring(user_passwd).strip() + else: + auth = None + h = httplib.HTTP(host) + if data is not None: + h.putrequest('POST', selector) + h.putheader('Content-type', 'application/x-www-form-urlencoded') + h.putheader('Content-length', '%d' % len(data)) + else: + h.putrequest('GET', selector) + if auth: h.putheader('Authorization', 'Basic %s' % auth) + if realhost: h.putheader('Host', realhost) + for args in self.addheaders: apply(h.putheader, args) + h.putheader("Accept-Encoding","gzip") + h.endheaders() + if data is not None: + h.send(data) + errcode, errmsg, headers = h.getreply() + fp = h.getfile() + if errcode == 200: + return addinfourldecompress(fp, headers, "http:" + url) + else: + if data is None: + return self.http_error(url, fp, errcode, errmsg, headers) + else: + return self.http_error(url, fp, errcode, errmsg, headers, data) + # END - Added by Tobias Minich 3/28/2003 class HTTPContentEncodingHandler(HTTPHandler): |