Monotone-Parent: 10eef03af266df87b4a50193c2a0106754ea1c61

Monotone-Revision: a1d5297ee60258830645ba6ddadf4cdd9b01b0fd

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-08-27T15:59:19
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2009-08-27 15:59:19 +00:00
parent 53f2433ad6
commit cfe59955d9
3 changed files with 58 additions and 12 deletions

View File

@ -1,3 +1,12 @@
2009-08-27 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Tests/webdavlib.py (HTTPQuery.__init__): the content-type is no
longer passed as parameter and should be directly set by the
client as an attribute.
(HTTPSimpleQuery.prepare_headers): new method to enable
query-specific headers.
(CalDAVPOST.__init__): new query type
2009-08-26 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* UI/MainUI/SOGoUserHomePage.m (-defaultAction): when the user has

View File

@ -64,7 +64,8 @@ class DAVAclTest(unittest.TestCase):
<set-roles user="%s">%s</set-roles>
</acl-query>""" % (subscriber_username, rights_str)
post = webdavlib.HTTPPOST(self.resource, aclQuery, "application/xml")
post = webdavlib.HTTPPOST(self.resource, aclQuery)
post.content_type = "application/xml"
self.client.execute(post)
self.assertEquals(post.response["status"], 204,
"rights modification: failure to set '%s' (status: %d)"
@ -178,7 +179,8 @@ class DAVCalendarAclTest(DAVAclTest):
"filename": filename,
"organizer_line": organizer_line,
"attendee_line": attendee_line }
put = webdavlib.HTTPPUT(url, event, "text/calendar; charset=utf-8")
put = webdavlib.HTTPPUT(url, event)
put.content_type = "text/calendar; charset=utf-8"
client.execute(put)
self.assertEquals(put.response["status"], exp_status,
"%s: event creation/modification:"
@ -326,7 +328,7 @@ class DAVCalendarAclTest(DAVAclTest):
icsClass = self.classToICSClass[event_class]
url = "%s%s.ics" % (self.resource, icsClass.lower())
multiget = webdavlib.WebDAVCalendarMultiget(self.resource,
multiget = webdavlib.CalDAVCalendarMultiget(self.resource,
["{urn:ietf:params:xml:ns:caldav}calendar-data"],
[ url ])
self.subscriber_client.execute(multiget)
@ -638,7 +640,8 @@ END:VCARD""" }
if real_card is None:
real_card = filename
card = self.cards[real_card]
put = webdavlib.HTTPPUT(url, card, "text/x-vcard; charset=utf-8")
put = webdavlib.HTTPPUT(url, card)
put.content_type = "text/x-vcard; charset=utf-8"
client.execute(put)
self.assertEquals(put.response["status"], exp_status,
"%s: card creation/modification:"

View File

@ -20,7 +20,7 @@ class WebDAVClient:
self.simpleauth_hash = (("%s:%s" % (username, password))
.encode('base64')[:-1])
def _prepare_headers(self, query, body):
def prepare_headers(self, query, body):
headers = { "User-Agent": self.user_agent,
"authorization": "Basic %s" % self.simpleauth_hash }
if body is not None:
@ -30,6 +30,11 @@ class WebDAVClient:
if query.__dict__.has_key("content_type"):
headers["content-type"] = query.content_type
query_headers = query.prepare_headers()
if query_headers is not None:
for key in query_headers.keys():
headers[key] = query_headers[key]
return headers
def execute(self, query):
@ -37,7 +42,7 @@ class WebDAVClient:
query.start = time.time()
self.conn.request(query.method, query.url,
body, self._prepare_headers(query, body))
body, self.prepare_headers(query, body))
query.set_response(self.conn.getresponse());
query.duration = time.time() - query.start
@ -50,6 +55,9 @@ class HTTPSimpleQuery:
self.start = -1
self.duration = -1
def prepare_headers(self):
return {}
def render(self):
return None
@ -67,15 +75,15 @@ class HTTPGET(HTTPSimpleQuery):
method = "GET"
class HTTPQuery(HTTPSimpleQuery):
def __init__(self, url, content_type):
def __init__(self, url):
HTTPSimpleQuery.__init__(self, url)
self.content_type = content_type
self.content_type = "application/octet-stream"
class HTTPPUT(HTTPQuery):
method = "PUT"
def __init__(self, url, content, content_type = "application/octet-stream"):
HTTPQuery.__init__(self, url, content_type)
def __init__(self, url, content):
HTTPQuery.__init__(self, url)
self.content = content
def render(self):
@ -88,7 +96,8 @@ class WebDAVQuery(HTTPQuery):
method = None
def __init__(self, url, depth = None):
HTTPQuery.__init__(self, url, "application/xml; charset=\"utf-8\"")
HTTPQuery.__init__(self, url)
self.content_type = "application/xml; charset=\"utf-8\""
self.depth = depth
self.ns_mgr = _WD_XMLNS_MGR()
self.top_node = None
@ -156,7 +165,32 @@ class WebDAVPROPFIND(WebDAVQuery):
prop_tag = self.render_tag(prop)
props.append(_WD_XMLTreeElement(prop_tag))
class WebDAVCalendarMultiget(WebDAVREPORT):
class CalDAVPOST(WebDAVQuery):
method = "POST"
def __init__(self, url, content,
originator = None, recipients = None):
WebDAVQuery.__init__(self, url)
self.content_type = "text/calendar; charset=utf-8"
self.originator = originator
self.recipients = recipients
self.content = content
def prepare_headers(self):
headers = WebDAVQuery.prepare_headers(self)
if self.originator is not None:
headers["originator"] = self.originator
if self.recipients is not None:
headers["recipient"] = ",".join(self.recipients)
return headers
def render(self):
return self.content
class CalDAVCalendarMultiget(WebDAVREPORT):
def __init__(self, url, properties, hrefs):
WebDAVQuery.__init__(self, url)
multiget_tag = self.ns_mgr.register("calendar-multiget", "urn:ietf:params:xml:ns:caldav")