Popular Python recipes tagged "meta:requires=xml.sax.saxutils"http://code.activestate.com/recipes/langs/python/tags/meta:requires=xml.sax.saxutils/2012-07-03T05:23:57-07:00ActiveState Code RecipesCalendar Maker (Python) 2012-07-03T05:23:57-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578187-calendar-maker/ <p style="color: grey"> Python recipe 578187 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/old/">old</a>). </p> <p>This is an old program experimenting with CGI techniques in Python using <code>CGIHTTPServer</code> and designed for creating calendars. This is committed for archival to be run under Python 2.5 or later versions.</p> Safe HTML string and unicode (Python) 2012-01-10T08:14:14-08:00Garel Alexhttp://code.activestate.com/recipes/users/2757636/http://code.activestate.com/recipes/578008-safe-html-string-and-unicode/ <p style="color: grey"> Python recipe 578008 by <a href="/recipes/users/2757636/">Garel Alex</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/web/">web</a>). Revision 2. </p> <p>As you display message on a web page, you have to sanitize input data coming from users to avoid <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS</a>. Here is a small recipe where we can use a special class for our string to be sure we get safe all the way long.</p> Unicode class which adds proper XML declaration on encoding (Python) 2007-08-09T04:52:45-07:00Dmitry Vasilievhttp://code.activestate.com/recipes/users/1571302/http://code.activestate.com/recipes/526626-unicode-class-which-adds-proper-xml-declaration-on/ <p style="color: grey"> Python recipe 526626 by <a href="/recipes/users/1571302/">Dmitry Vasiliev</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>Sometimes you want to pass XML document as unicode object which later should be encoded for output. Unfortunately very often you don't know the output encoding and can't set XML declaration properly. UnicodeXML adds XML declaration right on encoding operation.</p> Cross-site scripting (XSS) defense (Python) 2006-08-05T10:45:10-07:00Josh Goldfoothttp://code.activestate.com/recipes/users/2960005/http://code.activestate.com/recipes/496942-cross-site-scripting-xss-defense/ <p style="color: grey"> Python recipe 496942 by <a href="/recipes/users/2960005/">Josh Goldfoot</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>This cleanses user input of potentially dangerous HTML or scripting code that can be used to launch "cross-site scripting" ("XSS") attacks, or run other harmful or annoying code. You want to run this on any user-entered text that will be saved and retransmitted to other users of your web site. This uses only standard Python libraries.</p> Deeply applying str() across a data structure (Python) 2006-11-12T03:23:54-08:00Danny Yoohttp://code.activestate.com/recipes/users/98032/http://code.activestate.com/recipes/498261-deeply-applying-str-across-a-data-structure/ <p style="color: grey"> Python recipe 498261 by <a href="/recipes/users/98032/">Danny Yoo</a> (<a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p>The str() in the standard library behaves in a slightly weird way when applied against lists: on each element of the list, the repr() is appended. In contrast, this module provides a deep_str() that deeply applies str() across lists.</p> Simple XML serlializer/de-serializer using Python dictionaries and marshalling (Python) 2005-06-07T09:13:40-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/415983-simple-xml-serlializerde-serializer-using-python-d/ <p style="color: grey"> Python recipe 415983 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>This recipe presents a way of serializing &amp; de-serializing XML using the marshal module. The XML is converted to an equivalent Python dictionary first, which is marshaled to serialize it. De-serialization first unmarshals the dictionary from the file, and constructs the original XML.</p> A SAX filter for normalizing text events (Python) 2005-04-10T06:06:10-07:00Uche Ogbujihttp://code.activestate.com/recipes/users/509776/http://code.activestate.com/recipes/265881-a-sax-filter-for-normalizing-text-events/ <p style="color: grey"> Python recipe 265881 by <a href="/recipes/users/509776/">Uche Ogbuji</a> (<a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>A SAX parser can report contiguous text using multiple characters events. This is often unexpected and can cause obscure bugs or require complicated adjustments to SAX handlers. By inserting text_normalize_filter into the SAX handler chain all downstream parsers are ensured that all text nodes in the document Infoset are reported as a single SAX characters event.</p> Recursive directory listing in HTML (Python) 2003-05-17T16:54:39-07:00Peter Scotthttp://code.activestate.com/recipes/users/991585/http://code.activestate.com/recipes/200131-recursive-directory-listing-in-html/ <p style="color: grey"> Python recipe 200131 by <a href="/recipes/users/991585/">Peter Scott</a> (<a href="/recipes/tags/files/">files</a>). Revision 2. </p> <p>Walk a directory path, listing the files and directories in HTML format.</p>