Hi,
I'm writing a piece of code to encrypt a text using symmetric encryption. But it's not coming back with the right result...
from Crypto.Cipher import AES
import os
crypto = AES.new(os.urandom(32), AES.MODE_CTR, counter = lambda : os.urandom(16))
encrypted = crypto.encrypt("aaaaaaaaaaaaaaaa")
print crypto.decrypt(encrypted)
Here,...
I'm writing a dead link detector and wondering which lib i should use, httplib and urllib, so I tried both.
def http_response_code(url):
host = urlparse(url)[1]
req = '/'.join(urlparse(url)[2:5])
conn = httplib.HTTPConnection(host)
conn.request('HEAD', req)
res = conn.getresponse()
return res.status, res.reason
...
I recently began learning Python, and I am a bit confused about how packages are distributed and installed.
I understand that the official way of installing packages is distutils: you download the source tarball, unpack it, and run: python setup.py install, then the module will automagically install itself
I also know about setuptools ...
Is there a way to run Selenium test in offline mode? If I set the offline mode in the firefox profile, selenium is stuck at selenium.start(). I'm using the python client driver. The code is as below
sel = selenium('localhost', 4444, '*firefox', 'file:///home/user/selenium/selenium-python/client-driver-1.0.1/inputs/input.html')
sel.st...
I am currently using pywin32 to create an Internet Explorer window and grab an object which I then store it into a variable called flashObject. I can then call methods on this such as fireEvent. However, what I want to do is basically call fireEvent("onkeypress"), but I want to specify an event to go along with that so it will basically ...
Hi there,
I'm currently retrieving and parsing pages from a website using urllib2. However, there are many of them (more than 1000), and processing them sequentially is painfully slow.
I was hoping there was a way to retrieve and parse pages in a parallel fashion. If that's a good idea, is it possible, and how do I do it?
Also, what...
I have a class like:
class MyClass:
Foo = 1
Bar = 2
Whenever MyClass.Foo or MyClass.Bar is invoked, I need a custom method to be invoked before the value is returned. Is it possible in Python ? I know it is possible if I create an instance of the class and I can define my own __getattr__ method. But my scnenario involves usi...
In Python, is there some short way to do something like
"for i in range(n)"
when n is too big for Python to actually create the array range(n)?
(short because otherwise I'd just use a while loop)
...
I tried to create a symbolic link in python site-packages directory using mklink /D syntax (on Windows 7 machine). Unfortunaly the module is not found when using import clause. When I copy the module physicaly to site-package directory, it works ok. Am I doing something wrong or is this just not possible on windows. I am using python 2.6...
i want to create a path like C:\sample\sample1\hello.py
It should automatically create the complete path from sample to hello.py
Is this possible in python while dealing with file.
pls help me
...
In the code below I intend to have two buttons, and when each is pressed '0' and '1' are to be printed to stdout, respectively. However when the program is run, they both print '1', which is the last value i had in the for iteration. Why?
import Tkinter as tk
import sys
root = tk.Tk()
for i in range(0,2):
cmd = lambda: sys.stdout...
Hi All,
I have been playing for a couple of days with Django Admin to explore it, but I am still clueless of how it can be customized in the way we need.
Every time I look for any help for the customization in the admin panel, what I find is, a bunch of articles on various communities and forums, explaining how to customize the templa...
I am currrently using BeautifulSoup to scrape some websites, however I have a problem with some specific characters, the code inside UnicodeDammit seems to indicate this (again) are some Microsoft-invented ones.
I'm using the newest version of BeautifulSoup(3.0.8.1) as I am still using python2.5
The following code illustrates my proble...
I wrote a function that copies the /etc/skel directory on a linux machine during a "create new user" RPC call. Now, there is quite a few things about this I want to test, for example the files in /etc/skel and the targets of symlinks should not have changed permissions afterwards, whereas the copied files including the actual symlinks sh...
I'm getting an error while parsing a JSON response in Python. Ex:
{
"oneliners": [
"she\'s the one",
"who opened the gates"
]
}
The JSON decoder coughs up on the invalid escape on the single quote. Typically do people apply a REGEX to remove the escape slash character prior to decoding a response that can poten...
Hi
I have GUI application with gtk.Treeview component. It's model is set to gtk.Treestore, which I fill with a hierarchical structure. Everything is working fine - the treeview is what I expect it to be.
Now I'd like to filter the leaf nodes to contain only a given string. I tried creating model filter like this:
self.modelfilter = ...
I want to write an application to video capture from web-cams in linux. Is there a python library to do that?
...
Hi. I'm writing a simple crawler with eventlet and I want to store all the url I retrieve in a simple datastore like shove. Is safe to use it in a non blocking enviroment?
...
I have developed fuse fs with python and now want to write tests for it. Before testing I mount fs to some dir:
fs = MyFuseFS()
fs.parse(errex=1, ['some_dir'])
fs.main()
After testing I want unmount my fs, want to do something like this:
fs.unmount()
Is it something like "unmount" method? Maybe there is another ways...
Hi,
I cannot os.chdir(path) in Python 2.6.5 under WindowsXP SP2. It works fine under CygWin and MAC OS X, but for WinXP regardless of path format, I always get this error:
AttributeError: 'str' object has no attribute 'chdir'.
I thought it was the problem with format of path but after trying r"C:\WINDOWS", 'C:\WINDOWS' and combinati...