MAJOR: Removing all unused (commented out) code
authorepage <eopage@byu.net>
Fri, 4 Jul 2008 15:39:37 +0000 (15:39 +0000)
committerepage <eopage@byu.net>
Fri, 4 Jul 2008 15:39:37 +0000 (15:39 +0000)
 * Browser Emulator layer
 * Hildon stuff not needed due to switch back to gtk.glade or move away from hildon password dialog box
 * not saving the cookie file explicitly

git-svn-id: file:///svnroot/gc-dialer/trunk@55 c39d3808-3fe2-4d86-a59f-b7f623ee9f21

gc_dialer/browser_emu.py
gc_dialer/gc_dialer.py
gc_dialer/gcbackend.py

index c9b685b..0fdc69a 100644 (file)
@@ -32,13 +32,9 @@ TODO:
 - 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
 
 
@@ -61,11 +57,7 @@ class MozillaEmulator(object):
                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
@@ -125,38 +117,6 @@ class MozillaEmulator(object):
                                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
@@ -166,21 +126,6 @@ class MozillaEmulator(object):
                                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."""
@@ -194,35 +139,3 @@ class HTTPNoRedirector(urllib2.HTTPRedirectHandler):
                                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'
-#
index a413ec5..0921e8b 100755 (executable)
@@ -27,15 +27,6 @@ try:
 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:
@@ -142,10 +133,6 @@ class Dialpad(object):
                                '../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:
@@ -200,7 +187,6 @@ class Dialpad(object):
                        "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
@@ -213,16 +199,12 @@ class Dialpad(object):
 
                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()
@@ -306,14 +288,8 @@ class Dialpad(object):
                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():
@@ -321,10 +297,6 @@ class Dialpad(object):
                                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("")
@@ -334,10 +306,6 @@ class Dialpad(object):
                        dialog.hide()
                        times = times - 1
 
-               #if self.isHildon:
-               #       print "destroy dialog"
-               #       dialog.destroy()
-
                return False
 
        def ErrPopUp(self, msg):
@@ -368,10 +336,6 @@ class Dialpad(object):
                        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:
@@ -385,7 +349,6 @@ class Dialpad(object):
 
                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):
                """
@@ -403,10 +366,6 @@ class Dialpad(object):
                        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)
@@ -433,12 +392,11 @@ def run_doctest():
 
 
 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):
index 29a6721..d129244 100644 (file)
@@ -38,14 +38,14 @@ class GCDialer(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
@@ -82,7 +82,6 @@ class GCDialer(object):
                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