- # replace a double (literal) IAC if there's an LF later
- if command is IAC:
- if text.find("\n", position) > 0:
- position += 1
- text = text[:position] + text[position+1:]
- else: position += 2
-
- # implement an RFC 1143 option negotiation queue here
- elif len_text > position+2 and WILL <= command <= DONT:
- # this will need to be byte type during 2to3 migration
- telopt = ord( text[position+2] )
- if telopt in supported:
- if command <= WONT:
- party = HIM
- rxpos = WILL
- txpos = DO
- txneg = DONT
+ # replace a double (literal) IAC if there's an LF later
+ if command is IAC:
+ if text.find("\n", position) > 0:
+ position += 1
+ text = text[:position] + text[position + 1:]
+ else:
+ position += 2
+
+ # implement an RFC 1143 option negotiation queue here
+ elif len_text > position + 2 and WILL <= command <= DONT:
+ telopt = text[position+2]
+ if telopt in supported:
+ if command <= WONT:
+ party = HIM
+ rxpos = WILL
+ txpos = DO
+ txneg = DONT
+ else:
+ party = US
+ rxpos = DO
+ txpos = WILL
+ txneg = WONT
+ if (telopt, party) not in user.telopts:
+ user.telopts[(telopt, party)] = NO
+ if command is rxpos:
+ if user.telopts[(telopt, party)] is NO:
+ user.telopts[(telopt, party)] = YES
+ send_command(user, txpos, telopt)
+ elif user.telopts[(telopt, party)] is WANTNO:
+ user.telopts[(telopt, party)] = NO
+ elif user.telopts[(telopt, party)] is WANTNO_OPPOSITE:
+ user.telopts[(telopt, party)] = YES
+ elif user.telopts[(telopt, party)] is WANTYES_OPPOSITE:
+ user.telopts[(telopt, party)] = WANTNO
+ send_command(user, txneg, telopt)
+ else:
+ user.telopts[(telopt, party)] = YES
+ else:
+ if user.telopts[(telopt, party)] is YES:
+ user.telopts[(telopt, party)] = NO
+ send_command(user, txneg, telopt)
+ elif user.telopts[(telopt, party)] is WANTNO_OPPOSITE:
+ user.telopts[(telopt, party)] = WANTYES
+ send_command(user, txpos, telopt)
+ else:
+ user.telopts[(telopt, party)] = NO
+ elif command is WILL:
+ send_command(user, DONT, telopt)