diff options
| author | Foram Katharotiya (OpenERP) <fka@tinyerp.com> | 2012-08-13 15:55:19 +0530 |
|---|---|---|
| committer | Foram Katharotiya (OpenERP) <fka@tinyerp.com> | 2012-08-13 15:55:19 +0530 |
| commit | 1bf105837ed5cad0715b20ef501e7147af87c7ef (patch) | |
| tree | 7a292e7311c91e6e0acafe7359dd1e7f1d7a4cb9 /addons/document_webdav/test_davclient.py | |
| parent | dae19bc174b3962088bf4b9fd0701f80ab8f8e5e (diff) | |
| parent | 03e6f93fcffa7775754bf5198478b5927d8ffe1c (diff) | |
[MERGE]merge with lp:~openerp-dev/openobject-addons/trunk-message-sub-type-apa
bzr revid: fka@tinyerp.com-20120813102519-9h3fpqj29dse2p3m
Diffstat (limited to 'addons/document_webdav/test_davclient.py')
| -rwxr-xr-x | addons/document_webdav/test_davclient.py | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/addons/document_webdav/test_davclient.py b/addons/document_webdav/test_davclient.py index a4dda231bd8..f1f2e58c835 100755 --- a/addons/document_webdav/test_davclient.py +++ b/addons/document_webdav/test_davclient.py @@ -69,9 +69,9 @@ class PersistentTransport(Transport): host, extra_headers, x509 = Transport.get_host_info(self,host) if extra_headers == None: extra_headers = [] - + extra_headers.append( ( 'Connection', 'keep-alive' )) - + return host, extra_headers, x509 def _parse_response(self, file, sock, response): @@ -122,9 +122,9 @@ class PersistentTransport(Transport): resp = h._conn.getresponse() # TODO: except BadStatusLine, e: - + errcode, errmsg, headers = resp.status, resp.reason, resp.msg - + if errcode != 200: raise ProtocolError( @@ -145,7 +145,7 @@ class PersistentTransport(Transport): class CompressedTransport(PersistentTransport): def send_content(self, connection, request_body): connection.putheader("Content-Type", "text/xml") - + if len(request_body) > 512 or True: buffer = StringIO.StringIO() output = gzip.GzipFile(mode='wb', fileobj=buffer) @@ -176,7 +176,7 @@ class SafePersistentTransport(PersistentTransport): class AuthClient(object): def getAuth(self, atype, realm): raise NotImplementedError("Cannot authenticate for %s" % atype) - + def resolveFailedRealm(self, realm): """ Called when, using a known auth type, the realm is not in cache """ @@ -195,7 +195,7 @@ class BasicAuthClient(AuthClient): _logger.debug("missing key: \"%s\"" % realm) self.resolveFailedRealm(realm) return 'Basic '+ self._realm_dict[realm] - + def addLogin(self, realm, username, passwd): """ Add some known username/password for a specific login. This function should be called once, for each realm @@ -210,7 +210,7 @@ class BasicAuthClient(AuthClient): class addAuthTransport: """ Intermediate class that authentication algorithm to http transport """ - + def setAuthClient(self, authobj): """ Set the authentication client object. This method must be called before any request is issued, that @@ -218,7 +218,7 @@ class addAuthTransport: """ assert isinstance(authobj, AuthClient) self._auth_client = authobj - + def request(self, host, handler, request_body, verbose=0): # issue XML-RPC request @@ -226,7 +226,7 @@ class addAuthTransport: h = self.make_connection(host) if verbose: h.set_debuglevel(1) - + tries = 0 atype = None realm = None @@ -246,7 +246,7 @@ class addAuthTransport: resp = h._conn.getresponse() # except BadStatusLine, e: tries += 1 - + if resp.status == 401: if 'www-authenticate' in resp.msg: (atype,realm) = resp.msg.getheader('www-authenticate').split(' ',1) @@ -258,7 +258,7 @@ class addAuthTransport: _logger.debug("Resp: %r %r", resp.version,resp.isclosed(), resp.will_close) _logger.debug("Want to do auth %s for realm %s", atype, realm) if atype != 'Basic': - raise ProtocolError(host+handler, 403, + raise ProtocolError(host+handler, 403, "Unknown authentication method: %s" % atype, resp.msg) continue # with the outer while loop else: @@ -268,17 +268,17 @@ class addAuthTransport: if resp.status != 200: raise ProtocolError( host + handler, resp.status, resp.reason, resp.msg ) - + self.verbose = verbose - + try: sock = h._conn.sock except AttributeError: sock = None - + return self._parse_response(h.getfile(), sock, resp) - raise ProtocolError(host+handler, 403, "No authentication",'') + raise ProtocolError(host+handler, 403, "No authentication.",'') class PersistentAuthTransport(addAuthTransport,PersistentTransport): pass @@ -302,7 +302,7 @@ class HTTPSConnection(httplib.HTTPSConnection): self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ca_certs=ca_certs, cert_reqs=cert_reqs) - + def getpeercert(self): import ssl @@ -316,14 +316,14 @@ class HTTPSConnection(httplib.HTTPSConnection): if cert[0-lf] != '\n': cert = cert[:0-lf]+'\n'+cert[0-lf:] _logger.debug("len-footer: %s cert: %r", lf, cert[0-lf]) - + return cert class DAVClient(object): """An instance of a WebDAV client, connected to the OpenERP server """ - + def __init__(self, user=None, passwd=None, dbg=0, use_ssl=False, useragent=False, timeout=None): if use_ssl: self.host = config.get_misc('httpsd', 'interface', False) @@ -353,10 +353,10 @@ class DAVClient(object): def get_creds(self, obj, cr, uid): """Read back the user credentials from cr, uid - + @param obj is any orm object, in order to use its pool @param uid is the numeric id, which we will try to reverse resolve - + note: this is a hackish way to get the credentials. It is expected to break if "base_crypt" is used. """ @@ -366,7 +366,7 @@ class DAVClient(object): self.user = res[0]['login'] self.passwd = res[0]['password'] if self.passwd.startswith('$1$'): - # md5 by base crypt. We cannot decode, wild guess + # md5 by base crypt. We cannot decode, wild guess # that passwd = login self.passwd = self.user return True @@ -402,7 +402,7 @@ class DAVClient(object): r1 = conn.getresponse() except httplib.BadStatusLine, bsl: log.warning("Bad status line: %s", bsl.line) - raise Exception('Bad status line') + raise Exception('Bad status line.') if r1.status == 401: # and r1.headers: if 'www-authenticate' in r1.msg: (atype,realm) = r1.msg.getheader('www-authenticate').split(' ',1) @@ -415,7 +415,7 @@ class DAVClient(object): auths = base64.encodestring(self.user + ':' + self.passwd) if auths[-1] == "\n": auths = auths[:-1] - hdrs['Authorization']= 'Basic '+ auths + hdrs['Authorization']= 'Basic '+ auths #sleep(1) conn.request(method, path, body, hdrs ) r1 = conn.getresponse() @@ -437,7 +437,7 @@ class DAVClient(object): doc = xml.dom.minidom.parseString(data1) _logger.debug("XML Body:\n %s", doc.toprettyxml(indent="\t")) except Exception: - _logger.warning("could not print xml", exc_info=True) + _logger.warning("Cannot print XML.", exc_info=True) pass conn.close() return r1.status, r1.msg, data1 @@ -475,10 +475,10 @@ class DAVClient(object): assert s == 200, "Status: %r" % s assert 'OPTIONS' in m.getheader('Allow') _logger.debug('Options: %r', m.getheader('Allow')) - + if expect: self._assert_headers(expect, m) - + def _parse_prop_response(self, data): """ Parse a propfind/propname response """ @@ -488,7 +488,7 @@ class DAVClient(object): if node.nodeType == node.TEXT_NODE: rc.append(node.data) return ''.join(rc) - + def getElements(node, namespaces=None, strict=False): for cnod in node.childNodes: if cnod.nodeType != node.ELEMENT_NODE: @@ -534,10 +534,10 @@ class DAVClient(object): rstatus = int(sta) else: _logger.debug("What is <%s> inside a <propstat>?", pno.tagName) - + else: _logger.debug("Unknown node: %s", cno.tagName) - + res.setdefault(href,[]).append((status, res_nss)) return res @@ -558,7 +558,7 @@ class DAVClient(object): propstr += '<ns%d:%s xmlns:ns%d="%s" />' %(nscount, p, nscount, ns) nscount += 1 propstr += '</prop>' - + body="""<?xml version="1.0" encoding="utf-8"?> <propfind xmlns="DAV:">%s</propfind>""" % propstr hdrs = { 'Content-Type': 'text/xml; charset=utf-8', @@ -566,7 +566,7 @@ class DAVClient(object): 'Depth': depth, } - s, m, d = self._http_request(self.davpath + path, method='PROPFIND', + s, m, d = self._http_request(self.davpath + path, method='PROPFIND', hdrs=hdrs, body=body) assert s == 207, "Bad status: %s" % s ctype = m.getheader('Content-Type').split(';',1)[0] @@ -578,7 +578,7 @@ class DAVClient(object): else: assert len(res) >= 1 return res - + def gd_propname(self, path, depth=0): body="""<?xml version="1.0" encoding="utf-8"?> @@ -587,7 +587,7 @@ class DAVClient(object): 'Accept': 'text/xml', 'Depth': depth } - s, m, d = self._http_request(self.davpath + path, method='PROPFIND', + s, m, d = self._http_request(self.davpath + path, method='PROPFIND', hdrs=hdrs, body=body) assert s == 207, "Bad status: %s" % s ctype = m.getheader('Content-Type').split(';',1)[0] @@ -605,7 +605,7 @@ class DAVClient(object): def gd_lsl(self, path): """ Return a list of 'ls -l' kind of data for a folder - + This is based on propfind. """ @@ -616,7 +616,7 @@ class DAVClient(object): propnames = [ l[1] for l in lspairs] propres = self.gd_propfind(path, props=propnames, depth=1) - + res = [] for href, pr in propres.items(): lsline = {} @@ -638,9 +638,9 @@ class DAVClient(object): lsline[lsp[0]] = lsp[2] else: _logger.debug("Strange status: %s", st) - + res.append(lsline) - + return res def gd_get(self, path, crange=None, mime=None, compare=None): @@ -651,7 +651,7 @@ class DAVClient(object): if isinstance(crange, tuple): crange = [crange,] if not isinstance(crange, list): - raise TypeError("Range must be a tuple or list of tuples") + raise TypeError("Range must be a tuple or list of tuples.") rs = [] for r in crange: rs.append('%d-%d' % r) @@ -683,13 +683,13 @@ class DAVClient(object): return ctype, rrange, d def gd_put(self, path, body=None, srcpath=None, mime=None, noclobber=False, ): - """ HTTP PUT + """ HTTP PUT @param noclobber will prevent overwritting a resource (If-None-Match) @param mime will set the content-type """ hdrs = { } if not (body or srcpath): - raise ValueError("PUT must have something to send") + raise ValueError("PUT must have something to send.") if (not body) and srcpath: fd = open(srcpath, 'rb') body = fd.read() @@ -698,7 +698,7 @@ class DAVClient(object): hdrs['Content-Type'] = mime if noclobber: hdrs['If-None-Match'] = '*' - s, m, d = self._http_request(self.davpath + path, method='PUT', + s, m, d = self._http_request(self.davpath + path, method='PUT', hdrs=hdrs, body=body) assert s == (201), "Bad status: %s" % s etag = m.getheader('ETag') |
