'Open port with current settings. This may throw a SerialException
if the port cannot be opened.'

def open(self):

    self.logger = None
    self._ignore_set_control_answer = False
    self._poll_modem_state = False
    self._network_timeout = 3
    if (self._port is None):
        raise SerialException('Port    must    be    configured    before    it    can    be    used.')
    if self.is_open:
        raise SerialException('Port    is    already    open.')
    try:
        self._socket = socket.create_connection(self.from_url(self.portstr), timeout=5)
        self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    except Exception as msg:
        self._socket = None
        raise SerialException('Could    not    open    port    {}:    {}'.format(self.portstr, msg))
    self._read_buffer = Queue.Queue()
    self._write_lock = threading.Lock()
    mandadory_options = [TelnetOption(self, 'we-BINARY', BINARY, WILL, WONT, DO, DONT, INACTIVE), TelnetOption(self, 'we-RFC2217', COM_PORT_OPTION, WILL, WONT, DO, DONT, REQUESTED)]
    self._telnet_options = ([TelnetOption(self, 'ECHO', ECHO, DO, DONT, WILL, WONT, REQUESTED), TelnetOption(self, 'we-SGA', SGA, WILL, WONT, DO, DONT, REQUESTED), TelnetOption(self, 'they-SGA', SGA, DO, DONT, WILL, WONT, REQUESTED), TelnetOption(self, 'they-BINARY', BINARY, DO, DONT, WILL, WONT, INACTIVE), TelnetOption(self, 'they-RFC2217', COM_PORT_OPTION, DO, DONT, WILL, WONT, REQUESTED)] + mandadory_options)
    self._rfc2217_port_settings = {'baudrate': TelnetSubnegotiation(self, 'baudrate', SET_BAUDRATE, SERVER_SET_BAUDRATE), 'datasize': TelnetSubnegotiation(self, 'datasize', SET_DATASIZE, SERVER_SET_DATASIZE), 'parity': TelnetSubnegotiation(self, 'parity', SET_PARITY, SERVER_SET_PARITY), 'stopsize': TelnetSubnegotiation(self, 'stopsize', SET_STOPSIZE, SERVER_SET_STOPSIZE)}
    self._rfc2217_options = {'purge': TelnetSubnegotiation(self, 'purge', PURGE_DATA, SERVER_PURGE_DATA), 'control': TelnetSubnegotiation(self, 'control', SET_CONTROL, SERVER_SET_CONTROL)}
    self._rfc2217_options.update(self._rfc2217_port_settings)
    self._linestate = 0
    self._modemstate = None
    self._modemstate_timeout = Timeout((-1))
    self._remote_suspend_flow = False
    self.is_open = True
    self._thread = threading.Thread(target=self._telnet_read_loop)
    self._thread.setDaemon(True)
    self._thread.setName('pySerial    RFC    2217    reader    thread    for    {}'.format(self._port))
    self._thread.start()
    try:
        for option in self._telnet_options:
            if (option.state is REQUESTED):
                self.telnet_send_option(option.send_yes, option.option)
        timeout = Timeout(self._network_timeout)
        while (not timeout.expired()):
            time.sleep(0.05)
            if (sum((o.active for o in mandadory_options)) == sum(((o.state != INACTIVE) for o in mandadory_options))):
                break
        else:
            raise SerialException('Remote    does    not    seem    to    support    RFC2217    or    BINARY    mode    {!r}'.format(mandadory_options))
        if self.logger:
            self.logger.info('Negotiated    options:    {}'.format(self._telnet_options))
        self._reconfigure_port()
        if (not self._dsrdtr):
            self._update_dtr_state()
        if (not self._rtscts):
            self._update_rts_state()
        self.reset_input_buffer()
        self.reset_output_buffer()
    except:
        self.close()
        raise
