コード例 #1
0
ファイル: connector.py プロジェクト: cyberklin/mpei-imm
class Connector(Protocol):

    def __init__(self):
        self.port = Port(use_stdio=False)
        pass

    def write(self, data):
        return self.port.write(data)
        
    def ping(self):
        while __builtin__.THREADS_RUN == True:
            try:
                self.write(Atom("ping"))
            except OSError:                
                print "PYGUI: erlang port gone away, exiting"
                sys.exit(0)    
            time.sleep(1)
        self.port.write(Atom("quit"))

    def main(self):
        self.run(self.port)

    def handle_pong(self):
        if not __builtin__.THREADS_RUN == True:
            self.port.write(Atom("quit"))            
            sys.exit(0)
コード例 #2
0
from erlport import Port, Protocol, String


# Inherit custom protocol from erlport.Protocol
class HelloProtocol(Protocol):

    # Function handle_NAME will be called for incoming tuple {NAME, ...}
    def handle_hello(self, name):
        # String wrapper forces name to be a string instead of a list
        return "Hello, %s" % String(name)


if __name__ == "__main__":
    proto = HelloProtocol()
    # Run protocol with port open on STDIO
    proto.run(Port(use_stdio=True))
コード例 #3
0
ファイル: echo.py プロジェクト: gar1t/python_port
from erlport import Port, Protocol


class Echo(Protocol):
    def handle_echo(self, msg):
        return msg


if __name__ == '__main__':
    Echo().run(Port(packet=4, use_stdio=True))
コード例 #4
0
            if l[1][0] != "text":
                ret.append((
                    l[1][0],
                    l[0],
                ))
        ret.sort()
        return [(
            'text',
            'Plain text',
        )] + ret

    def handle_highlight(self, code, lexer_name, formatter_name, options):
        try:
            lexer = lexers.get_lexer_by_name(lexer_name)
        except:
            lexer = lexers.get_lexer_by_name('text')

        if formatter_name == "SimpleFormatter":
            formatter_class = SimpleFormatter
        else:
            formatter_class = getattr(formatters, formatter_name)

        formatter = SimpleFormatter(**dict(options))
        return highlight(code, lexer, formatter)


if __name__ == "__main__":
    proto = HighlightProtocol()
    # Run protocol with port open on STDIO
    proto.run(Port(packet=4, use_stdio=True, compressed=True))
コード例 #5
0
ファイル: m2crypto.py プロジェクト: satish-zol/auth
            return True
        else:
            return False

    def handle_sign(self, pem, message):
        try:
            Key = M2Crypto.RSA.load_key_string(pem)
        except:
            return "key read error"
        return Key.sign_rsassa_pss(String(message)).encode('base64')

    def handle_decrypt(self, pem, message):
        try:
            Key = M2Crypto.RSA.load_key_string(pem)
        except:
            return "key read error"
        clear = Key.private_decrypt(
            String(message).decode('base64'), M2Crypto.RSA.pkcs1_oaep_padding)
        return clear

    def handle_split_key(self, filename):
        try:
            pubkey = M2Crypto.RSA.load_pub_key(String(filename))
            return (pubkey.e, pubkey.n)
        except:
            return False


if __name__ == "__main__":
    M2cryptoProtocol().run(Port(packet=4, use_stdio=True))
コード例 #6
0
from erlport import Port, Protocol
from erlport import Atom


class EventHandler(Protocol):
    def __init__(self):
        self.collected = []

    def handle(self, port, message):
        if message == Atom("stop"):
            port.write(self.collected)
            self.collected = []
        else:
            self.collected.append(message)


if __name__ == "__main__":
    proto = EventHandler()
    proto.run(Port(packet=4, use_stdio=True))
コード例 #7
0
ファイル: connector.py プロジェクト: cyberklin/mpei-imm
 def __init__(self):
     self.port = Port(use_stdio=False)
     pass
コード例 #8
0
ファイル: arith.py プロジェクト: gar1t/python_port
from erlport import Port, Protocol


class Arith(Protocol):
    def handle_add(self, x, y):
        return x + y

    def handle_subtr(self, x, y):
        return x - y

    def handle_mult(self, x, y):
        return x * y

    def handle_div(self, x, y):
        return x / y


if __name__ == '__main__':
    Arith().run(Port(packet=4, use_stdio=True))