# HG changeset patch # User Gregory Szorc # Date 1538699956 25200 # Node ID 5d44c4d1d5169101404196f7d4169019dc07bc2a # Parent 293835e0fff7153a9c330e0a5c713c2588778513 wireprotov2: establish dedicated classes for input and output streams Streams are unidirectional. As part of implementing encoding/decoding support, it became clear that it didn't make sense for a generic "stream" class to hold functionality related to both encoding and decoding. So we create new classes to represent the flavor of stream. Differential Revision: https://phab.mercurial-scm.org/D4920 diff -r 293835e0fff7 -r 5d44c4d1d516 mercurial/wireprotoframing.py --- a/mercurial/wireprotoframing.py Thu Oct 04 17:17:57 2018 -0700 +++ b/mercurial/wireprotoframing.py Thu Oct 04 17:39:16 2018 -0700 @@ -668,6 +668,9 @@ return makeframe(requestid, self.streamid, streamflags, typeid, flags, payload) +class inputstream(stream): + """Represents a stream used for receiving data.""" + def setdecoder(self, name, extraobjs): """Set the decoder for this stream. @@ -675,6 +678,9 @@ decoded from the stream encoding settings frame payloads. """ +class outputstream(stream): + """Represents a stream used for sending data.""" + def ensureserverstream(stream): if stream.streamid % 2: raise error.ProgrammingError('server should only write to even ' @@ -799,7 +805,7 @@ _('received frame on unknown inactive stream without ' 'beginning of stream flag set')) - self._incomingstreams[frame.streamid] = stream(frame.streamid) + self._incomingstreams[frame.streamid] = inputstream(frame.streamid) if frame.streamflags & STREAM_FLAG_ENCODING_APPLIED: # TODO handle decoding frames @@ -1012,7 +1018,7 @@ streamid = self._nextoutgoingstreamid self._nextoutgoingstreamid += 2 - s = stream(streamid) + s = outputstream(streamid) self._outgoingstreams[streamid] = s return s @@ -1372,7 +1378,7 @@ self._nextrequestid = 1 # We only support a single outgoing stream for now. - self._outgoingstream = stream(1) + self._outgoingstream = outputstream(1) self._pendingrequests = collections.deque() self._activerequests = {} self._incomingstreams = {} @@ -1485,7 +1491,8 @@ 'without beginning of stream flag set'), } - self._incomingstreams[frame.streamid] = stream(frame.streamid) + self._incomingstreams[frame.streamid] = inputstream( + frame.streamid) if frame.streamflags & STREAM_FLAG_ENCODING_APPLIED: raise error.ProgrammingError('support for decoding stream '