python

How do I (successfully) decode a encoded password from command line openSSL?

Using PyCrypto (although I've tried this in ObjC with OpenSSL bindings as well) : from Crypto.Cipher import DES import base64 obj=DES.new('abcdefgh', DES.MODE_ECB) plain="Guido van Rossum is a space alien.XXXXXX" ciph=obj.encrypt(plain) enc=base64.b64encode(ciph) #print ciph print enc outputs a base64 encoded value of : ESzjTnGMRFnfV...

How to use the HTTPPasswordMgrWithDefaultRealm() in Python

I need to write some python ftp code that uses a ftp proxy. The proxy doesn't require authentication but the ftp server I am connecting to does. I have the following code but I am getting a "I/O error(ftp error): 501 USER format: proxy-user:auth-method@destination. Closing connection." error. My code is: import urllib2 proxies = {'ftp'...

What is your favorite solution for managing database migrations in django?

I quite like Rails' database migration management system. It is not 100% perfect, but it does the trick. Django does not ship with such a database migration system (yet?) but there are a number of open source projects to do just that, such as django-evolution and south for example. So I am wondering, what database migration management...

How do I mock the Python method OptionParser.error(), which does a sys.exit()?

I'm trying to unit test some code that looks like this: def main(): parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool') parser.add_option('--foo', action='store', help='The foo option is self-explanatory') options, arguments = parser.parse_args() if not options.foo: parser.error('--f...

PyObjc vs RubyCocoa for Mac development: Which is more mature?

I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming. So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa). I know that ideally to get the best learning exp...

What cross-platform GUI libraries are simple, lightweight, and have minimal dependencies?

I've written a small command line utility in Python (ljdump if you're curious). I originally wrote it for a technical audience who is comfortable with editing textual config files and running Python scripts from the command line. With Python, I don't have to worry about cross-platform concerns very much. I would like to make this more a...

What is the easiest way to export data from a live google app engine application?

I'm especially interested in solutions with source code available (django independency is a plus, but I'm willing to hack my way through) ...

Scripting LMMS from Python

Recently I asked about scripting FruityLoops or Reason from Python, which didn't turn up much. Today I found LMMS, a free-software FruityLoops clone. So, similarly. Has anyone tried scripting this from Python (or similar)? Is there an API or wrapper for accessing its resources from outside? If not, what would be the right approach to t...

Does anyone know of a Python equivalent of FMPP?

Does anyone know of a Python equivalent for FMPP the text file preprocessor? Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple templates depending on that data to create multi page reports in html all linked to a main ...

How do I timestamp simultaneous function calls in Python?

I have a read function in a module. If I perform that function simultaneously I need to timestamp it. How do I do this? ...

Unit testing and mocking email sender in Python with Google AppEngine

I'm a newbie to python and the app engine. I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using GAEUnit), how do I confirm an email with specific contents were sent? - i.e. how do I mock the emailer with a fake emailer to verify send was called? class EmailHandler(webapp.Reques...

How can I get the source code of python function?

Suppose, I have simple python function named foo as shown below, def foo(arg1,arg2): #do something with args a = arg1 + arg2 return a I get name of the function using >> foo.func_name how can I get >> foo.somemethod ? #do something with args a = arg1 + arg2 return a What is best way to do this? Thanks in advan...

Ordered lists in django

Hi, i have very simple problem. I need to create model, that represent element of ordered list. This model can be implemented like this: class Item(models.Model): data = models.TextField() order = models.IntegerField() or like this: class Item(models.Model): data = models.TextField() next = models.ForeignKey('self') ...

Why do managed attributes just work for class attributes and not for instance attributes in python?

To illustrate the question check the following code: class MyDescriptor(object): def __get__(self, obj, type=None): print "get", self, obj, type return self._v def __set__(self, obj, value): self._v = value print "set", self, obj, value return None class SomeClass1(object): m = MyDescriptor() class SomeClass2...

How to programmatically change urls of images in word documents

I have a set of word documents that contains a lot of non-embedded images in them. The url that the images point to no longer exist. I would like to programmatically change the domain name of the url to something else. How can I go about doing this in Java or Python ? ...

Measure load time for python cgi script?

I use python cgi for our intranet application. When I measure time, the script takes 4s to finish. But after that, it still takes another 11s to show the screen in the browser. The screen is build with tables (size: 10 KB, 91 KB uncompressed) and has a large css file (5 KB, 58 KB uncompressed). I used YSlow and did as much optimizatio...

How can I get the created date of a file on the web (with Python)?

I have a python application that relies on a file that is downloaded by a client from a website. The website is not under my control and has no API to check for a "latest version" of the file. Is there a simple way to access the file (in python) via a URL and check it's date (or size) without having to download it to the clients machin...

How to process a YAML stream in Python

I have a command line app the continuously outputs YAML data in the form: - col0: datum0 col1: datum1 col2: datum2 - col0: datum0 col1: datum1 col2: datum2 ... It does this for all of eternity. I would like to write a Python script that continuously reads each of these records. The PyYAML library seems best at taking fully l...

Can I use urllib to submit a SOAP request?

I have a SOAP request that is known to work using a tool like, say, SoapUI, but I am trying to get it to work using urllib. This is what I have tried so far and it did not work: import urllib f = "".join(open("ws_request_that_works_in_soapui", "r").readlines()) urllib.urlopen('http://url.com/to/Router?wsdl', f) I haven't been able to...

what's the pythonic way to count the occurrence of an element in a list?

this is what I did. is there a better way in python? for k in a_list: if kvMap.has_key(k): kvMap[k]=kvMap[k]+1 else: kvMap[k]=1 Thanks ...