[CalendarServer-changes] [13607] CalendarServer/trunk/txdav/dps/json.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 4 15:14:20 PDT 2014
Revision: 13607
http://trac.calendarserver.org//changeset/13607
Author: wsanchez at apple.com
Date: 2014-06-04 15:14:20 -0700 (Wed, 04 Jun 2014)
Log Message:
-----------
Break out code a bit more
Modified Paths:
--------------
CalendarServer/trunk/txdav/dps/json.py
Modified: CalendarServer/trunk/txdav/dps/json.py
===================================================================
--- CalendarServer/trunk/txdav/dps/json.py 2014-06-04 18:51:13 UTC (rev 13606)
+++ CalendarServer/trunk/txdav/dps/json.py 2014-06-04 22:14:20 UTC (rev 13607)
@@ -75,6 +75,27 @@
+def matchTypeFromJSON(json):
+ return MatchType.lookupByName(json)
+
+
+
+def matchFlagsFromJSON(json):
+ if json == "{}":
+ return MatchFlags.none
+
+ if json.startswith("{") and json.endswith("}"):
+ # Composite flags: "{A,B,C,...}"
+ flags = MatchFlags.none
+ for flag in json[1:-1].split(","):
+ flags |= MatchFlags.lookupByName(flag)
+
+ return flags
+
+ return MatchFlags.lookupByName(json)
+
+
+
def matchExpressionFromJSON(service, json):
try:
jsonField = json["field"]
@@ -84,23 +105,11 @@
"JSON match expression must have {!r} key.".format(e[0])
)
- jsonMatch = json.get("match", "equals")
- jsonFlags = json.get("flags", "{}")
-
fieldName = service.fieldName.lookupByName(jsonField)
fieldValue = unicode(jsonValue)
- matchType = MatchType.lookupByName(jsonMatch)
+ matchType = matchTypeFromJSON(json.get("match", "equals"))
+ flags = matchFlagsFromJSON(json.get("flags", "{}"))
- if jsonFlags == "{}":
- flags = MatchFlags.none
- elif jsonFlags.startswith("{") and jsonFlags.endswith("}"):
- # Composite flags: "{A,B,C,...}"
- flags = MatchFlags.none
- for flag in jsonFlags[1:-1].split(","):
- flags |= MatchFlags.lookupByName(flag)
- else:
- flags = MatchFlags.lookupByName(jsonFlags)
-
return MatchExpression(
fieldName, fieldValue,
matchType=matchType, flags=flags,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140604/67f35026/attachment.html>
More information about the calendarserver-changes
mailing list