Mercurial > templog
comparison server/ts.py @ 132:97aad4471593
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 14 Oct 2012 21:51:55 +0800 |
parents | de950be796dd |
children | 94330d90f11f |
comparison
equal
deleted
inserted
replaced
130:66d5e15f40d0 | 132:97aad4471593 |
---|---|
41 | 41 |
42 return s | 42 return s |
43 | 43 |
44 | 44 |
45 def flush(sock): | 45 def flush(sock): |
46 while readline(sock): | 46 ret = [] |
47 pass | 47 while True: |
48 l = readline(sock) | |
49 if l: | |
50 ret.append(l) | |
51 else: | |
52 break | |
53 return ret | |
54 | |
55 def encode_extra(extra_lines): | |
56 return ['extra%d=%s' % (n, l.strip()) for (n,l) in enumerate(extra_lines)] | |
48 | 57 |
49 @retry() | 58 @retry() |
50 def fetch(sock): | 59 def fetch(sock): |
51 flush(sock) | 60 extra_lines = flush(sock) |
52 sock.send("fetch\n") | 61 sock.send("fetch\n") |
53 | 62 |
54 crc = 0 | 63 crc = 0 |
55 | 64 |
56 lines = [] | 65 lines = [] |
57 l = readline(sock) | 66 l = readline(sock) |
67 if not l: | |
68 return None | |
69 | |
58 if l != 'START\n': | 70 if l != 'START\n': |
59 W("Bad expected START line '%s'\n" % str(l).rstrip('\n')) | 71 W("Bad expected START line '%s'\n" % l.rstrip('\n')) |
60 return None | 72 extra_lines.append(l) |
73 return encode_extra(extra_lines) | |
61 crc = crc16(l, crc) | 74 crc = crc16(l, crc) |
62 | 75 |
63 while True: | 76 while True: |
64 l = readline(sock) | 77 l = readline(sock) |
65 | 78 |
67 | 80 |
68 if l == 'END\n': | 81 if l == 'END\n': |
69 break | 82 break |
70 | 83 |
71 lines.append(l.rstrip('\n')) | 84 lines.append(l.rstrip('\n')) |
85 | |
86 lines += encode_extra(extra_lines) | |
72 | 87 |
73 for d in lines: | 88 for d in lines: |
74 L("Received: %s" % d) | 89 L("Received: %s" % d) |
75 | 90 |
76 l = readline(sock) | 91 l = readline(sock) |