python

GAEUnit: Trouble with long strings in assert statements?

I'm having an odd error where GAEUnit seems to be hung on assertion statements that have error strings that are too long. I'm running these tests on the GAE Dev server 1.3.3. This works just fine: self.assertEquals(2 + 2, 5, "[2, 3, 4]") # works However, if I defined a longer string, and try to print that out: jsonTest = '''[ ...

Error in creating HTML form using Python-CGI

I have to create a HTML form and get the data using python-cgi. HTML form requires user to submit firstname and lastname and then the python script is supposed to get the data generated in the form. I have read up tutorials and tried playing with it to make it work, but it does not seem to happen. HTML code: <form method = "POST" actio...

Eventlet throwing unintelligble exceptions

I'm using Eventlet's example code found here: http://eventlet.net/doc/examples.html#producer-consumer-recursive-web-crawler Halfway through the run, I encounter multiple instances of the following: Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/eventlet-0.9.9-py2.6.egg/eventlet/hubs/hub.py", line 285,...

Reading Japanese filenames in windows, using Python and glob not working

I just setup PortablePython on my system, so I can run python scripts from PHP and I got some very basic code (Below) to list all the files in a directory, however it doesn't work with Japanese filenames. It works fine with English filenames, but it spits out errors (Below) when I put any file containing Japanese characters in the direct...

batch renaming 100K files with python

I have a folder with over 100,000 files, all numbered with the same stub, but without leading zeros, and the numbers aren't always contiguous (usually they are, but there are gaps) e.g: file-21.png, file-22.png, file-640.png, file-641.png, file-642.png, file-645.png, file-2130.png, file-2131.png, file-3012.png, etc. I would...

Optimization: Python String Repetition

I have a piece of code that will take a string and repeat it such that the length of the string is x. >>> import math >>> def repeat(data, length): return (data * int(math.ceil(float(length) / len(data))))[:length] >>> repeat("Hello World", 22) 'Hello WorldHello World' >>> repeat("Hello World", 20) 'Hello WorldHello Wor' Is th...

Broken Link On Django Admin Interface

I'm currently reading Practical Django Projects and in the Django admin interface there is an option to "View on site" when entering information. But after finishing chapter 5 of the book I started to tinker with the admin interface and found that clicking this link with my categories app doesn't work as it isn't appending weblog to the...

How does the right-shift operator work in a python print statement?

I've seen someone using "print" with ">>" to write stuffs into a file: In [7]: with open('text', 'w') as f: ...: print >> f, "Hello, world!" ...: In [8]: !type text Hello, world! How does it work? When should I use this instead of just using the "write" method? ...

Python output out of order

I needed some really simple XML output so I decided to write my own functions. This was just the first step, but something has gone terribly wrong. While I would expect the output to look like this: <A> <D> <I></I> <J></J> <K></K> </D> <E> <I></I> <J></J> <K></K> </E> .....

Python CGI-based frameworks for web development and templates?

What are my choices for frameworks for doing Python web development and having a nice language for writing templates for CSS/HTML? A key goal for me is not to have to run a server or install many extra dependencies -- I'd like something that works just by using CGI and hopefully does not force me to do any fancy reconfiguration of Apach...

Is there an open-source eMail message (headers, attachments, etc.) parser?

Is there a free open-source solution taking raw e-mail message (as a piece of text) and returning each header field, each attachment and the message body as separate fields? ...

How to search code snippets

For example I want to know how to use Python pickle serialization & deserialization. Since I've never use it, reading Python official doc would be a great reference, but I prefer some snippets/example codes either has description or not. Like sites for python beginners, someone's blog, or from google codes. How would you search? Like g...

How to make a cost effective but scalable site?

Portal Technology Assessment in which we will be creating a placement portal for the campuses and industry to help place students. The portal will handle large volumes of data and people logging in, approximately 1000 users/day in a concurrent mode. What technology should i use? PHP with CakePHP as a framework, Ruby on Rails, ASP.NET, P...

How to install Python SSL module on OSX?

When I deploy my google app engine project, I get the following warning: WARNING appengine_rpc.py:399 ssl module not found. Without the ssl module, the identity of the remote host cannot be verified, and connections may NOT be secure. To fix this, please install the ssl module from http://pypi.python.org/pypi/ssl. I downloaded the pac...

OpenSSL question

I'm looking to create an application in Django which will allow for each client to point their domain to my server. At this point, I would want their domain to be accessed via https protocol and have a valid SSL connection. With OpenSSL, more specifically M2Crypto, can I do this right out the gate? Or, do I still need to purchase an SSL ...

Python / google app engine self request domain

I know that the google app engine come with the self.request for url and the path in the python platform. What I wanted to know is that did it come with anything to return only the domain name? This is because sometime in the localhost, mywebapps.appspot.com and www.mywebapps.com will have different kind of behavior. Or is there any p...

Binary Search Tree in python not working

class Node: '''represents a new node in the BST''' def __init__(self,key): self.key=key self.disconnect() def disconnect(self): self.left=None; self.right=None; self.parent=None; def __str__(self): return 'node with kay %s'%self.key class BST: def __init__(self): ...

Python urllib2 HTTPBasicAuthHandler

Here is the code: import urllib2 as URL def get_unread_msgs(user, passwd): auth = URL.HTTPBasicAuthHandler() auth.add_password( realm='New mail feed', uri='https://mail.google.com', user='%s'%user, passwd=passwd ) opener = URL.build_opener(auth) URL.install_ope...

Adding printf to the starting of all functions in a file

I have some very large C files, having lots of functions. I need to trace the execution path at run time. There is no way I can trace it through debugging as its a hypervisor code currently running over qemu and doing a lot of binary translations. Can anyone point me to some script in Perl or Python which can add a printf at the startin...

how to check if an ip address or proxy is working or not.

How can I check if a specific ip address or proxy is alive or dead ...