[Checkins] SVN: z3c.testsetup/trunk/src/z3c/testsetup/util.py Add helper functions to extract marker strings.

Uli Fouquet uli at gnufix.de
Mon Jul 28 06:48:23 EDT 2008


Log message for revision 88853:
  Add helper functions to extract marker strings.

Changed:
  U   z3c.testsetup/trunk/src/z3c/testsetup/util.py

-=-
Modified: z3c.testsetup/trunk/src/z3c/testsetup/util.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/util.py	2008-07-27 22:03:18 UTC (rev 88852)
+++ z3c.testsetup/trunk/src/z3c/testsetup/util.py	2008-07-28 10:48:21 UTC (rev 88853)
@@ -51,3 +51,30 @@
         if varkw is None:
             break
     return list(result)
+
+def get_marker_from_string(marker, text):
+    """Looks for a markerstring  in a string.
+
+    Returns the found value or `None`. A markerstring has the form::
+
+     :<Tag>: <Value>
+    """
+    marker = ":%s:" % marker.lower()
+    for line in text.split('\n'):
+        line = line.strip()
+        if not line.lower().startswith(marker):
+            continue
+        result = line[len(marker):].strip()
+        return unicode(result)
+    return None
+
+def get_marker_from_file(marker, filepath):
+    """Looks for a markerstring  in a file.
+
+    Returns the found value or `None`. A markerstring has the form::
+
+     :<Tag>: <Value>
+
+    """
+    return get_marker_from_string(marker, open(filepath, 'r').read())
+



More information about the Checkins mailing list