Monotone-Parent: 5d96177dbc88f1f06a0c3249d56ab7ae20914b0a

Monotone-Revision: 612feb8d0685768e00f996a577adc89429721263

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-10-01T17:11:54
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2009-10-01 17:11:54 +00:00
parent 0bb0771f1c
commit cd2c6e9139
3 changed files with 75 additions and 0 deletions

View File

@@ -7,6 +7,14 @@
2009-10-01 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Tests/test-webdavlib.py: new test script for testing the
webdavlib library itself.
(HTTPUnparsedURLTest.testURLParse): new test case for the new
HTTPUnparsedURL class.
* Tests/webdavlib.py (HTTPUnparsedURL): new utility class for
consistently parsing url strings
* Tests/test-maildav.py (DAVMailCollectionTest.testPUT): fixed to
delete the test collection prior to the test

32
Tests/test-webdavlib.py Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/python
import unittest
from webdavlib import *
class HTTPUnparsedURLTest(unittest.TestCase):
def testURLParse(self):
fullURL = "http://username:password@hostname:123/folder/folder/object?param1=value1&param2=value2"
testURL = HTTPUnparsedURL(fullURL)
self.assertEquals(testURL.protocol, "http")
self.assertEquals(testURL.username, "username")
self.assertEquals(testURL.password, "password")
self.assertEquals(testURL.hostname, "hostname")
self.assertEquals(testURL.port, "123")
self.assertEquals(testURL.path, "/folder/folder/object")
exp_params = { "param1": "value1",
"param2": "value2" }
self.assertEquals(exp_params, testURL.parameters)
pathURL = "/folder/folder/simplereference"
testURL = HTTPUnparsedURL(pathURL)
self.assertEquals(testURL.protocol, None)
self.assertEquals(testURL.username, None)
self.assertEquals(testURL.password, None)
self.assertEquals(testURL.hostname, None)
self.assertEquals(testURL.port, None)
self.assertEquals(testURL.path, "/folder/folder/simplereference")
if __name__ == "__main__":
unittest.main()

View File

@@ -1,12 +1,47 @@
import cStringIO
import httplib
import M2Crypto.httpslib
import re
import time
import xml.sax.saxutils
import xml.dom.ext.reader.Sax2
import xml.xpath
import sys
xmlns_dav = "DAV:"
xmlns_caldav = "urn:ietf:params:xml:ns:caldav"
xmlns_inversedav = "urn:inverse:params:xml:ns:inverse-dav"
url_re = None
class HTTPUnparsedURL:
def __init__(self, url):
self._parse(url)
def _parse(self, url):
# ((proto)://((username(:(password)?)@)?hostname(:(port))))(path)?
# if url_re is None:
url_parts = url.split("?")
alpha_match = "[a-zA-Z0-9]+"
num_match = "[0-9]+"
pattern = ("((%s)://(((%s)(:(%s)?)@)?(%s)(:(%s))))?(/.*)"
% (alpha_match, alpha_match, alpha_match,
alpha_match, num_match))
url_re = re.compile(pattern)
re_match = url_re.match(url_parts[0])
if re_match is None:
raise Exception, "URL expression could not be parsed: %s" % url
(trash, self.protocol, trash, trash, self.username, trash,
self.password, self.hostname, trash, self.port, self.path) = re_match.groups()
self.parameters = {}
if len(url_parts) > 1:
param_elms = url_parts[1].split("&")
for param_pair in param_elms:
parameter = param_pair.split("=")
self.parameters[parameter[0]] = parameter[1]
class WebDAVClient:
user_agent = "Mozilla/5.0"