# # # patch "dws/dws.py" # from [cc67b5fbce796506d59263f574c641b2e4350aa2] # to [42db972f333461d07a15be7090a34f9314eb295b] # # patch "setup.py" # from [57f5630c7a5d708b66fe640272304a3f7eb6c2de] # to [0330702aab0e264622587bc829d9cb57205dd4a2] # ============================================================ --- dws/dws.py cc67b5fbce796506d59263f574c641b2e4350aa2 +++ dws/dws.py 42db972f333461d07a15be7090a34f9314eb295b @@ -15,16 +15,19 @@ import re class Connection: - def __init__(self, base, path=""): + def __init__(self, base, path="", verbosity=0): self.base = base self.path = path + self.verbosity = verbosity (scheme, host, path, query, frag) = urlparse.urlsplit(self.base, "http") if scheme not in ("http","https"): raise Exception("bad scheme: http,https are supported") self.host = host if scheme == "http": self.conn = httplib.HTTPConnection(host) + self.verbose(1,"http connection to %s" % host) else: - self.conn = httplib.HTTPSConnection(host) + self.conn = httplib.HTTPSConnection(host) + self.verbose(1,"https connection to %s" % host) self.baseUrl = "/" + path def request(self, what, method="GET", postData = "", **kwargs): @@ -40,9 +43,10 @@ theUrl += d + k + "=" + str(v) d = "&" if postData: - self.verbose( "requesting %s (POST %i bytes)" % (theUrl, len(postData)) ) + self.verbose( 1, "requesting %s (POST %i bytes)" % (theUrl, len(postData)) ) else: - self.verbose( "requesting %s" % theUrl ) + self.verbose( 1, "requesting %s" % theUrl ) + r = None if self.conn: headers = { 'Connection': 'keep-alive' @@ -53,7 +57,7 @@ self.conn.request("GET", theUrl, headers = headers) req = self.conn.getresponse() try: - return str(req.read()) + r = str(req.read()) except Exception,e: self.error( "request failed (%s): %s" %(theUrl, str(e)) ) raise @@ -62,20 +66,21 @@ req = urllib2.Request( url=theUrl, data = postData ) else: req = urllib2.Request( url=theUrl ) - + try: f = urllib2.urlopen(req) r = str(f.read()) except Exception,e: self.error( "request failed (%s): %s" %(theUrl, str(e)) ) raise - return r - + self.verbose(2,"'%s': readed %i bytes" % (theUrl, len(r))) + return r + def clear(self): self.request("clear") - + def list(self): - allFiles = self.request("list_files").split("\n")[0:-1] + allFiles = self.request("list_files").split("\n")[0:-1] plen = len(self.path) if plen == 0: return allFiles r = [] @@ -95,16 +100,16 @@ m = self.matchSimpleValue.match(line) if not m: self.warning( "stat: unknown line: '%s'" % line) - continue + continue result[m.group(1)] = m.group(2) if not result: raise Exception("DWS FATAL ERROR: bad 'stat' response for file '%s'" % name) return result - + def get(self,name): realName = self.path + name return self.request("get", n = realName) - + def getParts(self, name, parts): realName = self.path + name partsArg = ",".join( [ "%i:%i" % (off, size) for off, size in parts ] ) @@ -113,16 +118,17 @@ def put(self,name, content): realName = self.path + name return self.request("put", n = realName, postData=content) - + def append(self, name, content): - realName = self.path + name + realName = self.path + name return self.request("append", n = realName, postData=content) def error(self, msg): print >> sys.stderr, "dws: error: %s" % msg - def verbose(self, msg): - pass + def verbose(self, level, msg): + if level <= self.verbosity: + print >> sys.stderr, "dws: info %i: %s" % (level,msg) def warning(self, msg): print >> sys.stderr, "dws: warning: %s" % msg ============================================================ --- setup.py 57f5630c7a5d708b66fe640272304a3f7eb6c2de +++ setup.py 0330702aab0e264622587bc829d9cb57205dd4a2 @@ -17,7 +17,7 @@ and one-way (pull) via http(s) and ftp.""" license = "LGPL" -version = "0.0.1" +version = "0.0.3" _authors = [ 'Nathaniel Smith', 'Zbynek Winkler', 'Riccardo "rghetta"',