[Python-modules-commits] [yattag] 01/05: Import yattag_1.6.0.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Sat Jun 11 20:20:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository yattag.

commit 851c6f71efd580c8c3c99e128649e3fca00887ed
Author: Sandro Tosi <morph at debian.org>
Date:   Sat Jun 11 21:17:46 2016 +0100

    Import yattag_1.6.0.orig.tar.gz
---
 PKG-INFO                |  2 +-
 setup.py                |  2 +-
 test/tests_simpledoc.py | 27 +++++++++++++++++++++++++++
 yattag/__init__.py      |  2 +-
 yattag/simpledoc.py     | 17 +++++++++++++++++
 5 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 28d92ef..a0360bf 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: yattag
-Version: 1.5.3
+Version: 1.6.0
 Summary: Generate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.
 Home-page: http://www.yattag.org
 Author: Benjamin Le Forestier
diff --git a/setup.py b/setup.py
index 7d00859..0f04946 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open('README.rst') as fd:
 
 setup(
     name='yattag',
-    version='1.5.3',
+    version='1.6.0',
     packages=['yattag'],
     author = 'Benjamin Le Forestier',
     author_email = 'benjamin at leforestier.org',
diff --git a/test/tests_simpledoc.py b/test/tests_simpledoc.py
index 1af7999..b145c6c 100644
--- a/test/tests_simpledoc.py
+++ b/test/tests_simpledoc.py
@@ -72,5 +72,32 @@ class TestSimpledoc(unittest.TestCase):
         )
         self.assertRaises(KeyError, lambda: class_elems(root[1]))
 
+    def test_cdata(self):
+        doc, tag, text = SimpleDoc().tagtext()
+        with tag('example'):
+            doc.cdata('6 > 8 & 54')
+        self.assertEqual(
+            doc.getvalue(),
+            '<example><![CDATA[6 > 8 & 54]]></example>'
+        )
+        
+        doc = SimpleDoc()
+        doc.cdata('Jean Michel', safe = True)
+        self.assertEqual(doc.getvalue(), '<![CDATA[Jean Michel]]>')
+        
+        doc = SimpleDoc()
+        doc.cdata('A CDATA section should end with ]]>')
+        self.assertEqual(
+            doc.getvalue(),
+            '<![CDATA[A CDATA section should end with ]]]]><![CDATA[>]]>'
+        )
+        
+        doc = SimpleDoc()
+        doc.cdata('Some data ]]><script src="malicious.js">')
+        self.assertEqual(
+            doc.getvalue(),
+            '<![CDATA[Some data ]]]]><![CDATA[><script src="malicious.js">]]>'
+        )
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/yattag/__init__.py b/yattag/__init__.py
index 66f5c29..424a057 100644
--- a/yattag/__init__.py
+++ b/yattag/__init__.py
@@ -55,7 +55,7 @@ Full tutorial on yattag.org_
 """
 
 __author__ = "Benjamin Le Forestier (benjamin at leforestier.org)"
-__version__ = '1.5.3'
+__version__ = '1.6.0'
 
 from yattag.simpledoc import SimpleDoc
 from yattag.doc import Doc
diff --git a/yattag/simpledoc.py b/yattag/simpledoc.py
index 1f6e2be..6ae307f 100644
--- a/yattag/simpledoc.py
+++ b/yattag/simpledoc.py
@@ -180,6 +180,23 @@ class SimpleDoc(object):
         else:
             self._append("<%s />" % tag_name)
             
+    def cdata(self, strg, safe = False):
+        """
+        appends a CDATA section containing the supplied string
+        
+        You don't have to worry about potential ']]>' sequences that would terminate
+        the CDATA section. They are replaced with ']]]]><![CDATA[>'.
+        
+        If you're sure your string does not contain ']]>', you can pass `safe = True`.
+        If you do that, your string won't be searched for ']]>' sequences.
+        """
+        self._append('<![CDATA[')
+        if safe:
+            self._append(strg)
+        else:
+            self._append(strg.replace(']]>', ']]]]><![CDATA[>'))
+        self._append(']]>')
+            
     def getvalue(self):
         """
         returns the whole document as a single string

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/yattag.git



More information about the Python-modules-commits mailing list