Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprotoframing.py @ 48946:642e31cb55f0
py3: use class X: instead of class X(object):
The inheritance from object is implied in Python 3. So this should
be equivalent.
This change was generated via an automated search and replace. So there
may have been some accidental changes.
Differential Revision: https://phab.mercurial-scm.org/D12352
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 21 Feb 2022 13:08:28 -0700 |
parents | f254fc73d956 |
children | 18c8c18993f0 |
comparison
equal
deleted
inserted
replaced
48945:55d132525155 | 48946:642e31cb55f0 |
---|---|
132 | 132 |
133 return b'|'.join(flags) | 133 return b'|'.join(flags) |
134 | 134 |
135 | 135 |
136 @attr.s(slots=True) | 136 @attr.s(slots=True) |
137 class frameheader(object): | 137 class frameheader: |
138 """Represents the data in a frame header.""" | 138 """Represents the data in a frame header.""" |
139 | 139 |
140 length = attr.ib() | 140 length = attr.ib() |
141 requestid = attr.ib() | 141 requestid = attr.ib() |
142 streamid = attr.ib() | 142 streamid = attr.ib() |
144 typeid = attr.ib() | 144 typeid = attr.ib() |
145 flags = attr.ib() | 145 flags = attr.ib() |
146 | 146 |
147 | 147 |
148 @attr.s(slots=True, repr=False) | 148 @attr.s(slots=True, repr=False) |
149 class frame(object): | 149 class frame: |
150 """Represents a parsed frame.""" | 150 """Represents a parsed frame.""" |
151 | 151 |
152 requestid = attr.ib() | 152 requestid = attr.ib() |
153 streamid = attr.ib() | 153 streamid = attr.ib() |
154 streamflags = attr.ib() | 154 streamflags = attr.ib() |
587 flags=0, | 587 flags=0, |
588 payload=payload, | 588 payload=payload, |
589 ) | 589 ) |
590 | 590 |
591 | 591 |
592 class bufferingcommandresponseemitter(object): | 592 class bufferingcommandresponseemitter: |
593 """Helper object to emit command response frames intelligently. | 593 """Helper object to emit command response frames intelligently. |
594 | 594 |
595 Raw command response data is likely emitted in chunks much smaller | 595 Raw command response data is likely emitted in chunks much smaller |
596 than what can fit in a single frame. This class exists to buffer | 596 than what can fit in a single frame. This class exists to buffer |
597 chunks until enough data is available to fit in a single frame. | 597 chunks until enough data is available to fit in a single frame. |
697 | 697 |
698 # TODO consider defining encoders/decoders using the util.compressionengine | 698 # TODO consider defining encoders/decoders using the util.compressionengine |
699 # mechanism. | 699 # mechanism. |
700 | 700 |
701 | 701 |
702 class identityencoder(object): | 702 class identityencoder: |
703 """Encoder for the "identity" stream encoding profile.""" | 703 """Encoder for the "identity" stream encoding profile.""" |
704 | 704 |
705 def __init__(self, ui): | 705 def __init__(self, ui): |
706 pass | 706 pass |
707 | 707 |
713 | 713 |
714 def finish(self): | 714 def finish(self): |
715 return b'' | 715 return b'' |
716 | 716 |
717 | 717 |
718 class identitydecoder(object): | 718 class identitydecoder: |
719 """Decoder for the "identity" stream encoding profile.""" | 719 """Decoder for the "identity" stream encoding profile.""" |
720 | 720 |
721 def __init__(self, ui, extraobjs): | 721 def __init__(self, ui, extraobjs): |
722 if extraobjs: | 722 if extraobjs: |
723 raise error.Abort( | 723 raise error.Abort( |
726 | 726 |
727 def decode(self, data): | 727 def decode(self, data): |
728 return data | 728 return data |
729 | 729 |
730 | 730 |
731 class zlibencoder(object): | 731 class zlibencoder: |
732 def __init__(self, ui): | 732 def __init__(self, ui): |
733 import zlib | 733 import zlib |
734 | 734 |
735 self._zlib = zlib | 735 self._zlib = zlib |
736 self._compressor = zlib.compressobj() | 736 self._compressor = zlib.compressobj() |
747 res = self._compressor.flush(self._zlib.Z_FINISH) | 747 res = self._compressor.flush(self._zlib.Z_FINISH) |
748 self._compressor = None | 748 self._compressor = None |
749 return res | 749 return res |
750 | 750 |
751 | 751 |
752 class zlibdecoder(object): | 752 class zlibdecoder: |
753 def __init__(self, ui, extraobjs): | 753 def __init__(self, ui, extraobjs): |
754 import zlib | 754 import zlib |
755 | 755 |
756 if extraobjs: | 756 if extraobjs: |
757 raise error.Abort( | 757 raise error.Abort( |
762 | 762 |
763 def decode(self, data): | 763 def decode(self, data): |
764 return self._decompressor.decompress(data) | 764 return self._decompressor.decompress(data) |
765 | 765 |
766 | 766 |
767 class zstdbaseencoder(object): | 767 class zstdbaseencoder: |
768 def __init__(self, level): | 768 def __init__(self, level): |
769 from . import zstd | 769 from . import zstd |
770 | 770 |
771 self._zstd = zstd | 771 self._zstd = zstd |
772 cctx = zstd.ZstdCompressor(level=level) | 772 cctx = zstd.ZstdCompressor(level=level) |
790 class zstd8mbencoder(zstdbaseencoder): | 790 class zstd8mbencoder(zstdbaseencoder): |
791 def __init__(self, ui): | 791 def __init__(self, ui): |
792 super(zstd8mbencoder, self).__init__(3) | 792 super(zstd8mbencoder, self).__init__(3) |
793 | 793 |
794 | 794 |
795 class zstdbasedecoder(object): | 795 class zstdbasedecoder: |
796 def __init__(self, maxwindowsize): | 796 def __init__(self, maxwindowsize): |
797 from . import zstd | 797 from . import zstd |
798 | 798 |
799 dctx = zstd.ZstdDecompressor(max_window_size=maxwindowsize) | 799 dctx = zstd.ZstdDecompressor(max_window_size=maxwindowsize) |
800 self._decompressor = dctx.decompressobj() | 800 self._decompressor = dctx.decompressobj() |
840 | 840 |
841 STREAM_ENCODERS[b'identity'] = (identityencoder, identitydecoder) | 841 STREAM_ENCODERS[b'identity'] = (identityencoder, identitydecoder) |
842 STREAM_ENCODERS_ORDER.append(b'identity') | 842 STREAM_ENCODERS_ORDER.append(b'identity') |
843 | 843 |
844 | 844 |
845 class stream(object): | 845 class stream: |
846 """Represents a logical unidirectional series of frames.""" | 846 """Represents a logical unidirectional series of frames.""" |
847 | 847 |
848 def __init__(self, streamid, active=False): | 848 def __init__(self, streamid, active=False): |
849 self.streamid = streamid | 849 self.streamid = streamid |
850 self._active = active | 850 self._active = active |
993 DEFAULT_PROTOCOL_SETTINGS = { | 993 DEFAULT_PROTOCOL_SETTINGS = { |
994 b'contentencodings': [b'identity'], | 994 b'contentencodings': [b'identity'], |
995 } | 995 } |
996 | 996 |
997 | 997 |
998 class serverreactor(object): | 998 class serverreactor: |
999 """Holds state of a server handling frame-based protocol requests. | 999 """Holds state of a server handling frame-based protocol requests. |
1000 | 1000 |
1001 This class is the "brain" of the unified frame-based protocol server | 1001 This class is the "brain" of the unified frame-based protocol server |
1002 component. While the protocol is stateless from the perspective of | 1002 component. While the protocol is stateless from the perspective of |
1003 requests/commands, something needs to track which frames have been | 1003 requests/commands, something needs to track which frames have been |
1681 | 1681 |
1682 def _onframeerrored(self, frame): | 1682 def _onframeerrored(self, frame): |
1683 return self._makeerrorresult(_(b'server already errored')) | 1683 return self._makeerrorresult(_(b'server already errored')) |
1684 | 1684 |
1685 | 1685 |
1686 class commandrequest(object): | 1686 class commandrequest: |
1687 """Represents a request to run a command.""" | 1687 """Represents a request to run a command.""" |
1688 | 1688 |
1689 def __init__(self, requestid, name, args, datafh=None, redirect=None): | 1689 def __init__(self, requestid, name, args, datafh=None, redirect=None): |
1690 self.requestid = requestid | 1690 self.requestid = requestid |
1691 self.name = name | 1691 self.name = name |
1693 self.datafh = datafh | 1693 self.datafh = datafh |
1694 self.redirect = redirect | 1694 self.redirect = redirect |
1695 self.state = b'pending' | 1695 self.state = b'pending' |
1696 | 1696 |
1697 | 1697 |
1698 class clientreactor(object): | 1698 class clientreactor: |
1699 """Holds state of a client issuing frame-based protocol requests. | 1699 """Holds state of a client issuing frame-based protocol requests. |
1700 | 1700 |
1701 This is like ``serverreactor`` but for client-side state. | 1701 This is like ``serverreactor`` but for client-side state. |
1702 | 1702 |
1703 Each instance is bound to the lifetime of a connection. For persistent | 1703 Each instance is bound to the lifetime of a connection. For persistent |