[CalendarServer-changes] [10675] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 11 10:49:10 PST 2013
Revision: 10675
http://trac.calendarserver.org//changeset/10675
Author: wsanchez at apple.com
Date: 2013-02-11 10:49:10 -0800 (Mon, 11 Feb 2013)
Log Message:
-----------
Work on mutable records.
Modified Paths:
--------------
CalendarServer/trunk/twext/who/directory.py
CalendarServer/trunk/twext/who/test/test_xml.py
CalendarServer/trunk/twext/who/xml.py
Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py 2013-02-11 15:20:35 UTC (rev 10674)
+++ CalendarServer/trunk/twext/who/directory.py 2013-02-11 18:49:10 UTC (rev 10675)
@@ -192,6 +192,28 @@
raise AttributeError(name)
+ def description(self):
+ description = [self.__class__.__name__, ":"]
+
+ for name, value in self.fields.items():
+ if hasattr(name, "description"):
+ name = name.description
+ else:
+ name = str(name)
+
+ if hasattr(value, "description"):
+ value = value.description
+ else:
+ value = str(value)
+
+ description.append("\n ")
+ description.append(name)
+ description.append(" = ")
+ description.append(value)
+
+ return "".join(description)
+
+
def members(self):
if self.recordType == RecordType.group:
raise NotImplementedError()
Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-11 15:20:35 UTC (rev 10674)
+++ CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-11 18:49:10 UTC (rev 10675)
@@ -280,17 +280,33 @@
# Verify change is present immediately
record = (yield service.recordWithUID("__wsanchez__"))
- self.assertEquals(record.fullName, "Wilfredo Sanchez Vega")
+ self.assertEquals(set(record.fullNames), set(("Wilfredo Sanchez Vega",)))
# Verify change is persisted
service.flush()
record = (yield service.recordWithUID("__wsanchez__"))
- self.assertEquals(record.fullName, "Wilfredo Sanchez Vega")
+ self.assertEquals(set(record.fullNames), set(("Wilfredo Sanchez Vega",)))
- test_updateRecord.todo = "Not implemented."
+ @inlineCallbacks
+ def test_addRecord(self):
+ service = self._testService()
+ raise NotImplementedError()
+ test_addRecord.todo = "Not implemented."
+
+
+ @inlineCallbacks
+ def test_addRecordNo(self):
+ service = self._testService()
+
+ raise NotImplementedError()
+
+ test_addRecord.todo = "Not implemented."
+
+
+
class DirectoryRecordTest(BaseTest, test_directory.DirectoryRecordTest):
@inlineCallbacks
def test_members(self):
Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py 2013-02-11 15:20:35 UTC (rev 10674)
+++ CalendarServer/trunk/twext/who/xml.py 2013-02-11 18:49:10 UTC (rev 10675)
@@ -29,6 +29,8 @@
from xml.etree.ElementTree import parse as parseXML
from xml.etree.ElementTree import ParseError as XMLParseError
+from xml.etree.ElementTree import tostring as etreeToString
+from xml.etree.ElementTree import Element as XMLElement
from twisted.python.constants import Names, NamedConstant, Values, ValueConstant
from twisted.internet.defer import succeed, inlineCallbacks, returnValue
@@ -408,10 +410,48 @@
record = recordsByUID.get(uidNode.text, None)
if record:
- raise NotImplementedError("Update record: %s" % (record,))
+ recordNode.clear()
+ for (name, value) in record.fields.items():
+ if name == self.fieldName.recordType:
+ # FIXME: This lookup of the record type value is a bit much to do in a loop
+ for valueName in self.value.iterconstants():
+ if getattr(valueName, "recordType", None) == value:
+ recordNode.set(self.attribute.recordType.value, valueName.value)
+ break
+ else:
+ raise AssertionError("Unknown record type: %r" % (value,))
+ else:
+ # FIXME: This lookup of the field name element is a bit much to do in a loop
+ for elementName in self.element.iterconstants():
+ if getattr(elementName, "fieldName", None) == name:
+ if self.fieldName.isMultiValue(name):
+ values = value
+ else:
+ values = (value,)
+ for value in values:
+ subNode = XMLElement(tag=elementName.value)
+ subNode.text = value
+ recordNode.append(subNode)
+ break
+ else:
+ raise AssertionError("Unknown field name: %r" % (name,))
+
+ del recordsByUID[record.uid]
+
+ if recordsByUID:
+ if not create:
+ raise NotImplementedError("Raise something.")
+
+ raise NotImplementedError("Add new records.")
+
+ self.filePath.setContent(etreeToString(directoryNode))
+ self.flush()
+
+
+
class DirectoryRecord(BaseDirectoryRecord):
"""
XML directory record
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130211/8478b149/attachment.html>
More information about the calendarserver-changes
mailing list