mirror of
https://github.com/romanz/amodem.git
synced 2026-02-09 02:48:01 +08:00
HACK: better line iteration
This commit is contained in:
@@ -49,6 +49,14 @@ def pksign(keygrip, digest, algo):
|
||||
return result
|
||||
|
||||
|
||||
def iterlines(conn):
|
||||
while True:
|
||||
line = keyring.recvline(conn)
|
||||
if line is None:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def handle_connection(conn):
|
||||
"""Handle connection from GPG binary using the ASSUAN protocol."""
|
||||
keygrip = None
|
||||
@@ -56,8 +64,7 @@ def handle_connection(conn):
|
||||
algo = None
|
||||
|
||||
keyring.sendline(conn, b'OK')
|
||||
while True:
|
||||
line = keyring.recvline(conn)
|
||||
for line in iterlines(conn):
|
||||
parts = line.split(' ')
|
||||
command = parts[0]
|
||||
args = parts[1:]
|
||||
@@ -90,10 +97,7 @@ def main():
|
||||
with server.unix_domain_socket_server(sock_path) as sock:
|
||||
for conn in yield_connections(sock):
|
||||
with contextlib.closing(conn):
|
||||
try:
|
||||
handle_connection(conn)
|
||||
except EOFError:
|
||||
break
|
||||
handle_connection(conn)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -42,7 +42,8 @@ def recvline(sock):
|
||||
while True:
|
||||
c = sock.recv(1)
|
||||
if not c:
|
||||
raise EOFError
|
||||
return None # socket is closed
|
||||
|
||||
if c == b'\n':
|
||||
break
|
||||
reply.write(c)
|
||||
|
||||
Reference in New Issue
Block a user