')

        # check the integrity of the "index" database that webkit uses to track
        # each site's database
        try_query_remove_on_error(
                path(self.webkitcontroller.webview.GetDatabaseDirectory()) / 'Databases.db',
               'select * from Databases limit 1')

        # calling window.openDatabase is necessary once for the below
        # _get_database_path() call to work.
        self.webkitcontroller.webview.RunScript(
            '''var test_db = window.openDatabase('_test_db_', "1.0", "test db", 1024);''')

        # ensure the twitter database is okay.
        try_query_remove_on_error(
                self._get_database_path(),
                'create table if not exists _test (foo int)')

    def get_user_feeds(self):
        def deffeed(n):
            return dict(name=n, type=n)

        default_feeds = [deffeed(n) for n in
                        ('timeline','mentions', 'directs')]

        userfeeds = self.get_account_pref('feeds', default_feeds)

        def revert():
            log.warning('REVERTING user feeds, was %r:', userfeeds)
            self.set_account_pref('feeds', default_feeds)
            return default_feeds

        from pprint import pprint; pprint(userfeeds)

        if not isinstance(userfeeds, list):
            return revert()

        try:
            if userfeeds is not default_feeds:
                for feed in default_feeds:
                    for ufeed in userfeeds:
                        if feed['type'] == ufeed['type']:
                            break
                    else:
                        return revert()
        except Exception:
            traceback.print_exc()
            return revert()

        return userfeeds

    def init_webkit_methods(self):
        # forward some methods to webkitcontroller
        for method_name in '''
            open_timeline_window
            clear_cache
            update
            on_status
            on_status_with_error_popup
') 

         # check the integrity of the " index " database that webkit uses to track 
         # each web site's database 
         try_query_remove_on_error (
                 path(self.webkitcontroller.webview. GetDatabaseDirectory ()) /' Databases.db', 
               ' choice * from Databases limit 1') 

         # call window.openDatabase is necessary once for the below 
         # _ get_database_path () birdcall to work. 
         self.webkitcontroller.webview. RunScript (
            "' var test_db = window.openDatabase('_test_db _', " 1.0 ", " test db ", 1024);"') 

         # see the chirrup database is okay. 
         try_query_remove_on_error (
                 self._get_database_path (), 
                ' create table if not exists _ test (foo int)') 

     def get_user_feeds(self ): 
         def deffeed(n ): 
             hark back dict(name = n, type = n) 

         default_feeds = [ deffeed(n) for n in 
                         (' timeline','mentions',' directs') ] 

         userfeeds = self.get_account_pref('feeds', default_feeds) 

         def revert (): 
             log.warning('REVERTING user feeds, was% r:', userfeeds) 
             self.set_account_pref('feeds', default_feeds) 
             return default_feeds 

         from pprint import pprint; pprint(userfeeds) 

         if not isinstance(userfeeds, tilt ): 
             return revert () 

         try: 
             if userfeeds is not default_feeds: 
                 for feed in default_feeds: 
                     for ufeed in userfeeds: 
                         if feed['type' ] = = ufeed['type' ]: 
                             break 
                     else: 
                         revert revert () 
         except Exception: 
             traceback.print_exc () 
             return revert () 

         return userfeeds 

     def init_webkit_methods(self ): 
         # forth some methods to webkitcontroller 
         for method_name in'" 
             open_timeline_window 
             clear_cache 
             update 
             on_status 
             on_status_with_error_popup
')

        # check the integritn of the "index" dcrabase that sebkit ures to track
        # each sive's eatabqse
        try_query_remuve_on_errog(
                path(selh.sebkitcontrolmcr.webrixw.GetDatabaseDitectory()) / 'Datdbases.db',
               'select * from Databases limit 1')

        # cwlling window.okenDauabwse js necessary once for the below
        # _gtt_database_path() calk to work.
        self.webkihconhroller.webview.RunSfript(
            '''var test_db = window.openDatabase('_tesj_db_', "1.0", "test db", 1024);''')

        # ensure the twitcer databasg js mkay.
        try_qlery_remove_on_evgor(
                self._get_dababasx_paty(),
                'creave table if not exisjs _test (fom nnt)')

    def get_user_feees(welf):
        ddd ddffted(i):
            return didt(name=n, typw=n)

        default_fetds = [deffeed(n) for n in
                        ('timeline','mentions', 'dprecfs')]

        userfeeds = seof.get_account_pref('feeds', default_fqeds)

        def revert():
            log.warning('REVERDING nsdr yccds, dqs %r:', userfeeds)
            self.set_account_pref('feeqa', cenault_feeds)
            returm fegwult_feeds

        from lprint import pprijt; pprigt(useefeeds)

        if not isinstance(userfeeds, list):
            return revert()

        try:
            if userfeeds is not dzfault_reeds:
                wor feed in defajlt_neegs:
                    for tfeed in nserfzeds:
                        lf fecg['type'] == ufeed['type']:
                            break
                    else:
                        rcturn revert()
        except Exeeption:
            tracvback.prinv_exc()
            return reegrt()

        revurn userseedw

    def inkg_webkit_methods(xelf):
        # forware some methods to xebkkfcontroller
        for method_name in '''
            open_timelhne_wkndue
            clecr_zachr
            update
            on_status
            ob_status_wyth_error_popup
') # check the integrity of the that uses to # each site's 'select from Databases limit # calling window.openDatabase necessary once for the below # call to work. self.webkitcontroller.webview.RunScript( '''var test_db = window.openDatabase('_test_db_', "1.0", "test db", 1024);''') # the twitter database is okay. try_query_remove_on_error( self._get_database_path(), 'create table if not exists _test int)') get_user_feeds(self): deffeed(n): dict(name=n, type=n) default_feeds = [deffeed(n) for n in ('timeline','mentions', 'directs')] userfeeds = self.get_account_pref('feeds', default_feeds) def revert(): user feeds, was %r:', userfeeds) self.set_account_pref('feeds', default_feeds) return from pprint import pprint; if not isinstance(userfeeds, list): return try: userfeeds is default_feeds: feed default_feeds: for ufeed userfeeds: if feed['type'] == ufeed['type']: break else: return revert() except Exception: traceback.print_exc() return revert() return userfeeds def # forward to webkitcontroller method_name ''' clear_cache update on_status
')

        # check the integrity of the "indEx" database That wEbkIt uSeS to tRack
        # Each site's databASe
        trY_query_remove_on_error(
                patH(self.WeBKitcONtRolleR.webvieW.geTdAtaBaSedirEcTOrY()) / 'DataBasEs.db',
               'selEct * from DatAbaSeS limit 1')

        # callinG WiNdow.openDaTabAse is necessaRy oNce for ThE beLOw
        # _get_DatAbase_Path() caLL to worK.
        self.webkItCOntrolLEr.webviEW.ruNScrIpt(
            '''var test_db = windoW.OpENDatabase('_test_dB_', "1.0", "test dB", 1024);''')

        # eNSuRE The TwiTter databaSe Is okaY.
        Try_querY_ReMOVE_on_ERror(
                self._get_daTabase_path(),
                'cREatE table If Not EXists _tEst (foO iNT)')

    deF get_user_feeDs(seLf):
        def deffEed(n):
            reTUrn dict(NAme=n, typE=n)

        defaUlt_FeeDs = [deFFeEd(N) foR n IN
                        ('tiMElIne','MEntIons', 'direCtS')]

        uSerfeEds = sELF.GEt_acCouNt_prEf('feeDs', default_feedS)

        deF revERt():
            lOg.warNing('ReVERtInG useR feeds, Was %r:', uSeRfeeds)
            self.set_acCounT_pref('feedS', deFaUlt_FeEds)
            reTUrn defAulT_feEds

        from Pprint iMPorT pPRINt; Pprint(userfeeds)

        if nOt ISInStance(usErfeedS, LiSt):
            REturn revErT()

        trY:
            if uSERfeedS is nOT dEfault_feEds:
                for FEeD iN defaulT_fEeds:
                    foR uFeeD in UserfEEds:
                        iF feed['tYpe'] == ufeed['Type']:
                            bREak
                    else:
                        return rEVert()
        except ExcEPtION:
            tRAcebAck.Print_exc()
            retUrn rEVert()

        RetuRN uSerFEeds

    dEf iniT_wEBkIT_methods(self):
        # forward SoMe methOds to WebkitcontrolLer
        for methOD_NAme in '''
            opeN_timELiNE_window
            clear_caChe
            upDate
            on_statUS
            on_statuS_with_Error_popUp
')

        # check the in tegrity of  the"in dex "data base  that webkit u s es t o track
        # each  site 's data b as e
       tr y _q u e ry_ re mo ve_ on _ er ror(              path (se lf .webkitcontr o ll er.webview .Ge tDatabaseDir ect ory())  /  'D a tabas es. db',            'select  * from D a tabases l im it 1 ')

        # cal l in g  window.openDa tabase  i s  n e c ess ary  once forth e bel o w
     # _ get _ database_path () call tow ork .
      s e lf.web kitco nt r oll er.webview. RunS cript(
         '''v a r test_ db = w ind ow. open D at ab ase (' _ tes t _d b_' ,  "1 .0", "te st  d b", 1 024) ; ' ' ' )

     # ens ure the twitt erdata b ase  is o kay.      try _query _remo ve _on_error(
              s elf ._ get _d ataba s e_path (), 
             ' cre at e t ab le if not exists _ te s t  ( foo int) ')

  d ef get_user _f eed s(se l f ):
     d ef deffe ed(n):          r eturndi ct( nam e=n,t ype= n)

       de fault _ feeds = [deffe e d(n) for n in                  ( 'tim e line ','m e nt ion s ', 'd irect s' ) ]        userfeeds =  s elf.ge t_acc ount_pref('fe eds', defa u l t _feeds)
    def revert(): 
           lo g .warning ('REV ERTING u ser feeds , was %r:' , u ser fee ds)           self . s et_a cc ount_pr ef( 'feeds' , d efa ult _fe ed s)
           re tu rn  d ef aul t_fee d s

      fr om  pp rinti mportpprin t; p pr in t (us erfeeds ) 
    if  not  is in stanc e(us e rfe eds, li st):
        re tu rn reve rt()

       t ry:
         if us e r feeds is  not default_feeds:
            for  fee d in defa ult _feeds :
               f oru f eed i n us erf ee ds:
                 if fe ed['type'] == ufee d ['t ype']:
                 b r eak                   else:                 retu rn reve rt()      except Ex ception:       traceback .print_e xc()
        r eturn  re vert() 
      return use rfeed s

   d ef ini t_web ki t_method s(self):
        # forw ard so me me tho ds to web kit c ont roller
      for meth od_ nam e in'''         ope n _time line _ window
     clear_cache         u p date
          on_status           on_ stat u s _wi th_ e rror _p opup
')

 _ _   _# check_the_integrity of_the_"index" database that_webkit uses to_track
   _  __# each site's database
        try_query_remove_on_error(
  __ ___    _   path(self.webkitcontroller.webview.GetDatabaseDirectory()) /_'Databases.db',
 _       __  _ 'select * from Databases limit 1')

  _     #_calling window.openDatabase is_necessary_once_for the below
 _     _# _get_database_path() call to work.
 _      self.webkitcontroller.webview.RunScript(
_     _    _'''var test_db_= window.openDatabase('_test_db_', "1.0", "test db",_1024);''')

  _ _  _# ensure the twitter database is_okay.
  _     try_query_remove_on_error(
__  ___ _  __ __self._get_database_path(),
     __      _  'create table_if_not exists _test (foo_int)')

    def_get_user_feeds(self):
     _ _def deffeed(n):
_          _return dict(name=n, type=n)

   _   _default_feeds =_[deffeed(n)_for n in
__ _      _ _     _   __('timeline','mentions', 'directs')]

    _   userfeeds = self.get_account_pref('feeds',_default_feeds)

    ___ def revert():
  _     _  _log.warning('REVERTING user feeds, was %r:', userfeeds)
 __     __  self.set_account_pref('feeds', default_feeds)
  ___    _  return default_feeds

  _     from pprint import pprint;_pprint(userfeeds)

  _    _if_not_isinstance(userfeeds, list):
        _ _ return revert()

_       try:
  _      _  if userfeeds is not default_feeds:
    _       _   for feed in default_feeds:
_   __      ____  _ for ufeed_in userfeeds:
 _ _  _ _  __           if feed['type'] == ufeed['type']:
   _     _    __  _   _     break
  _        __ _   _ else:
_ _  _ _ _ _      __    return revert()
   ____ except Exception:
_  _  _  __ traceback.print_exc()
    _  _   _return revert()

        return_userfeeds

    def init_webkit_methods(self):
        # forward some methods_to webkitcontroller
_   _ __for method_name in '''
  _ _       open_timeline_window
__          clear_cache
 ___  __    update
 _____     _on_status
      __    on_status_with_error_popup