[CalendarServer-changes] [13557] CalendarServer/trunk/txdav/dps/json.py

source_changes at macosforge.org source_changes at macosforge.org
Thu May 29 11:43:24 PDT 2014


Revision: 13557
          http://trac.calendarserver.org//changeset/13557
Author:   wsanchez at apple.com
Date:     2014-05-29 11:43:24 -0700 (Thu, 29 May 2014)
Log Message:
-----------
cosmetic

Modified Paths:
--------------
    CalendarServer/trunk/txdav/dps/json.py

Modified: CalendarServer/trunk/txdav/dps/json.py
===================================================================
--- CalendarServer/trunk/txdav/dps/json.py	2014-05-29 18:13:38 UTC (rev 13556)
+++ CalendarServer/trunk/txdav/dps/json.py	2014-05-29 18:43:24 UTC (rev 13557)
@@ -21,7 +21,9 @@
 """
 
 __all__ = [
+    "expressionAsJSON",
     "expressionAsJSONText",
+    "expressionFromJSON",
     "expressionFromJSONText",
 ]
 
@@ -34,21 +36,13 @@
 
 
 
-def expressionAsJSONText(expression):
-    json = expressionAsJSON(expression)
-    return to_json_text(json)
-
-
-
-def expressionAsJSON(expression):
-    if isinstance(expression, CompoundExpression):
-        return compoundExpressionAsJSON(expression)
-
-    if isinstance(expression, MatchExpression):
-        return matchExpressionAsJSON(expression)
-
-    raise NotImplementedError(
-        "Unknown expression type: {!r}".format(expression)
+def matchExpressionAsJSON(expression):
+    return dict(
+        type=expression.__class__.__name__,
+        field=expression.fieldName.name,
+        value=expression.fieldValue,
+        match=expression.matchType.name,
+        flags=expression.flags.name,
     )
 
 
@@ -62,41 +56,48 @@
 
 
 
-def matchExpressionAsJSON(expression):
-    return dict(
-        type=expression.__class__.__name__,
-        field=expression.fieldName.name,
-        value=expression.fieldValue,
-        match=expression.matchType.name,
-        flags=expression.flags.name,
+def expressionAsJSON(expression):
+    if isinstance(expression, CompoundExpression):
+        return compoundExpressionAsJSON(expression)
+
+    if isinstance(expression, MatchExpression):
+        return matchExpressionAsJSON(expression)
+
+    raise NotImplementedError(
+        "Unknown expression type: {!r}".format(expression)
     )
-    raise NotImplementedError()
 
 
 
-def expressionFromJSONText(jsonText):
-    json = from_json_text(jsonText)
-    return expressionFromJSON(json)
+def expressionAsJSONText(expression):
+    json = expressionAsJSON(expression)
+    return to_json_text(json)
 
 
 
-def expressionFromJSON(json):
-    if not isinstance(json, dict):
-        raise TypeError("JSON expression must be a dict.")
-
+def matchExpressionFromJSON(json):
     try:
-        json_type = json["type"]
+        field_json = json["field"]
+        value_json = json["value"]
+        match_json = json["match"]
+        flags_json = json["flags"]
     except KeyError as e:
-        raise ValueError("JSON expression must have {!r} key.".format(e[0]))
+        raise ValueError(
+            "JSON match expression must have {!r} key.".format(e[0])
+        )
 
-    if json_type == "CompoundExpression":
-        return compoundExpressionFromJSON(json)
+    raise NotImplementedError()
 
-    if json_type == "MatchExpression":
-        return matchExpressionFromJSON(json)
+    fieldName = NotImplemented, field_json   # Need service...
+    fieldValue = NotImplemented, value_json  # Need to cast to correct value
+    matchType = MatchType.lookupByName(match_json)
+    flags = NotImplemented, flags_json       # Need to handle composite flags
 
-    raise NotImplementedError(
-        "Unknown expression type: {}".format(json_type)
+    MatchFlags  # Shh, flakes
+
+    return MatchExpression(
+        fieldName, fieldValue,
+        matchType=matchType, flags=flags,
     )
 
 
@@ -117,33 +118,33 @@
 
 
 
-def matchExpressionFromJSON(json):
+def expressionFromJSON(json):
+    if not isinstance(json, dict):
+        raise TypeError("JSON expression must be a dict.")
+
     try:
-        field_json = json["field"]
-        value_json = json["value"]
-        match_json = json["match"]
-        flags_json = json["flags"]
+        json_type = json["type"]
     except KeyError as e:
-        raise ValueError(
-            "JSON match expression must have {!r} key.".format(e[0])
-        )
+        raise ValueError("JSON expression must have {!r} key.".format(e[0]))
 
-    raise NotImplementedError()
+    if json_type == "CompoundExpression":
+        return compoundExpressionFromJSON(json)
 
-    fieldName = NotImplemented, field_json   # Need service...
-    fieldValue = NotImplemented, value_json  # Need to cast to correct value
-    matchType = MatchType.lookupByName(match_json)
-    flags = NotImplemented, flags_json       # Need to handle composite flags
+    if json_type == "MatchExpression":
+        return matchExpressionFromJSON(json)
 
-    MatchFlags  # Shh, flakes
-
-    return MatchExpression(
-        fieldName, fieldValue,
-        matchType=matchType, flags=flags,
+    raise NotImplementedError(
+        "Unknown expression type: {}".format(json_type)
     )
 
 
 
+def expressionFromJSONText(jsonText):
+    json = from_json_text(jsonText)
+    return expressionFromJSON(json)
+
+
+
 def to_json_text(obj):
     """
     Convert an object into JSON text.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140529/dd44af40/attachment-0001.html>


More information about the calendarserver-changes mailing list