Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Use format() instead of %

  • Loading branch information
bgaya committed Apr 9, 2014
1 parent 2553223 commit 72b61714f0e8b50c5fdc5b44797aca9a398bbaf3
Showing with 62 additions and 37 deletions.
  1. +35 −19 txdav/xml/rfc2518.py
  2. +27 −18 txdav/xml/rfc3744.py
@@ -78,7 +78,7 @@ def validate(self):

depth = str(self)
if depth not in ("0", "1", "infinity"):
raise ValueError("Invalid depth: %s" % (depth,))
raise ValueError("Invalid depth: {0}".format(depth,))



@@ -307,22 +307,35 @@ def __new__(cls, *children):
propstat_count += 1

if resource_count < 1:
raise ValueError("%s element must have at least one %s."
% (cls.sname(), HRef.sname()))
raise ValueError(
"{0} element must have at least one {1}.".format(
cls.sname(), HRef.sname()
)
)

if status_count is 0:
if propstat_count is 0:
raise ValueError("%s element must have one of %s or %s"
% (cls.sname(), Status.sname(), PropertyStatus.sname()))
raise ValueError(
"{0} element must have one of {1} or {2}".format(
cls.sname(), Status.sname(), PropertyStatus.sname()
)
)

if resource_count > 1:
raise ValueError("%s element with %s may only have one %s"
% (cls.sname(), PropertyStatus.sname(), HRef.sname()))
raise ValueError(
"{0} element with {1} may only have one {2}".format(
cls.sname(), PropertyStatus.sname(), HRef.sname()
)
)

return PropertyStatusResponse.__new__(PropertyStatusResponse, *children)

if status_count > 1:
raise ValueError("%s element may only have one %s" % (cls.sname(), Status.sname()))
raise ValueError(
"{0} element may only have one {1}".format(
cls.sname(), Status.sname()
)
)

return StatusResponse.__new__(StatusResponse, *children)

@@ -393,21 +406,21 @@ def fromResponseCode(cls, code):
txweb2.responsecode.RESPONSES.keys()
"""
if code not in responsecode.RESPONSES:
raise ValueError("Invalid response code: %r" % (code,))
raise ValueError("Invalid response code: {0!r}".format(code,))

return cls(PCDATAElement("HTTP/1.1 %d %s" % (code, responsecode.RESPONSES[code])))
return cls(PCDATAElement("HTTP/1.1 {0} {1}".format(code, responsecode.RESPONSES[code])))


def __init__(self, *children, **attributes):
super(Status, self).__init__(*children, **attributes)

status = str(self)
if not status.startswith("HTTP/1.1 "):
raise ValueError("Invalid WebDAV status: %s" % (status,))
raise ValueError("Invalid WebDAV status: {0}".format(status,))

code = int(status[9:12])
if code not in responsecode.RESPONSES:
raise ValueError("Invalid status code: %s" % (code,))
raise ValueError("Invalid status code: {0}".format(code,))

self.code = code

@@ -475,8 +488,9 @@ def __init__(self, *children, **attributes):

if len(self.children) != 1:
raise ValueError(
"Exactly one of DAV:omit, DAV:keepalive required for %s, got: %s"
% (self.sname(), self.children)
"Exactly one of DAV:omit, DAV:keepalive required for {0}, got: {1}".format(
self.sname(), self.children
)
)

self.behavior = children[0]
@@ -508,13 +522,14 @@ def validate(self):
type = child.qname()
elif child.qname() != type:
raise ValueError(
"Only one of DAV:href or PCDATA allowed for %s, got: %s"
% (self.sname(), self.children)
"Only one of DAV:href or PCDATA allowed for {0}, got: {1}".format(
self.sname(), self.children
)
)

if type == "#PCDATA":
if str(self) != "*":
raise ValueError("Invalid keepalive value: %r", (str(self),))
raise ValueError("Invalid keepalive value: {0!r}".format(str(self),))



@@ -592,8 +607,9 @@ def validate(self):

if len(self.children) != 1:
raise ValueError(
"Exactly one of DAV:allprop, DAV:propname or DAV:prop is required for %s, got: %r"
% (self.sname(), self.children)
"Exactly one of DAV:allprop, DAV:propname or DAV:prop is required for {0}, got: {1!r}".format(
self.sname(), self.children
)
)


@@ -187,8 +187,9 @@ def validate(self):
raise ValueError(
"Exactly one of DAV:href, DAV:all, DAV:authenticated, "
"DAV:unauthenticated, DAV:property or DAV:self is required for "
"%s, got: %r"
% (self.sname(), self.children)
"{0}, got: {1!r}".format(
self.sname(), self.children
)
)


@@ -504,8 +505,9 @@ def __init__(self, *children, **attributes):
if name in ("principal", "invert"):
if self.principal is not None:
raise ValueError(
"Only one of DAV:principal or DAV:invert allowed in %s, got: %s"
% (self.sname(), self.children)
"Only one of DAV:principal or DAV:invert allowed in {0}, got: {1}".format(
self.sname(), self.children
)
)
if name == "invert":
self.invert = True
@@ -517,8 +519,9 @@ def __init__(self, *children, **attributes):
elif name in ("grant", "deny"):
if self.allow is not None:
raise ValueError(
"Only one of DAV:grant or DAV:deny allowed in %s, got: %s"
% (self.sname(), self.children)
"Only one of DAV:grant or DAV:deny allowed in {0}, got: {1}".format(
self.sname(), self.children
)
)
self.allow = (name == "grant")
self.privileges = child.children
@@ -535,15 +538,17 @@ def __init__(self, *children, **attributes):

if self.principal is None:
raise ValueError(
"One of DAV:principal or DAV:invert is required in %s, got: %s"
% (self.sname(), self.children)
"One of DAV:principal or DAV:invert is required in {0}, got: {1}".format(
self.sname(), self.children
)
)
assert self.invert is not None

if self.allow is None:
raise ValueError(
"One of DAV:grant or DAV:deny is required in %s, got: %s"
% (self.sname(), self.children)
"One of DAV:grant or DAV:deny is required in {0}, got: {1}".format(
self.sname(), self.children
)
)
assert self.privileges is not None

@@ -740,8 +745,9 @@ def validate(self):
elif child.qname() != type:
raise ValueError(
"Only one of DAV:all, DAV:authenticated, DAV:unauthenticated, "
"DAV:self, DAV:href or DAV:property allowed for %s, got: %s"
% (self.sname(), self.children)
"DAV:self, DAV:href or DAV:property allowed for {0}, got: {1}".format(
self.sname(), self.children
)
)


@@ -835,8 +841,9 @@ def validate(self):
if child.qname() == (dav_namespace, "prop"):
if prop:
raise ValueError(
"Only one DAV:prop allowed for %s, got: %s"
% (self.sname(), self.children)
"Only one DAV:prop allowed for {0}, got: {1}".format(
self.sname(), self.children
)
)
prop = True

@@ -873,15 +880,17 @@ def validate(self):
if (namespace == dav_namespace) and name in ("principal-property", "self"):
if principalPropertyOrSelf:
raise ValueError(
"Only one of DAV:principal-property or DAV:self allowed in %s, got: %s"
% (self.sname(), self.children)
"Only one of DAV:principal-property or DAV:self allowed in {0}, got: {1}".format(
self.sname(), self.children
)
)
principalPropertyOrSelf = True

if not principalPropertyOrSelf:
raise ValueError(
"One of DAV:principal-property or DAV:self is required in %s, got: %s"
% (self.sname(), self.children)
"One of DAV:principal-property or DAV:self is required in {0}, got: {1}".format(
self.sname(), self.children
)
)


0 comments on commit 72b6171

Please sign in to comment.
You can’t perform that action at this time.