summaryrefslogtreecommitdiff
path: root/src/atom_parser.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-07-10 18:15:52 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-07-10 18:15:52 +0200
commitfa464e4d86185266e1de9fb89d32fa2f35964ce1 (patch)
treead9c8395217ad955fb5645c561cbb04c01b873d1 /src/atom_parser.py
parent0327e5aca3c15d408b885f7e6a751ab4a2cfccb6 (diff)
downloadpoezio-fa464e4d86185266e1de9fb89d32fa2f35964ce1.tar.gz
poezio-fa464e4d86185266e1de9fb89d32fa2f35964ce1.tar.bz2
poezio-fa464e4d86185266e1de9fb89d32fa2f35964ce1.tar.xz
poezio-fa464e4d86185266e1de9fb89d32fa2f35964ce1.zip
Pubsub browser can display atom element, etc
Diffstat (limited to 'src/atom_parser.py')
-rw-r--r--src/atom_parser.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/atom_parser.py b/src/atom_parser.py
new file mode 100644
index 00000000..e676d968
--- /dev/null
+++ b/src/atom_parser.py
@@ -0,0 +1,48 @@
+# Copyright 2010-2011 Le Coz Florent <louiz@louiz.org>
+#
+# This file is part of Poezio.
+#
+# Poezio is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# Poezio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Defines a function returning a dict containing the values from an
+atom entry contained in a pubsub entry
+"""
+
+ATOM_XMLNS = "http://www.w3.org/2005/Atom"
+
+def parse_atom_entry(pubsub_item):
+ """
+ Takes a pubsub ET.Element item and returns a dict containing
+ all needed values from the atom entry element.
+ Returns None if the item does not contain an atom entry.
+ """
+ entry_elem = pubsub_item.find('{%s}entry' % (ATOM_XMLNS,))
+ if entry_elem is None:
+ return None
+ res = {'author':{}}
+ author_elem = entry_elem.find('{%s}author' % (ATOM_XMLNS,))
+ if author_elem is not None:
+ for sub in ('name', 'uri'):
+ sub_elem = author_elem.find('{%s}%s' % (ATOM_XMLNS, sub,))
+ if sub_elem is not None:
+ res['author'][sub] = sub_elem.text
+ for elem_name in {'title':'text', 'updated':'date', 'published': 'date',
+ 'summary':'text'}:
+ elem = entry_elem.find('{%s}%s' % (ATOM_XMLNS, elem_name,))
+ if elem is not None:
+ res[elem_name] = elem.text
+ link_elem = entry_elem.find('{%s}link' % (ATOM_XMLNS,))
+ if link_elem is not None:
+ res['link_href'] = link_elem.attrib.get('href') or ''
+ return res