Posts

Showing posts from June, 2009

Mini HOWTO: Programmatically upload a file in Django

Surprisely, there is no any good advice in the Internet how to programmatically upload a file to the FileField field in the Django. I want to cover this issue with the sample that shows how to upload a generic file from the Internet to a Django application. The code is simple: import urllib, mimetypes, os from django.core.files.base import ContentFile #... filename, msg = urllib.urlretrieve(img) ext = mimetypes.guess_extension(msg.type) name, original_ext = os.path.splitext(filename) new_filename = filename if ext != original_ext: new_filename += ext obj.file.save(new_filename, ContentFile(open(filename).read())) First of all, we retrieves a file. urlretrieve returns a tuple <filename, msg>. filename is a name of a temporary file with the downloaded content. msg is a HTTPMessage class instance that contains headers of the file. We use msg to determinate the type of the file. For this guess_extension method is used. It is required for the case when the file is gene

PhoneyC honeyclient

Overview Let me introduce PhoneyC - pure Python honeyclient implementation. It is a perspective project and it has a huge potential. All features and advantages are described in a corresponding article . Briefly, PhoneyC is a low interaction, virtual honeyclient that emulates the core functionality of a web client and emulates specific vulnerabilities to pinpoint the attack vector. It consists of two core components - a simple web crawler ( honeywalk.py ) and an analysis engine ( honeyclient.py ) with all required auxiliary modules. Further I'll describe installation and usage procedures. Installation As a sample platform I'm using Ubuntu 9.04 Jaunty Jackalope for x84-64 processor. Following the README instructions we have to install python 2.3 and upper, clamav, spidermonkey, vb2py and curl (it is not mentioned in the README file, but it is used internally by the analysis engine): $ sudo apt-get install clamav spidermonkey-bin Python is already installed in the syste

Git vs Mercurial

Due to latest changes in projects hosting situation (like FTC Sues, Shuts Down N. Calif. Web Hosting Firm , Adobe acts against Flash video stream recorder ) I started thinking about moving on to some DVCS system. Now there are only two serious alternatives: Git and Mercurial . First of all, here are two good articles where these systems are compared: Chosing a distributed VCS for the Python project Analysis of Git and Mercurial In both of these articles Mercurial wins due to: lack of good Git support in Windows system; having Python API. But also in both of these articles it is said that Git has more features and is more powerful than Mercurial. Actually none of the issues above does not concern me personally because I'm not developing in Windows OS now, and I do not require any integration with DVCS. But let me notice that these issues are not so critical right now: there is an awesome TortoiseGit project and it works really good; basically only certain hooks