diff options
| author | Foram Katharotiya (OpenERP) <fka@tinyerp.com> | 2012-06-22 12:18:39 +0530 |
|---|---|---|
| committer | Foram Katharotiya (OpenERP) <fka@tinyerp.com> | 2012-06-22 12:18:39 +0530 |
| commit | 0c374a66bc3de5cdf48eb66b2078c0946aa045db (patch) | |
| tree | 50320ad4188001b50cb8b0dcd239cc121ad7ef48 /addons/document_webdav | |
| parent | e02d8a68ef8eba0ab3b6c084301e0b707e8402e6 (diff) | |
[IMP] Add logging at the top of python files
bzr revid: fka@tinyerp.com-20120622064839-llitm8szgikxznwr
Diffstat (limited to 'addons/document_webdav')
| -rw-r--r-- | addons/document_webdav/redirect.py | 6 | ||||
| -rwxr-xr-x | addons/document_webdav/test_davclient.py | 46 | ||||
| -rw-r--r-- | addons/document_webdav/webdav_server.py | 20 |
3 files changed, 39 insertions, 33 deletions
diff --git a/addons/document_webdav/redirect.py b/addons/document_webdav/redirect.py index 7bc0883f9e8..31f462bcbbe 100644 --- a/addons/document_webdav/redirect.py +++ b/addons/document_webdav/redirect.py @@ -24,9 +24,9 @@ import logging import urlparse from service.websrv_lib import FixSendError, HTTPHandler, HttpOptions from service.http_server import HttpLogHandler - +_logger = logging.getLogger(__name__) class RedirectHTTPHandler(HttpLogHandler, FixSendError, HttpOptions, HTTPHandler): - _logger = logging.getLogger('httpd.well-known') + _HTTP_OPTIONS = { 'Allow': ['OPTIONS', 'GET', 'HEAD', 'PROPFIND'] } redirect_paths = {} @@ -80,7 +80,7 @@ class RedirectHTTPHandler(HttpLogHandler, FixSendError, HttpOptions, HTTPHandler self.send_header("Content-Length", 0) self.end_headers() # Do we need a Cache-content: header here? - self._logger.debug("redirecting %s to %s", self.path, redir_path) + _logger.debug("redirecting %s to %s", self.path, redir_path) return None def do_PROPFIND(self): diff --git a/addons/document_webdav/test_davclient.py b/addons/document_webdav/test_davclient.py index 3c20cfed5b8..a62515de14e 100755 --- a/addons/document_webdav/test_davclient.py +++ b/addons/document_webdav/test_davclient.py @@ -43,7 +43,7 @@ from xmlrpclib import Transport, ProtocolError import StringIO import base64 -log = logging.getLogger('http-client') +_log = logging.getLogger(__name__) class HTTP11(httplib.HTTP): _http_vsn = 11 @@ -62,7 +62,7 @@ class PersistentTransport(Transport): if not self._http.has_key(host): host, extra_headers, x509 = self.get_host_info(host) self._http[host] = HTTP11(host) - log.debug("New connection to %s", host) + _log.debug("New connection to %s", host) return self._http[host] def get_host_info(self, host): @@ -170,7 +170,7 @@ class SafePersistentTransport(PersistentTransport): if not self._http.has_key(host): host, extra_headers, x509 = self.get_host_info(host) self._http[host] = httplib.HTTPS(host, None, **(x509 or {})) - log.debug("New connection to %s", host) + _log.debug("New connection to %s", host) return self._http[host] class AuthClient(object): @@ -191,8 +191,8 @@ class BasicAuthClient(AuthClient): return super(BasicAuthClient,self).getAuth(atype, realm) if not self._realm_dict.has_key(realm): - log.debug("realm dict: %r", self._realm_dict) - log.debug("missing key: \"%s\"" % realm) + _log.debug("realm dict: %r", self._realm_dict) + _log.debug("missing key: \"%s\"" % realm) self.resolveFailedRealm(realm) return 'Basic '+ self._realm_dict[realm] @@ -239,7 +239,7 @@ class addAuthTransport: # This line will bork if self.setAuthClient has not # been issued. That is a programming error, fix your code! auths = self._auth_client.getAuth(atype, realm) - log.debug("sending authorization: %s", auths) + _log.debug("sending authorization: %s", auths) h.putheader('Authorization', auths) self.send_content(h, request_body) @@ -255,8 +255,8 @@ class addAuthTransport: log.warning("Why have data on a 401 auth. message?") if realm.startswith('realm="') and realm.endswith('"'): realm = realm[7:-1] - log.debug("Resp: %r %r", resp.version,resp.isclosed(), resp.will_close) - log.debug("Want to do auth %s for realm %s", atype, realm) + _log.debug("Resp: %r %r", resp.version,resp.isclosed(), resp.will_close) + _log.debug("Want to do auth %s for realm %s", atype, realm) if atype != 'Basic': raise ProtocolError(host+handler, 403, "Unknown authentication method: %s" % atype, resp.msg) @@ -315,7 +315,7 @@ class HTTPSConnection(httplib.HTTPSConnection): lf = (len(ssl.PEM_FOOTER)+1) if cert[0-lf] != '\n': cert = cert[:0-lf]+'\n'+cert[0-lf:] - log.debug("len-footer: %s cert: %r", lf, cert[0-lf]) + _log.debug("len-footer: %s cert: %r", lf, cert[0-lf]) return cert @@ -390,7 +390,7 @@ class DAVClient(object): import base64 dbg = self.dbg hdrs.update(self.hdrs) - log.debug("Getting %s http://%s:%d/%s", method, self.host, self.port, path) + _log.debug("Getting %s http://%s:%d/%s", method, self.host, self.port, path) conn = httplib.HTTPConnection(self.host, port=self.port, timeout=self.timeout) conn.set_debuglevel(dbg) if not path: @@ -409,8 +409,8 @@ class DAVClient(object): data1 = r1.read() if not self.user: raise Exception('Must auth, have no user/pass!') - log.debug("Ver: %s, closed: %s, will close: %s", r1.version,r1.isclosed(), r1.will_close) - log.debug("Want to do auth %s for realm %s", atype, realm) + _log.debug("Ver: %s, closed: %s, will close: %s", r1.version,r1.isclosed(), r1.will_close) + _log.debug("Want to do auth %s for realm %s", atype, realm) if atype == 'Basic' : auths = base64.encodestring(self.user + ':' + self.passwd) if auths[-1] == "\n": @@ -422,22 +422,22 @@ class DAVClient(object): else: raise Exception("Unknown auth type %s" %atype) else: - log.warning("Got 401, cannot auth") + _log.warning("Got 401, cannot auth") raise Exception('No auth') - log.debug("Reponse: %s %s",r1.status, r1.reason) + _log.debug("Reponse: %s %s",r1.status, r1.reason) data1 = r1.read() if method != 'GET': - log.debug("Body:\n%s\nEnd of body", data1) + _log.debug("Body:\n%s\nEnd of body", data1) try: ctype = r1.msg.getheader('content-type') if ctype and ';' in ctype: ctype, encoding = ctype.split(';',1) if ctype == 'text/xml': doc = xml.dom.minidom.parseString(data1) - log.debug("XML Body:\n %s", doc.toprettyxml(indent="\t")) + _log.debug("XML Body:\n %s", doc.toprettyxml(indent="\t")) except Exception: - log.warning("could not print xml", exc_info=True) + _log.warning("could not print xml", exc_info=True) pass conn.close() return r1.status, r1.msg, data1 @@ -474,7 +474,7 @@ class DAVClient(object): s, m, d = self._http_request(path, method='OPTIONS', hdrs=hdrs) assert s == 200, "Status: %r" % s assert 'OPTIONS' in m.getheader('Allow') - log.debug('Options: %r', m.getheader('Allow')) + _log.debug('Options: %r', m.getheader('Allow')) if expect: self._assert_headers(expect, m) @@ -493,10 +493,10 @@ class DAVClient(object): for cnod in node.childNodes: if cnod.nodeType != node.ELEMENT_NODE: if strict: - log.debug("Found %r inside <%s>", cnod, node.tagName) + _log.debug("Found %r inside <%s>", cnod, node.tagName) continue if namespaces and (cnod.namespaceURI not in namespaces): - log.debug("Ignoring <%s> in <%s>", cnod.tagName, node.localName) + _log.debug("Ignoring <%s> in <%s>", cnod.tagName, node.localName) continue yield cnod @@ -533,10 +533,10 @@ class DAVClient(object): assert htver == 'HTTP/1.1' rstatus = int(sta) else: - log.debug("What is <%s> inside a <propstat>?", pno.tagName) + _log.debug("What is <%s> inside a <propstat>?", pno.tagName) else: - log.debug("Unknown node: %s", cno.tagName) + _log.debug("Unknown node: %s", cno.tagName) res.setdefault(href,[]).append((status, res_nss)) @@ -637,7 +637,7 @@ class DAVClient(object): if lsp[1] in davprops: lsline[lsp[0]] = lsp[2] else: - log.debug("Strange status: %s", st) + _log.debug("Strange status: %s", st) res.append(lsline) diff --git a/addons/document_webdav/webdav_server.py b/addons/document_webdav/webdav_server.py index ae75d0b80fc..4cb3233cf69 100644 --- a/addons/document_webdav/webdav_server.py +++ b/addons/document_webdav/webdav_server.py @@ -55,6 +55,9 @@ from DAV.propfind import PROPFIND from xml.dom import minidom from redirect import RedirectHTTPHandler +_logger_DAV = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) +_log_web = logging.getLogger(__name__) khtml_re = re.compile(r' KHTML/([0-9\.]+) ') def OpenDAVConfig(**kw): @@ -73,7 +76,7 @@ def OpenDAVConfig(**kw): class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler): verbose = False - _logger = logging.getLogger('webdav') + protocol_version = 'HTTP/1.1' _HTTP_OPTIONS= { 'DAV' : ['1', '2'], 'Allow' : [ 'GET', 'HEAD', 'COPY', 'MOVE', 'POST', 'PUT', @@ -127,10 +130,10 @@ class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler): return self.davpath def log_message(self, format, *args): - self._logger.debug(format % args) + _logger.debug(format % args) def log_error(self, format, *args): - self._logger.warning(format % args) + _logger.warning(format % args) def _prep_OPTIONS(self, opts): ret = opts @@ -477,7 +480,7 @@ class dummy_dav_interface(object): uri2 = uri.split('/') if len(uri2) < 3: return True - logging.getLogger('webdav').debug("Requested uri: %s", uri) + _logger_DAV.debug("Requested uri: %s", uri) return None # no def is_collection(self, uri): @@ -487,6 +490,7 @@ class dummy_dav_interface(object): class DAVStaticHandler(http_server.StaticHTTPHandler): """ A variant of the Static handler, which will serve dummy DAV requests """ + verbose = False protocol_version = 'HTTP/1.1' _HTTP_OPTIONS= { 'DAV' : ['1', '2'], @@ -573,7 +577,7 @@ try: conf = OpenDAVConfig(**_dc) handler._config = conf reg_http_service(directory, DAVHandler, DAVAuthProvider) - logging.getLogger('webdav').info("WebDAV service registered at path: %s/ "% directory) + _logger_DAV.info("WebDAV service registered at path: %s/ "% directory) if not (config.get_misc('webdav', 'no_root_hack', False)): # Now, replace the static http handler with the dav-enabled one. @@ -595,7 +599,7 @@ try: reg_http_service('/', DAVStaticHandler) except Exception, e: - logging.getLogger('webdav').error('Cannot launch webdav: %s' % e) + _logger_DAV.error('Cannot launch webdav: %s' % e) def init_well_known(): @@ -616,6 +620,8 @@ def init_well_known(): init_well_known() class PrincipalsRedirect(RedirectHTTPHandler): + + redirect_paths = {} def _find_redirect(self): @@ -639,7 +645,7 @@ def init_principals_redirect(): if dbname: PrincipalsRedirect.redirect_paths[''] = '/webdav/%s/principals' % dbname reg_http_service('/principals', PrincipalsRedirect) - logging.getLogger("web-services").info( + _log_web.info( "Registered HTTP redirect handler for /principals to the %s db.", dbname) |
