diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-03-08 08:18:07 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-03-08 08:18:07 +0000 |
commit | 49b878b1b0f2e52bbd5282c22ac32a68e1e8736c (patch) | |
tree | 1eb26926f9d703c61b329a0f07178090b57cd55d /sca-cpp/trunk/modules/wsgi/atomutil.py | |
parent | 5b33dc5c5a87fff146951ca0543bf558454c331d (diff) |
Change ATOM and RSS feed representations to use name value pairs instead of just strings, to allow support for all ATOM and RSS attributes and avoid confusion with non-feed string results.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1079292 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/wsgi/atomutil.py')
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/atomutil.py | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/atomutil.py b/sca-cpp/trunk/modules/wsgi/atomutil.py index 8e812abbe9..ad6425f062 100644 --- a/sca-cpp/trunk/modules/wsgi/atomutil.py +++ b/sca-cpp/trunk/modules/wsgi/atomutil.py @@ -22,31 +22,27 @@ from elemutil import * from xmlutil import * # Convert a list of elements to a list of values representing an ATOM entry -def entryElementsToValues(e): +def entryElementValues(e): lt = filter(selector((element, "'title")), e) t = "" if isNil(lt) else elementValue(car(lt)) li = filter(selector((element, "'id")), e) i = "" if isNil(li) else elementValue(car(li)) lc = filter(selector((element, "'content")), e) - return (t, i, elementValue(car(lc))) + return append((element, "'entry", (element, "'title", t), (element, "'id", i)), + () if isNil(lc) else ((element, "'content", elementValue(car(lc))),)) # Convert a list of elements to a list of values representing ATOM entries -def entriesElementsToValues(e): +def entriesElementValues(e): if isNil(e): return e - return cons(entryElementsToValues(car(e)), entriesElementsToValues(cdr(e))) + return cons(entryElementValues(car(e)), entriesElementValues(cdr(e))) # Convert a list of strings to a list of values representing an ATOM entry def readATOMEntry(l): e = readXML(l) if isNil(e): return () - return entryElementsToValues(car(e)) - -# Convert a list of values representing an ATOM entry to a value -def entryValue(e): - v = elementsToValues((caddr(e),)) - return cons(car(e), (cadr(e), cdr(car(v)))) + return (entryElementValues(car(e)),) # Return true if a list of strings represents an ATOM feed def isATOMFeed(l): @@ -68,26 +64,23 @@ def readATOMFeed(l): t = filter(selector((element, "'title")), car(f)) i = filter(selector((element, "'id")), car(f)) e = filter(selector((element, "'entry")), car(f)) - if isNil(e): - return (elementValue(car(t)), elementValue(car(i))) - return cons(elementValue(car(t)), cons(elementValue(car(i)), entriesElementsToValues(e))) - -# Convert an ATOM feed containing elements to an ATOM feed containing values -def feedValuesLoop(e): - if (isNil(e)): - return e - return cons(entryValue(car(e)), feedValuesLoop(cdr(e))) - -def feedValues(e): - return cons(car(e), cons(cadr(e), feedValuesLoop(cddr(e)))) + return (append( + (element, "'feed", (element, "'title", elementValue(car(t))), (element, "'id", elementValue(car(i)))), + entriesElementValues(e)),) # Convert a list of values representy an ATOM entry to a list of elements def entryElement(l): - return (element, "'entry", (attribute, "'xmlns", "http://www.w3.org/2005/Atom"), - (element, "'title", (attribute, "'type", "text"), car(l)), - (element, "'id", cadr(l)), - (element, "'content", (attribute, "'type", ("application/xml" if isList(caddr(l)) else "text")), caddr(l)), - (element, "'link", (attribute, "'href", cadr(l)))) + title = elementValue(namedElementChild("'title", l)) + id = elementValue(namedElementChild("'id", l)) + content = namedElementChild("'content", l) + text = False if isNil(content) else elementHasValue(content) + return append(append( + (element, "'entry", (attribute, "'xmlns", "http://www.w3.org/2005/Atom"), + (element, "'title", (attribute, "'type", "text"), title), + (element, "'id", id)), + () if isNil(content) else (append( + (element, "'content", (attribute, "'type", "text" if text else "application/xml")), (elementValue(content),) if text else elementChildren(content)),)), + ((element, "'link", (attribute, "'href", id)),)) # Convert a list of values representing ATOM entries to a list of elements def entriesElements(l): @@ -96,31 +89,32 @@ def entriesElements(l): return cons(entryElement(car(l)), entriesElements(cdr(l))) # Convert a list of values representing an ATOM entry to an ATOM entry -def writeATOMEntry(l): +def writeATOMEntry(ll): + l = ll if isNil(ll) else car(ll) return writeXML((entryElement(l),), True) # Convert a list of values representing an ATOM feed to an ATOM feed -def writeATOMFeed(l): +def writeATOMFeed(ll): + l = ll if isNil(ll) else car(ll) + lt = filter(selector((element, "'title")), l) + t = '' if isNil(lt) else elementValue(car(lt)) + li = filter(selector((element, "'id")), l) + i = '' if isNil(li) else elementValue(car(li)) f = (element, "'feed", (attribute, "'xmlns", "http://www.w3.org/2005/Atom"), - (element, "'title", (attribute, "'type", "text"), car(l)), - (element, "'id", cadr(l))) - if isNil(cddr(l)): - return writeXML((f,), True) - fe = append(f, entriesElements(cddr(l))) - return writeXML((fe,), True) + (element, "'title", (attribute, "'type", "text"), t), + (element, "'id", i)) -# Convert an ATOM entry containing a value to an ATOM entry containing an item element -def entryValuesToElements(v): - if isList(caddr(v)): - return cons(car(v), cons(cadr(v), valuesToElements((cons("'item", caddr(v)),)))) - return cons(car(v), cons(cadr(v), valuesToElements((("'item", caddr(v)),)))) + # Write ATOM entries + le = filter(selector((element, "'entry")), l) + if isNil(le): + return writeXML((f,), True) -# Convert an ATOM feed containing values to an ATOM feed containing elements -def feedValuesToElementsLoop(v): - if isNil(v): - return v - return cons(entryValuesToElements(car(v)), feedValuesToElementsLoop(cdr(v))) + # Write a single ATOM entry element with a list of values + if not isNil(le) and not isNil(car(le)) and isList(car(caddr(car(le)))): + fe = append(f, entriesElements(caddr(car(le)))) + return writeXML((fe,), True) -def feedValuesToElements(v): - return cons(car(v), cons(cadr(v), feedValuesToElementsLoop(cddr(v)))) + # Write separate ATOM entry elements + fe = append(f, entriesElements(le)) + return writeXML((fe,), True) |