Popular recipes by Duncan McGreggor http://code.activestate.com/recipes/users/1923213/2006-09-05T18:09:47-07:00ActiveState Code RecipesXML as Dictionary (Python) 2005-05-08T17:58:54-07:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/410469-xml-as-dictionary/ <p style="color: grey"> Python recipe 410469 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/xml/">xml</a>). Revision 5. </p> <p>I use this for configuration. I hadn't intended to put it up anywhere, but there have been a couple discussions lately about converting XML to python dicts, so I feel obligated to share another approach, one that is based on Fredrik Lundh's ElementTree.</p> Classes for Working with URIs (Python) 2006-02-12T10:24:56-08:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/473864-classes-for-working-with-uris/ <p style="color: grey"> Python recipe 473864 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/web/">web</a>). Revision 3. </p> <p>This is a set of classes I have used for dealing with URL parsing in an easy and convenient manner. It keeps the code clean, etc.</p> Authenticate with twisted.web.xmlrpc (Python) 2006-09-05T18:09:47-07:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/473865-authenticate-with-twistedwebxmlrpc/ <p style="color: grey"> Python recipe 473865 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/network/">network</a>). Revision 2. </p> <p>These classes subclass several of the culprits in twisted.web.xmlrpc that are responsible for not being able to make autenticated XML-RPC calls.</p> <p>Note that this recipe also makes use of the URI classes that were posted in a previous recipe here: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473864" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473864</a></p> <p>I will submit a patch to twisted along these lines, but there will be no references to the custom Uri module or code.</p> <p>Update: XML-RPC Authentication is now supported in Twisted (version 2.4 included a patch based on this recipe). If you are using a recent version of Twisted or can update to a recent version, this recipe is no longer needed.</p> Authenticating Twisted with Zope/Plone (Python) 2006-02-08T00:19:44-08:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/473838-authenticating-twisted-with-zopeplone/ <p style="color: grey"> Python recipe 473838 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/web/">web</a>). Revision 8. </p> <p>I was writing a custom Twisted XML-RPC server for radio station DJs to use, but one station was managing all of its internal web app users and groups through Zope. Twisted has an amazingly pluggable authentication framework, so the requirement was satisfied with the following.</p> <p>Note that in this simple example, every time a user executes an XML-RPC method, they are authenticating against Zope. This involves an xmlrpclib.ServerProxy instantiation as well as the overhead of making a network connection to Zope. For this reason, as well as in the event of Zope being down, one might want to implement some form of caching (without passwords), so that application functionality is not impacted by Zope downtime and overhead from authentication is only incurred when necessary.</p> <p>radix makes a very good point in the comments: the use of xmlrpclib in this recipe is blocking. This means that if you have 10, 20, whatever number of people using the app, and someone new logs in, the twisted reactor can't do it's usual thing and cycle through requests until that user finishes logging in. I will post an update that makes use of the non-blocking t.w.xmlrpc code. The solution will be messier, though, as t.w.xmlrpc is broken in that it doesn't handle scheme://username:pass@host:port URLs. This is due to the fact that t.w.xmlrpc.QueryProtocol doesn't set an Authentication header... and there's no mechanism in t.w.xmlrpc.Proxy and QueryFactory for parsing and setting user and password into from the URL.</p> <p>Update: see the comments below for how to work around this limitation.</p> Custom String Representations of Bases (Python) 2005-05-10T23:15:37-07:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/410672-custom-string-representations-of-bases/ <p style="color: grey"> Python recipe 410672 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p>For those times when '20050415115959' just takes up too much space. Useful for making your numbers shorter (like timestamps in URLs).</p>