I think implementing a finite state automaton would be a good (best?)
solution. I have drawn a FSM for you (try viewing the following in
fixed width font). Just increment the count when you reach state 5.
<---------------|
| |
0 0 | 1 0 |0
-->[1]--->[2]--->[3]--->[4]--->[5]-|
^ | | ^ | | |
1| |<---| | | |1 |1
|_| 1 |_| | |
^ 0 | |
|---------------------|<-----|
If you don't understand FSM's, try getting a book on computational
theory (the book by Hopcroft & Ullman is great.)
Here you don't have special cases whether reading in blocks or reading
whole at once (as you only need one byte at a time).
Vaibhav
--
http://mail.python.org/mailman/listinfo/python-list