mercurial/wireprototypes.py
author Pulkit Goyal <7895pulkit@gmail.com>
Thu, 12 Apr 2018 14:28:08 +0530
changeset 37578 56df2ca5c032
parent 37485 0b7475ea38cf
child 37612 5e71dea79aae
permissions -rw-r--r--
py3: prevent transformer from adding b'' by adding r'' prefix These are cases where we need to use str, therefore we add r'' prefix. # skip-blame because just r'' prefixes Differential Revision: https://phab.mercurial-scm.org/D3276
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36111
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com>
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
# GNU General Public License version 2 or any later version.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
from __future__ import absolute_import
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
     8
from .thirdparty.zope import (
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
     9
    interface as zi,
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
    10
)
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
    11
36565
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36402
diff changeset
    12
# Names of the SSH protocol implementations.
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36402
diff changeset
    13
SSHV1 = 'ssh-v1'
37049
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    14
# These are advertised over the wire. Increment the counters at the end
36565
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36402
diff changeset
    15
# to reflect BC breakages.
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36402
diff changeset
    16
SSHV2 = 'exp-ssh-v2-0001'
37049
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    17
HTTPV2 = 'exp-http-v2-0001'
36565
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36402
diff changeset
    18
36638
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    19
# All available wire protocol transports.
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    20
TRANSPORTS = {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    21
    SSHV1: {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    22
        'transport': 'ssh',
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    23
        'version': 1,
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    24
    },
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    25
    SSHV2: {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    26
        'transport': 'ssh',
37294
27527d8cff5c wireproto: mark SSHv2 as a version 1 transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37049
diff changeset
    27
        # TODO mark as version 2 once all commands are implemented.
27527d8cff5c wireproto: mark SSHv2 as a version 1 transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37049
diff changeset
    28
        'version': 1,
36638
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    29
    },
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    30
    'http-v1': {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    31
        'transport': 'http',
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    32
        'version': 1,
37049
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    33
    },
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    34
    HTTPV2: {
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    35
        'transport': 'http',
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36809
diff changeset
    36
        'version': 2,
36638
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    37
    }
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    38
}
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36565
diff changeset
    39
36112
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36111
diff changeset
    40
class bytesresponse(object):
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36111
diff changeset
    41
    """A wire protocol response consisting of raw bytes."""
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36111
diff changeset
    42
    def __init__(self, data):
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36111
diff changeset
    43
        self.data = data
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36111
diff changeset
    44
36111
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
class ooberror(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
    """wireproto reply: failure of a batch of operation
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
    Something failed during a batch call. The error message is stored in
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
    `self.message`.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
    def __init__(self, message):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
        self.message = message
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
class pushres(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
    """wireproto reply: success with simple integer return
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
    The call was successful and returned an integer contained in `self.res`.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
    def __init__(self, res, output):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
        self.res = res
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
        self.output = output
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
class pusherr(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
    """wireproto reply: failure
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
    The call failed. The `self.res` attribute contains the error message.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
    def __init__(self, res, output):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
        self.res = res
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    70
        self.output = output
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    72
class streamres(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    73
    """wireproto reply: binary stream
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
    The call was successful and the result is a stream.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    76
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
    Accepts a generator containing chunks of data to be sent to the client.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    78
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
    ``prefer_uncompressed`` indicates that the data is expected to be
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    80
    uncompressable and that the stream should therefore use the ``none``
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    81
    engine.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    82
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    83
    def __init__(self, gen=None, prefer_uncompressed=False):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    84
        self.gen = gen
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    85
        self.prefer_uncompressed = prefer_uncompressed
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    86
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    87
class streamreslegacy(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    88
    """wireproto reply: uncompressed binary stream
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    89
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    90
    The call was successful and the result is a stream.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    91
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    92
    Accepts a generator containing chunks of data to be sent to the client.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    93
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    94
    Like ``streamres``, but sends an uncompressed data for "version 1" clients
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    95
    using the application/mercurial-0.1 media type.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    96
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    97
    def __init__(self, gen=None):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    98
        self.gen = gen
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
    99
37485
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   100
class cborresponse(object):
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   101
    """Encode the response value as CBOR."""
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   102
    def __init__(self, v):
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   103
        self.value = v
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   104
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   105
class baseprotocolhandler(zi.Interface):
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   106
    """Abstract base class for wire protocol handlers.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   107
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   108
    A wire protocol handler serves as an interface between protocol command
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   109
    handlers and the wire protocol transport layer. Protocol handlers provide
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   110
    methods to read command arguments, redirect stdio for the duration of
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   111
    the request, handle response types, etc.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   112
    """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   113
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   114
    name = zi.Attribute(
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   115
        """The name of the protocol implementation.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   116
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   117
        Used for uniquely identifying the transport type.
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   118
        """)
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   119
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   120
    def getargs(args):
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   121
        """return the value for arguments in <args>
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   122
37485
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   123
        For version 1 transports, returns a list of values in the same
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   124
        order they appear in ``args``. For version 2 transports, returns
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   125
        a dict mapping argument name to value.
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   126
        """
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   127
37393
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   128
    def getprotocaps():
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   129
        """Returns the list of protocol-level capabilities of client
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   130
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   131
        Returns a list of capabilities as declared by the client for
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   132
        the current request (or connection for stateful protocol handlers)."""
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   133
37414
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   134
    def getpayload():
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   135
        """Provide a generator for the raw payload.
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   136
37414
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   137
        The caller is responsible for ensuring that the full payload is
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   138
        processed.
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   139
        """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   140
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   141
    def mayberedirectstdio():
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   142
        """Context manager to possibly redirect stdio.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   143
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   144
        The context manager yields a file-object like object that receives
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   145
        stdout and stderr output when the context manager is active. Or it
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   146
        yields ``None`` if no I/O redirection occurs.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   147
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   148
        The intent of this context manager is to capture stdio output
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   149
        so it may be sent in the response. Some transports support streaming
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   150
        stdio to the client in real time. For these transports, stdio output
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   151
        won't be captured.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   152
        """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   153
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   154
    def client():
36402
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36112
diff changeset
   155
        """Returns a string representation of this client (as bytes)."""
36642
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   156
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   157
    def addcapabilities(repo, caps):
36642
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   158
        """Adds advertised capabilities specific to this protocol.
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   159
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   160
        Receives the list of capabilities collected so far.
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   161
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   162
        Returns a list of capabilities. The passed in argument can be returned.
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36638
diff changeset
   163
        """
36809
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   164
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   165
    def checkperm(perm):
36809
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   166
        """Validate that the client has permissions to perform a request.
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   167
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   168
        The argument is the permission required to proceed. If the client
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   169
        doesn't have that permission, the exception should raise or abort
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   170
        in a protocol specific manner.
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36642
diff changeset
   171
        """