Skip to content

Commit

Permalink
Extract inner class
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhnik committed Jul 18, 2018
1 parent a6e2ecd commit 27e3436
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions lib/StreamFilter.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#!/usr/bin/env python3
"""Filter the stream from within given pair of tokens."""


class _StringMatcher:
def __init__(self, s, hold, succeed, fail):
self.s = s
self.hold = hold
self.succeed = succeed
self.fail = fail
self.idx = 0

def match(self, ch):
if self.s[self.idx] == ch:
self.idx += 1
if self.idx == len(self.s):
self.idx = 0
return self.succeed
return self.hold
self.idx = 0
return self.fail


class StreamFilter:
"""Stream filter class."""

class _StringMatcher:
def __init__(self, s, hold, succeed, fail):
self.s = s
self.hold = hold
self.succeed = succeed
self.fail = fail
self.idx = 0

def match(self, ch):
if self.s[self.idx] == ch:
self.idx += 1
if self.idx == len(self.s):
self.idx = 0
return self.succeed
return self.hold
self.idx = 0
return self.fail

def __init__(self, start, finish):
"""Initialize the filter with start and finish tokens."""
self.passing = StreamFilter._StringMatcher(start,
self._StartHold,
self._StartMatch,
self._StartFail)
self.rejecting = StreamFilter._StringMatcher(finish,
self._Nop,
self._FinishMatch,
self._Nop)
self.passing = _StringMatcher(start,
self._StartHold,
self._StartMatch,
self._StartFail)
self.rejecting = _StringMatcher(finish,
self._Nop,
self._FinishMatch,
self._Nop)
self.state = self.passing
self.buffer = ''

Expand Down

0 comments on commit 27e3436

Please sign in to comment.