conduit r1352 - in trunk: . conduit conduit/modules test/python-tests



Author: jstowers
Date: Thu Mar  6 22:51:41 2008
New Revision: 1352
URL: http://svn.gnome.org/viewvc/conduit?rev=1352&view=rev

Log:
2008-03-07  John Stowers  <john stowers gmail com>

	* conduit/Utils.py:
	* conduit/modules/TomboyModule.py:
	* test/python-tests/TestCoreUtil.py: Always extract the note title from
	the tomboy xml file.



Modified:
   trunk/ChangeLog
   trunk/conduit/Utils.py
   trunk/conduit/modules/TomboyModule.py
   trunk/test/python-tests/TestCoreUtil.py

Modified: trunk/conduit/Utils.py
==============================================================================
--- trunk/conduit/Utils.py	(original)
+++ trunk/conduit/Utils.py	Thu Mar  6 22:51:41 2008
@@ -273,6 +273,18 @@
         return newf
     return decorator
 
+def xml_extract_value_from_tag(tag, text):
+    """
+    Returns the contents of the xml tag or None. Uses a simple regex.   
+
+    Taken from:
+    http://immike.net/blog/2007/04/06/5-regular-expressions-every-web-programmer-should-know/
+    """
+    ans = re.compile("<%(tag)s[^>]*>(.*?)</%(tag)s>" % {"tag":tag}).findall(text)
+    if ans:
+        return ans[0]
+    else:
+        return None
 #
 # Memstats
 #

Modified: trunk/conduit/modules/TomboyModule.py
==============================================================================
--- trunk/conduit/modules/TomboyModule.py	(original)
+++ trunk/conduit/modules/TomboyModule.py	Thu Mar  6 22:51:41 2008
@@ -69,7 +69,7 @@
         #A tomboy formatted XML file
         if text.startswith('<?xml version="1.0" encoding="utf-8"?>') and text.find('xmlns="http://beatniksoftware.com/tomboy";>') > 0:
             note = TomboyNote(
-                    title=title,
+                    title=Utils.xml_extract_value_from_tag("title", text),
                     contents=None,
                     xml=text
                     )

Modified: trunk/test/python-tests/TestCoreUtil.py
==============================================================================
--- trunk/test/python-tests/TestCoreUtil.py	(original)
+++ trunk/test/python-tests/TestCoreUtil.py	Thu Mar  6 22:51:41 2008
@@ -46,11 +46,17 @@
 VmSize,VmRSS,VmStack = m.calculate()
 ok("Memstats: size:%s rss:%s stack:%s" % (VmSize,VmRSS,VmStack), VmSize > 0 and VmRSS > 0 and VmStack > 0)
 
-# Test the shink command line executer
+# Test the shiny command line executer
 conv = Utils.CommandLineConverter()
 conv.build_command("ls %s %s")
 cmdok,output = conv.convert("/tmp","/dev/null",callback=None,save_output=True)
 
 ok("Command executed ok", cmdok == True and len(output) > 0)
 
+ok("Simple xml tag extractor", 
+        Utils.xml_extract_value_from_tag("tag", "<tag>foo tag bar</tag>") == "foo tag bar")
+ok("Simple xml tag extractor", 
+        Utils.xml_extract_value_from_tag("tag", "<nottag>tag</nottag>") == None)
+
+
 finished()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]