Archive
python-requests package update
The newest version of python-requests now supports python 3. The python 3 version of requests is available as python3-requests package. Thanks Rex Dieter for the patch https://bugzilla.redhat.com/show_bug.cgi?id=807525 . I have also decided to maintain python-requests for EL6, i have pushed the latest version 0.11.1 to EL6.
Though it violates the updates policy https://fedoraproject.org/wiki/Updates_Policy, i have updated python-requests from 0.6.6 to 0.10.8 in Fedora 16 as python-requests is a fast moving young project.
All the packages should land in updates-testing in a few days. Please visit https://admin.fedoraproject.org/updates/python-requests to learn more about the updates.
New Package: Python-requests – HTTP for Humans
According to http://docs.python-requests.org/en/latest/index.html
Most existing Python modules for sending HTTP requests are extremely verbose and cumbersome. Python’s builtin urllib2 module provides most of the HTTP capabilities you should need, but the api is thoroughly broken. It requires an enormous amount of work (even method overrides) to perform the simplest of tasks.
Things shouldn’t be this way. Not in Python
Sample code
>>> r = requests.get(‘https://api.github.com’, auth=(‘user’, ‘pass’))
>>> r.status_code
204
>>> r.headers['content-type']
‘application/json’
>>> r.content
…
The same sample , without using requests would look like https://gist.github.com/973705. Requests library indeed reduces the lines of code we have to write to set up HTTP requests.
The new library is available as python-requests in Fedora. You can test the packaging using the following command
yum –enablerepo=updates-testing install python-requests
Have fun!
Presentation on basics of Django
I did a presentation on basics of Django in chennai python user group (chennaipy) meeting last week. This post contains the presentation and code samples i used in the talk.
The presentation and code samples were designed to help Django newbies. There are some differences in the code i used in the presentation and the actual code samples , also i was not able to get the alignment of python code correct in the presentation.
The presentation can be downloaded from here
The code samples and source of the presentation (latex-beamer) are available under GNU Free documentation license https://gitorious.org/saga-presentations . Feel free to modify them for your own needs
Django , Interpolate two strings in a template
While i was working on my weekend project http://downloader.zer0c00l.in/, I had to concat interpolate two strings inside a template, first string was hard coded in the template and another one had to be passed from the view. Initially i tried something like
<a href="/view/logs/?page="{{ page }}> next </a>
That resulted in <a href=”/view/logs/?page=”>next</a> . Django completely ignored the {{ page }}. After scratching my head for a long time i removed the quotes and rewrote the code into
<a href=/view/logs/?page={{ page }}> next </a>
That worked as expected.
Behaviour of ConfigParser.read() – Python
I am playing around with python for a while. My code uses ConfigParser to parse a piece of configuration file. Now the documentation says ConfigParser.read() accepts list of file names as an argument and tries to read them one by one and returns the list of files that are read successfully.This behaviour is helpful when you have multiple configuration files all across your system.
what the documentation doesn’t tell you is, which configuration file it will use for further processing in case of multiple successful reads. ConfigParser actually uses the last read file for further processing. So prioritize your configuration files accordingly
import ConfigParser
config_parser = ConfigParser.ConfigParser()
filenames = ['low_priority_file','medium_priority_file','high_priority_file']
config_parser.read(filenames)

