[CalendarServer-changes] [12595] CalendarServer/trunk/txweb2/dav/http.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:21:10 PDT 2014
Revision: 12595
http://trac.calendarserver.org//changeset/12595
Author: wsanchez at apple.com
Date: 2014-02-06 14:50:28 -0800 (Thu, 06 Feb 2014)
Log Message:
-----------
logging, linting
Modified Paths:
--------------
CalendarServer/trunk/txweb2/dav/http.py
Modified: CalendarServer/trunk/txweb2/dav/http.py
===================================================================
--- CalendarServer/trunk/txweb2/dav/http.py 2014-02-06 21:45:18 UTC (rev 12594)
+++ CalendarServer/trunk/txweb2/dav/http.py 2014-02-06 22:50:28 UTC (rev 12595)
@@ -7,10 +7,10 @@
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-#
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -51,6 +51,7 @@
log = Logger()
+
class ErrorResponse(Response):
"""
A L{Response} object which contains a status code and a L{element.Error}
@@ -79,7 +80,9 @@
self.description = description
if self.description:
- output = element.Error(error, element.ErrorDescription(self.description)).toxml()
+ output = element.Error(
+ error, element.ErrorDescription(self.description)
+ ).toxml()
else:
output = element.Error(error).toxml()
@@ -91,9 +94,14 @@
def __repr__(self):
- return "<%s %s %s>" % (self.__class__.__name__, self.code, self.error.sname())
+ return (
+ "<%s %s %s>"
+ % (self.__class__.__name__, self.code, self.error.sname())
+ )
-class NeedPrivilegesResponse (ErrorResponse):
+
+
+class NeedPrivilegesResponse(ErrorResponse):
def __init__(self, base_uri, errors):
"""
An error response which is due to unsufficient privileges, as
@@ -112,12 +120,17 @@
uri = joinURL(base_uri, subpath)
for p in privileges:
- denials.append(element.Resource(element.HRef(uri),
- element.Privilege(p)))
+ denials.append(
+ element.Resource(element.HRef(uri), element.Privilege(p))
+ )
- super(NeedPrivilegesResponse, self).__init__(responsecode.FORBIDDEN, element.NeedPrivileges(*denials))
+ super(NeedPrivilegesResponse, self).__init__(
+ responsecode.FORBIDDEN, element.NeedPrivileges(*denials)
+ )
-class MultiStatusResponse (Response):
+
+
+class MultiStatusResponse(Response):
"""
Multi-status L{Response} object.
Renders itself as a DAV:multi-status XML document.
@@ -131,15 +144,17 @@
self.headers.setHeader("content-type", MimeType("text", "xml"))
-class ResponseQueue (object):
+
+
+class ResponseQueue(object):
"""
Stores a list of (typically error) responses for use in a
L{MultiStatusResponse}.
"""
def __init__(self, path_basename, method, success_response):
"""
- @param path_basename: the base path for all responses to be added to the
- queue.
+ @param path_basename: the base path for all responses to be added to
+ the queue.
All paths for responses added to the queue must start with
C{path_basename}, which will be stripped from the beginning of each
path to determine the response's URI.
@@ -173,8 +188,11 @@
else:
raise AssertionError("Unknown data type: %r" % (what,))
- if code > 400: # Error codes only
- log.error("Error during %s for %s: %s" % (self.method, path, message))
+ if code > 400: # Error codes only
+ log.error(
+ "Error during {method} for {path}: {message}",
+ method=self.method, path=path, message=message
+ )
uri = path[self.path_basename_len:]
@@ -199,7 +217,9 @@
else:
return self.success_response
-class PropertyStatusResponseQueue (object):
+
+
+class PropertyStatusResponseQueue(object):
"""
Stores a list of propstat elements for use in a L{Response}
in a L{MultiStatusResponse}.
@@ -235,10 +255,15 @@
if len(property.children) > 0:
# Re-instantiate as empty element.
- property = element.WebDAVUnknownElement.withName(property.namespace, property.name)
+ property = element.WebDAVUnknownElement.withName(
+ property.namespace, property.name
+ )
- if code > 400: # Error codes only
- log.error("Error during %s for %s: %s" % (self.method, property, message))
+ if code > 400: # Error codes only
+ log.error(
+ "Error during {method} for {property}: {message}",
+ method=self.method, property=property, message=message
+ )
children = []
children.append(element.PropertyContainer(property))
@@ -251,7 +276,8 @@
def error(self):
"""
- Convert any 2xx codes in the propstat responses to 424 Failed Dependency.
+ Convert any 2xx codes in the propstat responses to 424 Failed
+ Dependency.
"""
for index, propstat in enumerate(self.propstats):
# Check the status
@@ -286,6 +312,7 @@
element.Status.fromResponseCode(self.success_response)
)
+
##
# Exceptions and response codes
##
@@ -299,7 +326,7 @@
"""
def msg(err):
if what is not None:
- log.debug("%s while %s" % (err, what))
+ log.debug("{err} while {what}", err=err, what=what)
if failure.check(IOError, OSError):
e = failure.value[0]
@@ -327,12 +354,14 @@
else:
failure.raiseException()
+
def errorForFailure(failure):
if failure.check(HTTPError) and isinstance(failure.value.response, ErrorResponse):
return element.Error(failure.value.response.error)
else:
return None
+
def messageForFailure(failure):
if failure.check(HTTPError):
if isinstance(failure.value.response, ErrorResponse):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/f02c2a21/attachment.html>
More information about the calendarserver-changes
mailing list