<s> import logging <EOL> import time <EOL> from selenium . webdriver . common . desired_capabilities import DesiredCapabilities <EOL> from selenium . webdriver . common import utils <EOL> from selenium . webdriver . remote . command import Command <EOL> from selenium . webdriver . remote . remote_connection import RemoteConnection <EOL> from selenium . webdriver . firefox . firefox_binary import FirefoxBinary <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> PORT = <NUM_LIT:0> <EOL> HOST = None <EOL> _URL = "<STR_LIT>" <EOL> class ExtensionConnection ( RemoteConnection ) : <EOL> def __init__ ( self , host , firefox_profile , firefox_binary = None , timeout = <NUM_LIT:30> ) : <EOL> self . profile = firefox_profile <EOL> self . binary = firefox_binary <EOL> HOST = host <EOL> if self . binary is None : <EOL> self . binary = FirefoxBinary ( ) <EOL> if HOST is None : <EOL> HOST = "<STR_LIT:127.0.0.1>" <EOL> PORT = utils . free_port ( ) <EOL> self . profile . port = PORT <EOL> self . profile . update_preferences ( ) <EOL> self . profile . add_extension ( ) <EOL> self . binary . launch_browser ( self . profile ) <EOL> _URL = "<STR_LIT>" % ( HOST , PORT ) <EOL> RemoteConnection . __init__ ( <EOL> self , _URL , keep_alive = True ) <EOL> def quit ( self , sessionId = None ) : <EOL> self . execute ( Command . QUIT , { '<STR_LIT>' : sessionId } ) <EOL> while self . is_connectable ( ) : <EOL> LOGGER . info ( "<STR_LIT>" ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> def connect ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . execute ( Command . NEW_SESSION , <EOL> { '<STR_LIT>' : DesiredCapabilities . FIREFOX } ) <EOL> @ classmethod <EOL> def connect_and_quit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _request ( '<STR_LIT>' % _URL ) <EOL> @ classmethod <EOL> def is_connectable ( self ) : <EOL> """<STR_LIT>""" <EOL> utils . is_connectable ( self . port ) <EOL> class ExtensionConnectionError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
