- should have a method to save/load cookies
"""
-#from __future__ import with_statement
-
import os
-#import md5
import urllib
import urllib2
-#import mimetypes
import cookielib
txheaders = {
'Accept':'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png',
'Accept-Language':'en,en-us;q=0.5',
-# 'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
-# 'Keep-Alive': '300',
-# 'Connection': 'keep-alive',
-# 'Cache-Control': 'max-age=0',
}
for key,value in extraheaders.iteritems():
txheaders[key] = value
self.cookies.extract_cookies(openerdirector,req)
if only_head:
return openerdirector
- #if openerdirector.headers.has_key('content-length'):
- # length = long(openerdirector.headers['content-length'])
- #else:
- # length = 0
- #dlength = 0
- #if fd:
- # while True:
- # data = openerdirector.read(1024)
- # dlength += len(data)
- # fd.write(data)
- # if onprogress:
- # onprogress(length,dlength)
- # if not data:
- # break
- #else:
- # data = ''
- # while True:
- # newdata = openerdirector.read(1024)
- # dlength += len(newdata)
- # data += newdata
- # if onprogress:
- # onprogress(length,dlength)
- # if not newdata:
- # break
- # #data = openerdirector.read()
- # if not (self.cacher is None):
- # self.cacher[key] = data
- #try:
- # d2= GzipFile(fileobj=cStringIO.StringIO(data)).read()
- # data = d2
- #except IOError:
- # pass
return openerdirector.read()
except urllib2.URLError:
cnt += 1
if self.debug:
print "MozillaEmulator: urllib2.URLError, retryting ",cnt
-# def post_multipart(self,url,fields, files, forbid_redirect=True):
-# """Post fields and files to an http host as multipart/form-data.
-# fields is a sequence of (name, value) elements for regular form fields.
-# files is a sequence of (name, filename, value) elements for data to be uploaded as files
-# Return the server's response page.
-# """
-# content_type, post_data = encode_multipart_formdata(fields, files)
-# result = self.download(url,post_data, {
-# 'Content-Type': content_type,
-# 'Content-Length': str(len(post_data))
-# },
-# forbid_redirect=forbid_redirect
-# )
-# return result
-
class HTTPNoRedirector(urllib2.HTTPRedirectHandler):
"""This is a custom http redirect handler that FORBIDS redirection."""
newurl = headers.getheaders('uri')[0]
e.newurl = newurl
raise e
-
-
-#def encode_multipart_formdata(fields, files):
-# """
-# fields is a sequence of (name, value) elements for regular form fields.
-# files is a sequence of (name, filename, value) elements for data to be uploaded as files
-# Return (content_type, body) ready for httplib.HTTP instance
-# """
-# BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
-# CRLF = '\r\n'
-# L = []
-# for (key, value) in fields:
-# L.append('--' + BOUNDARY)
-# L.append('Content-Disposition: form-data; name="%s"' % key)
-# L.append('')
-# L.append(value)
-# for (key, filename, value) in files:
-# L.append('--' + BOUNDARY)
-# L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
-# L.append('Content-Type: %s' % get_content_type(filename))
-# L.append('')
-# L.append(value)
-# L.append('--' + BOUNDARY + '--')
-# L.append('')
-# body = CRLF.join(L)
-# content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
-# return content_type, body
-#
-#
-#def get_content_type(filename):
-# return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
-#
except ImportError:
hildon = None
-#try:
-# if hasattr(gtk, "Builder"):
-# #detected that this is not a legacy system
-# raise ImportError
-# #Legacy support
-# import gtk.glade
-#except ImportError:
-# gtk.glade = None
-
try:
import osso
try:
'../lib/gc_dialer.glade',
'/usr/local/lib/gc_dialer.glade' ]:
if os.path.isfile(path):
- #if gtk.glade is None:
- # self.wTree = gtk.Builder()
- # self.wTree.add_from_file(path)
- #else:
self.wTree = gtk.glade.XML(path)
break
else:
"on_loginbutton_clicked" : self.on_loginbutton_clicked,
"on_loginclose_clicked" : self.on_loginclose_clicked,
"on_clearcookies_clicked" : self.on_clearcookies_clicked,
- # "on_callbackentry_changed" : self.on_callbackentry_changed,
"on_notebook_switch_page" : self.on_notebook_switch_page,
"on_recentview_row_activated" : self.on_recentview_row_activated,
"on_back_clicked" : self.Backspace
self.attemptLogin(2)
gobject.idle_add(self.init_grandcentral)
- #self.init_grandcentral()
gobject.idle_add(self.init_recentview)
- #self.reduce_memory()
-
def init_grandcentral(self):
""" deferred initalization of the grandcentral info """
try:
- #self.attemptLogin(2)
if self.gcd.isAuthed():
if self.gcd.getCallbackNumber() is None:
self.gcd.setSaneCallback()
text = makeugly(self.wTree.get_widget("callbackcombo").get_child().get_text())
if self.gcd.validate(text) and text != self.gcd.getCallbackNumber():
self.gcd.setCallbackNumber(text)
- #self.wTree.get_widget("callbackentry").set_text(self.wTree.get_object("callbackentry").get_text())
- #self.reduce_memory()
def attemptLogin(self, times = 1):
- #if self.isHildon:
- # dialog = hildon.LoginDialog(self.window)
- # dialog.set_message("Grandcentral Login")
- #else:
dialog = self.wTree.get_widget("login_dialog")
while (0 < times) and not self.gcd.isAuthed():
times = 0
continue
- #if self.isHildon:
- # username = dialog.get_username()
- # password = dialog.get_password()
- #else:
username = self.wTree.get_widget("usernameentry").get_text()
password = self.wTree.get_widget("passwordentry").get_text()
self.wTree.get_widget("passwordentry").set_text("")
dialog.hide()
times = times - 1
- #if self.isHildon:
- # print "destroy dialog"
- # dialog.destroy()
-
return False
def ErrPopUp(self, msg):
self.ErrPopUp("Backend link with grandcentral is not working, please try again")
return
- #if len(self.phonenumber) == 7:
- # #add default area code
- # self.phonenumber = self.areacode + self.phonenumber
-
try:
callSuccess = self.gcd.dial(self.phonenumber)
except ValueError, e:
self.recentmodel.clear()
self.recenttime = 0.0
- #self.reduce_memory()
def on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
"""
re.purge()
gc.collect()
- #if offline (how do I tell this? the message somehow?)
- # disable the gui?
- # disable clearing of caches and when they click dial, request to connect?
-
def setNumber(self, number):
self.phonenumber = makeugly(number)
self.prettynumber = makepretty(self.phonenumber)
def run_dialpad():
- #gc.set_threshold(50, 3, 3)
gtk.gdk.threads_init()
title = 'Dialpad'
handle = Dialpad()
gtk.main()
- sys.exit(1)
+ sys.exit(0)
class DummyOptions(object):
def __init__(self, cookieFile = None):
# Important items in this function are the setup of the browser emulation and cookie file
self._msg = ""
+
+ self._browser = MozillaEmulator(None, 0)
if cookieFile is None:
cookieFile = os.path.join(os.path.expanduser("~"), ".gc_dialer_cookies.txt")
- self._browser = MozillaEmulator(None, 0)
self._browser.cookies.filename = cookieFile
if os.path.isfile(cookieFile):
self._browser.cookies.load()
- #else:
- # self._browser.cookies.save()
+
self._lastData = ""
self._accessToken = None
self._accountNum = None
auth token ( a_t ) from the page. Once logged in
try not to reauth more than once a minute.
"""
-
if time.time() - self._lastAuthed < 60 and not force:
return True