python

Verify key is correct using pyCrypto AES decryption

How do I verify the correct key is being used to decrypt AES encrypted data using pyCrypto AES? cipher = AES.new(key, AES.MODE_CFB) cipher.decrypt(s) If an incorrect key is used, it still attempts to decrypt the data, obfuscating it more. Is there any test I can do to prove the data is being decrypted to the original state? ...

Jython 2.5.1, Eclipse & os.path

I have imported the Jython2.5.1 standalone jar into my build path in Eclipse. Whenever I run any Jython code from within Eclipse, that uses the os.path module, the app barfs: 'Execution failed. Traceback (most recent call last): File "<string>", line 1, in <module> File "../lib/python/threading.py", line 6, in <module> import traceb...

Widget Transparency in PyGTK?

What is the best way to have transparency of specific widgets in a PyGTK application? I do not want to use themes because the transparency of each of the widgets will be changing through animation. The only thing I can find is to use cairo to draw widgets with an Alpha, but I can't figure out how to do this. Is there perhaps a better wa...

How do I automatically rebuild the Sphinx index under django-sphinx?

I just setup django-sphinx, and it is working beautifully. I am now able to search my model and get amazing results. The one problem is that I have to build the index by hand using the indexer command. That means every time I add new content, I have to manually hit the command line to rebuild the search index. That is just not acceptable...

Install PyObjC on Python 2.6 on OS X 10.5?

OS X 10.5.8 came with Python 2.5, and had PyObjC already installed. I installed Python 2.6 from the python.org site, and PyObjC isn't there. I can't find a download to install PyObjC on my Python 2.6 install. Is checking out the PyObjC trunk and trying to build it my only choice? Will that work "out of the box"? ...

Cross-Platform Programming Language with a decent gui toolkit?

For the program idea I have, it requires that the software be written in one binary that is executeable by all major desktop platforms, meaning it needs an interpreted language or a language within a JVM. Either is fine with me, but the programming language has to balance power & simplicity (e.g. Python) I know of wxPython but I have re...

Lightweight crash recovery for Python

What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program again and the caching w...

How can I parse text in Python?

Sample Text: SUBJECT = 'NETHERLANDS MUSIC EPA' CONTENT = 'Michael Buble performs in Amsterdam Canadian singer Michael Buble performs during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK ' Expected result: " NETHERLANDS MUSIC EPA | 36 before Michael Buble p...

Python urllib2 Response header question

I'm trying to extract the response header of a URL request. When I use firebug to analyze the response output of a URL request, it returns Content-Type text/html however when I use the python code urllib2.urlopen(URL).info() the resulting output returns Content-Type: video/x-flv I am new to python, and to web programming in general...

want to know how to get the syllables in telugu script

i am working on telugu script whose unicode range is 0C01-0C7F can u explain how to find out the syllables in that (Update copying from that question ) I am able to categorize chars but in telugu script one syllable may contain one or more chars, and when retrieving the chars from the file the syllable is divided and not able to combin...

Python deprecated functions

I have a Django app written in Python 2.5 and I plan to upgrade it to be compatible with Python 2.6. It contains hundreds of .py files. Is there a simple way to find all deprecated functions in those files? ...

How to prepopulate ID in Django

Hello, I have simple question model : class Question(Polymorph): text = models.CharField(max_length=256) poll = models.ForeignKey(Poll) index = models.IntegerField() And I would like to prepopulate ( when saving ) index field with ID value. Of course before save I dont have ID value ( its created after it ), so I wonder w...

If pickling was interrupted, will unpickling necessarily always fail? - Python

Suppose I my attempt to write a pickle object out to disk is incomplete due to a crash. Will an attempt to unpickle the object always lead to an exception or is it possible that the fragment that was written out may be interpreted as valid pickle and the error go unnoticed? ...

Does Python have an ordered set?

Python has an ordered dictionary, what about an ordered set? This question previously had a warning that there was going to be a self-answer. ...

Trapping signals in Python

According to the documentation: There is no way to “block” signals temporarily from critical sections (since this is not supported by all Unix flavors). What stops me using signal.signal(signum,SIG_IGN) to block it, then adding the signal back? ...

Testing twisted application - Load client

Hi, I've written a Twisted based server and I'd like to test it using twisted as well. But I'd like to write a load test starting a bunch of request at the same time. But I believe that I didn't get the concepts of Twisted, mainly client side, because I'm stucked with this problem: from twisted.internet import reactor, protocol f...

Run command pipes with subprocess.Popen

How to run the following command using subprocess.Popen? mysqldump database_name table_name | bzip2 > filename I know os.system() can do the job but I dont want to wait for the dump to finish in main program. ...

Python Syntax Highlighting in Microsoft Word

Is there any way I can get my Python code syntax highlighted in Microsoft Word? ...

Avoid C style comments while reading a file

Hi All, I am parsing a C file for LOC in a function using python. I am starting from first line of function definition and skipping all lines till i met first "{". The issue is that "{" can also come as a part of comment. I just want to skip all "{" present inside comments. e.g 100: int func( 102: int i, // some comment { ......

Find a path in Windows relative to another

This problem should be a no-brainer, but I haven't yet been able to nail it. I need a function that takes two parameters, each a file path, relative or absolute, and returns a filepath which is the first path (target) resolved relative to the second path (start). The resolved path may be relative to the current directory or may be absol...