HACK: better line iteration

This commit is contained in:
Roman Zeyde
2016-06-02 21:39:14 +03:00
parent f89c5bb125
commit 39cb5565bf
2 changed files with 12 additions and 7 deletions

View File

@@ -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__':

View File

@@ -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)