Looping through the gmail dot trick

2008-01-20 Thread Joshua Gilman
So I have a very interesting task ahead of me and it is to loop through an
email using the 'gmail dot trick'. Essentially this trick puts periods
throughout your email to make it look different. Even though it has periods
gmail will replace them all and send it to that email.

So [EMAIL PROTECTED] is the same as [EMAIL PROTECTED]

My task is this: Loop through an email and create as many combinations of
periods as possible. So all the combinations for blah would be:

b.lah
bl.ah
bla.h
b.l.ah
b.la.h
bl.a.h

I'm still rather new to python so this is turning out to be rather tricky.
My current code is as follows:

for d in range(1, len(email)):
> for i in range(1, len(email)):
> y = i
> temail = email
> for x in range(d):
> if email[y] == '.': break
> temail = temail.replace(email[y], '.' + email[y])
> if not y > len(email) - 2: y += 1
> print temail
>

It's not looking too bad except for some reason it's making emails like
bl..ah which is invalid. So can anyone help me out with getting this to
work? Thanks.

Cheers,
Josh
-- 
http://mail.python.org/mailman/listinfo/python-list

Using Cookie and Proxy handler with urllib2

2008-02-09 Thread Joshua Gilman
Hello, here is my current code:

import urllib, urllib2, cookielib

class wrapper:
def __init__(self):
self.setupCookies()

def request(self, address, postData=None, headers={ }):
if not postData == None:
postData = urllib.urlencode(postData)
req = urllib2.Request(address, postData, headers)
return urllib2.urlopen(req).read()

def loadCookies(self, cookieFile):
self.cookieJar.load(cookieFile)

def saveCookies(self, cookieFile):
self.cookieJar.save(cookieFile)

def useProxy(self, proxy):
proxymap = {'http': proxy}
self.cookieJar = cookielib.LWPCookieJar()

director = urllib2.OpenerDirector()
director.add_handler(urllib2.ProxyHandler(proxymap))
director.add_handler(urllib2.HTTPCookieProcessor(self.cookieJar))

urllib2.install_opener(director)

def setupCookies(self):
self.cookieJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(
self.cookieJar))
urllib2.install_opener(opener)

proxyhttp = wrapper()
proxyhttp.useProxy(proxy)
postData = {'username': username, 'password': password}
content = proxyhttp.request('http://blah.com/login.php', postData)

Now, basically what this should do is send a POST request to login.php using
the given proxy and then save the returned cookies using the cookie handler.
Either I'm doing something wrong or the proxy and cookie handler don't place
nicely together. Here is the resulting error:

  File "C:\Python25\neolib\wrapper.py", line 11, in request
return urllib2.urlopen(req).read()
  File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
  File "C:\Python25\lib\urllib2.py", line 380, in open
response = meth(req, response)
  File "C:\Python25\lib\urllib2.py", line 1124, in http_response
self.cookiejar.extract_cookies(response, request)
  File "C:\Python25\lib\cookielib.py", line 1627, in extract_cookies
_debug("extract_cookies: %s", response.info())
AttributeError: 'NoneType' object has no attribute 'info'

I don't know much about these handlers to really understand what's going
wrong. I assume it has to be something with these two handlers conflicting
because I can't seem to find anything wrong with my code. Is this a bug or
am I doing something wrong? Help is much appreciated, thanks.

Cheers,
Josh
-- 
http://mail.python.org/mailman/listinfo/python-list