Пример #1
0
	def input(self):
##		print "TkinterGui::MainWindow::input"
		cmd = self.inputField.get(1.0, Tkinter.END)
		self.inputField.delete(1.0, Tkinter.END)
		state = 'mmp'
		mmp = MMPState()
		psyc = PSYCState()
		for line in cmd.split('\n'):
			if line == ".":
				#end of packet
				break
			if line == "" or (not _isModifier(line)
					  and state == 'mmp'):
				state = 'psyc'
				
			if state == 'mmp':				
				mmp.set_state(line)
				continue
			if state == 'psyc':
				if _isModifier(line):
					psyc.set_state(line)
				elif line.__len__() and line[0] == '_':
					psyc.set_mc(line)
				else:
					psyc.append_text(line)

		self.center.send(mmp, psyc)
Пример #2
0
 def register(self):
     psyc = PSYCState()
     mmp = MMPState()
     if self.center:
         mmp.set_state(":_target\t" + self.config.get("main", "uni"))
         psyc.set_mc("_request_link")
         self.center.send(mmp, psyc)
Пример #3
0
    def auth(self):
        psyc = PSYCState()
        mmp = MMPState()
        if self.center:
            # das hier ist sicher weils nur an die eigene uni geht
            mmp.set_state(":_target\t" + self.config.get("main", "uni"))
            psyc.set_state(":_password\t" + self.config.get("main",
                                   "password"))
            psyc.set_mc("_set_password")

            self.center.send(mmp, psyc)
Пример #4
0
class MMPProtocol(asynchat.async_chat):
    """modular message protocol
	   see http://www.psyc.eu/mmp.html for details."""

    def __init__(self, callback, connection):
        asynchat.async_chat.__init__(self, connection)
        self.set_terminator("\n")
        self.buffer = ""
        self.mmp = MMPState()
        self.state = "mmp"
        self.data = []

        self.callback = callback

    def handle_connect(self):
        # dead code neuerdings, eh?
        print "connected... but this is dead code"

    def handle_close(self):
        s = MMPState()
        if self.addr[1] != 4404:
            s._set("_source", "psyc://%s:%d/" % self.addr)
        else:
            s._set("_source", "psyc://%s/" % self.addr[0])
        self.packetReceived(
            s,
            "_notice_circuit_broken\nYour TCP connection to [_source] was broken by the bull from the china shop\n.\n",
        )
        self.close()

    def collect_incoming_data(self, data):
        self.buffer += data

    def found_terminator(self):
        # hierfuer siehe asyncchat.py... das setzt
        # terminator auf 0 zurueck wenns nen int als terminator
        # hat und den findet (line 111)
        if self.get_terminator() == 0:
            self.set_terminator("\n")
        line = self.buffer
        self.buffer = ""
        self.lineReceived(line)

    def lineReceived(self, line):
        # kind of state machine
        line = line.strip()
        if line == ".":
            ##			print "<<EOP>>"
            self.packetReceived(self.mmp, self.data)
            # reset state, clear temporary variables, etc
            self.mmp.reset_state()
            self.data = []
            self.state = "mmp"
            return

        if (line == "" or not _isModifier(line)) and self.state == "mmp":
            # if we have _length for data then
            # binary support
            if self.mmp._query("_length"):
                self.set_terminator(self.mmp._query("_length"))
            self.state = "data"
        ##		print "<<" + self.state + ">> " + line 	## comment out
        if self.state == "mmp":
            # maybe else with the above could also work...
            self.mmp.set_state(line)
            return
        elif line != "":
            self.data += [line]

    def packetReceived(self, mmp, data):
        ##		print "MMPProtocol::packetReceived"
        ##	         print "=>MMP :", mmp.get_state()
        ##		print "=>data:", data
        self.callback.packetReceived(mmp, data)

    def sendPacket(self, mmp, data):
        ##		print "calling MMPProtocol::sendPacket()"
        packet = mmp.plain()
        packet += "\n" + data + "\n.\n"
        if debug:
            print ">>send>>\n", packet, "<<send<<\n"
        self.push(packet)