<s> import hashlib <EOL> import os <EOL> import sys <EOL> import datetime <EOL> import tempfile <EOL> from PyQt4 import QtCore <EOL> from PyQt4 import QtGui <EOL> from PyQt4 import QtWebKit <EOL> from PyQt4 import QtNetwork <EOL> PWD = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> fn = os . path . basename ( os . path . splitext ( __file__ ) [ <NUM_LIT:0> ] ) <EOL> PATH_TEMP = os . path . join ( tempfile . gettempdir ( ) , fn ) <EOL> if not os . path . exists ( PATH_TEMP ) : <EOL> os . makedirs ( PATH_TEMP ) <EOL> def to_uni ( obj ) : <EOL> if isinstance ( obj , bytes ) : <EOL> try : <EOL> return obj . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> return obj . decode ( '<STR_LIT>' ) <EOL> elif isinstance ( obj , ( int , long ) ) : <EOL> return unicode ( obj ) <EOL> elif isinstance ( obj , ( datetime . date , datetime . datetime ) ) : <EOL> return unicode ( obj ) <EOL> else : <EOL> return obj <EOL> def to_str ( obj ) : <EOL> if isinstance ( obj , unicode ) : <EOL> return obj . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return obj <EOL> class App ( QtGui . QMainWindow ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( App , self ) . __init__ ( parent ) <EOL> x , y , w , h = <NUM_LIT> , <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> <EOL> self . setGeometry ( x , y , w , h ) <EOL> self . setFixedSize ( w , h ) <EOL> self . url_lineedit = QtGui . QLineEdit ( self ) <EOL> self . url_lineedit . setGeometry ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . connect ( self . url_lineedit , QtCore . SIGNAL ( '<STR_LIT>' ) , self . url_returnPressed ) <EOL> self . progressbar = QtGui . QProgressBar ( self ) <EOL> self . progressbar . setGeometry ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . progressbar . setMinimum ( <NUM_LIT:0> ) <EOL> self . progressbar . setMaximum ( <NUM_LIT:100> ) <EOL> self . webview = QtWebKit . QWebView ( self ) <EOL> qsettings = self . webview . settings ( ) <EOL> qsettings . setAttribute ( QtWebKit . QWebSettings . DeveloperExtrasEnabled , True ) <EOL> self . webview . setGeometry ( <NUM_LIT:0> , <NUM_LIT> , w , h ) <EOL> self . connect ( self . webview , QtCore . SIGNAL ( "<STR_LIT>" ) , self . webview_loadStarted ) <EOL> self . connect ( self . webview , QtCore . SIGNAL ( "<STR_LIT>" ) , self . webview_loadFinished ) <EOL> self . connect ( self . webview , QtCore . SIGNAL ( '<STR_LIT>' ) , self . webview_loadProgress ) <EOL> cache = QtNetwork . QNetworkDiskCache ( ) <EOL> dir = QtGui . QDesktopServices . storageLocation ( QtGui . QDesktopServices . CacheLocation ) <EOL> cache . setCacheDirectory ( dir ) <EOL> self . am = self . webview . page ( ) . networkAccessManager ( ) <EOL> self . am . setCache ( cache ) <EOL> self . cj = QtNetwork . QNetworkCookieJar ( ) <EOL> self . am . setCookieJar ( self . cj ) <EOL> self . _portal_url = "<STR_LIT>" <EOL> self . url_lineedit . setText ( self . _portal_url ) <EOL> self . webview . load ( QtCore . QUrl ( self . _portal_url ) ) <EOL> self . url_lineedit . setFocus ( ) <EOL> self . setup_global_shortcuts ( ) <EOL> @ property <EOL> def url ( self ) : <EOL> s = str ( self . url_lineedit . text ( ) ) . strip ( ) <EOL> if not s . startswith ( '<STR_LIT:http>' ) : <EOL> return '<STR_LIT>' + s <EOL> return s <EOL> @ property <EOL> def entry_body ( self ) : <EOL> frame = self . webview . page ( ) . mainFrame ( ) <EOL> return to_uni ( str ( frame . toHtml ( ) . toUtf8 ( ) ) ) <EOL> def setup_global_shortcuts ( self ) : <EOL> show_debug_option_kseq = "<STR_LIT>" <EOL> key_seq = QtGui . QKeySequence ( show_debug_option_kseq ) <EOL> act = QtGui . QAction ( self ) <EOL> act . setShortcut ( key_seq ) <EOL> self . addAction ( act ) <EOL> act . triggered . connect ( self . _url_lineedit_get_focus ) <EOL> def _url_lineedit_get_focus ( self ) : <EOL> self . url_lineedit . setFocus ( ) <EOL> self . url_lineedit . setSelection ( <NUM_LIT:0> , len ( self . url ) ) <EOL> def show_and_raise ( self ) : <EOL> self . show ( ) <EOL> self . raise_ ( ) <EOL> def url_returnPressed ( self ) : <EOL> self . webview . load ( QtCore . QUrl ( self . url ) ) <EOL> def webview_loadProgress ( self , progress ) : <EOL> self . progressbar . setValue ( progress ) <EOL> def webview_loadStarted ( self ) : <EOL> print '<STR_LIT>' <EOL> self . progressbar . setValue ( <NUM_LIT:0> ) <EOL> def webview_loadFinished ( self , result ) : <EOL> print '<STR_LIT>' , result <EOL> if result : <EOL> save_to = os . path . join ( PATH_TEMP , hashlib . sha1 ( self . url ) . hexdigest ( ) ) <EOL> with open ( save_to , '<STR_LIT:w>' ) as f : <EOL> print '<STR_LIT>' % save_to <EOL> f . write ( to_str ( self . entry_body ) ) <EOL> path_jq = os . path . join ( PWD , '<STR_LIT>' ) <EOL> with open ( path_jq ) as f : <EOL> js_code = f . read ( ) <EOL> self . webview . page ( ) . mainFrame ( ) . evaluateJavaScript ( js_code ) <EOL> js_code = """<STR_LIT>""" <EOL> self . webview . page ( ) . mainFrame ( ) . evaluateJavaScript ( js_code ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> demo = App ( ) <EOL> demo . show_and_raise ( ) <EOL> sys . exit ( app . exec_ ( ) ) </s>
