Micro-optimization
This commit is contained in:
parent
56bff2f4a7
commit
bbdfce2141
@ -174,20 +174,11 @@ class Stream(object):
|
|||||||
if screen is self.listener:
|
if screen is self.listener:
|
||||||
self.listener = None
|
self.listener = None
|
||||||
|
|
||||||
def feed(self, data):
|
def feed(self, data: bytes) -> None:
|
||||||
"""Consumes a string and advances the state as necessary.
|
"""Consumes a string and advances the state as necessary.
|
||||||
|
|
||||||
:param bytes data: a blob of data to feed from.
|
:param bytes data: a blob of data to feed from.
|
||||||
"""
|
"""
|
||||||
if isinstance(data, str):
|
|
||||||
warnings.warn("As of version 0.6.0 ``pyte.streams.Stream.feed``"
|
|
||||||
"requires input in bytes. This warnings will become "
|
|
||||||
"and error in 0.6.1.")
|
|
||||||
data = data.encode("utf-8")
|
|
||||||
elif not isinstance(data, bytes):
|
|
||||||
raise TypeError("{0} requires bytes input"
|
|
||||||
.format(self.__class__.__name__))
|
|
||||||
|
|
||||||
send = self._parser.send
|
send = self._parser.send
|
||||||
draw = self.listener.draw
|
draw = self.listener.draw
|
||||||
match_text = self._text_pattern.match
|
match_text = self._text_pattern.match
|
||||||
@ -199,7 +190,7 @@ class Stream(object):
|
|||||||
while offset < length:
|
while offset < length:
|
||||||
if taking_plain_text:
|
if taking_plain_text:
|
||||||
match = match_text(data, offset)
|
match = match_text(data, offset)
|
||||||
if match:
|
if match is not None:
|
||||||
start, offset = match.span()
|
start, offset = match.span()
|
||||||
draw(data[start:offset])
|
draw(data[start:offset])
|
||||||
else:
|
else:
|
||||||
@ -348,20 +339,6 @@ class Stream(object):
|
|||||||
draw(char)
|
draw(char)
|
||||||
|
|
||||||
|
|
||||||
class ByteStream(Stream):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
warnings.warn("As of version 0.6.0 ``pyte.streams.ByteStream`` is an "
|
|
||||||
"alias for ``pyte.streams.Stream``. The former will be "
|
|
||||||
"removed in pyte 0.6.1.", DeprecationWarning)
|
|
||||||
|
|
||||||
if kwargs.pop("encodings", None):
|
|
||||||
warnings.warn(
|
|
||||||
"As of version 0.6.0 ``pyte.streams.ByteStream`` no longer "
|
|
||||||
"decodes input.", DeprecationWarning)
|
|
||||||
|
|
||||||
super(ByteStream, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class DebugStream(Stream):
|
class DebugStream(Stream):
|
||||||
r"""Stream, which dumps a subset of the dispatched events to a given
|
r"""Stream, which dumps a subset of the dispatched events to a given
|
||||||
file-like object (:data:`sys.stdout` by default).
|
file-like object (:data:`sys.stdout` by default).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user