mercurial/wireprototypes.py
author Boris Feld <boris.feld@octobus.net>
Mon, 22 Oct 2018 15:47:30 +0200
changeset 40401 6bd477ee7294
parent 40328 2c55716f8a1c
child 40492 440f5b65be57
permissions -rw-r--r--
logtoprocess: fix message formatting The logtoprocess used to try formatting the message using keyword options instead of always using the rest of the arguments. Update it to match blackbox behavior. Differential Revision: https://phab.mercurial-scm.org/D5180
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36073
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
37612
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
     8
from .node import (
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
     9
    bin,
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
    10
    hex,
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
    11
)
37783
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
    12
from .i18n import _
40020
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
    13
from .thirdparty import (
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
    14
    attr,
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
    15
)
37783
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
    16
from . import (
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
    17
    error,
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
    18
    util,
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
    19
)
37810
856f381ad74b interfaceutil: module to stub out zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37783
diff changeset
    20
from .utils import (
856f381ad74b interfaceutil: module to stub out zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37783
diff changeset
    21
    interfaceutil,
856f381ad74b interfaceutil: module to stub out zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37783
diff changeset
    22
)
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
    23
36536
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36371
diff changeset
    24
# Names of the SSH protocol implementations.
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36371
diff changeset
    25
SSHV1 = 'ssh-v1'
37046
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36801
diff changeset
    26
# These are advertised over the wire. Increment the counters at the end
36536
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36371
diff changeset
    27
# to reflect BC breakages.
40176
41263df08109 wireprotov2: change how revisions are specified to changesetdata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40172
diff changeset
    28
SSHV2 = 'exp-ssh-v2-0003'
41263df08109 wireprotov2: change how revisions are specified to changesetdata
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40172
diff changeset
    29
HTTP_WIREPROTO_V2 = 'exp-http-v2-0003'
36536
3cd245945ef3 wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36371
diff changeset
    30
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40025
diff changeset
    31
NARROWCAP = 'exp-narrow-1'
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40025
diff changeset
    32
ELLIPSESCAP = 'exp-ellipses-1'
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40025
diff changeset
    33
36609
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    34
# All available wire protocol transports.
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    35
TRANSPORTS = {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    36
    SSHV1: {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    37
        'transport': 'ssh',
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    38
        'version': 1,
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    39
    },
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    40
    SSHV2: {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    41
        'transport': 'ssh',
37294
27527d8cff5c wireproto: mark SSHv2 as a version 1 transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37046
diff changeset
    42
        # 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: 37046
diff changeset
    43
        'version': 1,
36609
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    44
    },
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    45
    'http-v1': {
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    46
        'transport': 'http',
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    47
        'version': 1,
37046
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36801
diff changeset
    48
    },
37644
77c9ee77687c wireproto: rename HTTPV2 so it less like HTTP/2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37613
diff changeset
    49
    HTTP_WIREPROTO_V2: {
37046
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36801
diff changeset
    50
        'transport': 'http',
1cfef5693203 wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36801
diff changeset
    51
        'version': 2,
36609
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    52
    }
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    53
}
abc3b9801563 wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36536
diff changeset
    54
36074
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36073
diff changeset
    55
class bytesresponse(object):
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36073
diff changeset
    56
    """A wire protocol response consisting of raw bytes."""
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36073
diff changeset
    57
    def __init__(self, data):
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36073
diff changeset
    58
        self.data = data
2f7290555c96 wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36073
diff changeset
    59
36073
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
class ooberror(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
    """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
    62
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
    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
    64
    `self.message`.
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
    def __init__(self, message):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
        self.message = message
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
class pushres(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    70
    """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
    71
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    72
    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
    73
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
    def __init__(self, res, output):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
        self.res = res
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    76
        self.output = output
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    78
class pusherr(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
    """wireproto reply: failure
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    80
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    81
    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
    82
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    83
    def __init__(self, res, output):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    84
        self.res = res
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    85
        self.output = output
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 streamres(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    88
    """wireproto reply: 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
    ``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
    95
    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
    96
    engine.
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    97
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    98
    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
    99
        self.gen = gen
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   100
        self.prefer_uncompressed = prefer_uncompressed
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   101
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   102
class streamreslegacy(object):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   103
    """wireproto reply: uncompressed binary stream
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   104
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   105
    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
   106
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   107
    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
   108
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   109
    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
   110
    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
   111
    """
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   112
    def __init__(self, gen=None):
cd6ab329c5c7 wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   113
        self.gen = gen
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   114
37612
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   115
# list of nodes encoding / decoding
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   116
def decodelist(l, sep=' '):
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   117
    if l:
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   118
        return [bin(v) for v in  l.split(sep)]
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   119
    return []
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   120
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   121
def encodelist(l, sep=' '):
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   122
    try:
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   123
        return sep.join(map(hex, l))
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   124
    except TypeError:
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   125
        raise
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   126
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   127
# batched call argument encoding
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   128
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   129
def escapebatcharg(plain):
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   130
    return (plain
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   131
            .replace(':', ':c')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   132
            .replace(',', ':o')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   133
            .replace(';', ':s')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   134
            .replace('=', ':e'))
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   135
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   136
def unescapebatcharg(escaped):
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   137
    return (escaped
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   138
            .replace(':e', '=')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   139
            .replace(':s', ';')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   140
            .replace(':o', ',')
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   141
            .replace(':c', ':'))
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37485
diff changeset
   142
37613
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   143
# mapping of options accepted by getbundle and their types
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   144
#
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   145
# Meant to be extended by extensions. It is extensions responsibility to ensure
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   146
# such options are properly processed in exchange.getbundle.
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   147
#
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   148
# supported types are:
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   149
#
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   150
# :nodes: list of binary nodes
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   151
# :csv:   list of comma-separated values
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   152
# :scsv:  list of comma-separated values return as set
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   153
# :plain: string with no transformation needed.
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   154
GETBUNDLE_ARGUMENTS = {
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   155
    'heads':  'nodes',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   156
    'bookmarks': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   157
    'common': 'nodes',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   158
    'obsmarkers': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   159
    'phases': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   160
    'bundlecaps': 'scsv',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   161
    'listkeys': 'csv',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   162
    'cg': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   163
    'cbattempted': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   164
    'stream': 'boolean',
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   165
}
96d735601ca1 wireproto: move gboptsmap to wireprototypes and rename (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   166
37810
856f381ad74b interfaceutil: module to stub out zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37783
diff changeset
   167
class baseprotocolhandler(interfaceutil.Interface):
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   168
    """Abstract base class for wire protocol handlers.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   169
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   170
    A wire protocol handler serves as an interface between protocol command
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   171
    handlers and the wire protocol transport layer. Protocol handlers provide
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   172
    methods to read command arguments, redirect stdio for the duration of
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   173
    the request, handle response types, etc.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   174
    """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   175
37810
856f381ad74b interfaceutil: module to stub out zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37783
diff changeset
   176
    name = interfaceutil.Attribute(
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   177
        """The name of the protocol implementation.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   178
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   179
        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
   180
        """)
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   181
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   182
    def getargs(args):
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   183
        """return the value for arguments in <args>
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   184
37485
0b7475ea38cf wireproto: port heads command to wire protocol v2
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37414
diff changeset
   185
        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
   186
        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
   187
        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
   188
        """
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   189
37393
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   190
    def getprotocaps():
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   191
        """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
   192
afcfdf53e4b5 wireproto: provide accessors for client capabilities
Joerg Sonnenberger <joerg@bec.de>
parents: 37296
diff changeset
   193
        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
   194
        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
   195
37414
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   196
    def getpayload():
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   197
        """Provide a generator for the raw payload.
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   198
37414
2d965bfeb8f6 wireproto: allow direct stream processing for unbundle
Joerg Sonnenberger <joerg@bec.de>
parents: 37393
diff changeset
   199
        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
   200
        processed.
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   201
        """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   202
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   203
    def mayberedirectstdio():
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   204
        """Context manager to possibly redirect stdio.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   205
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   206
        The context manager yields a file-object like object that receives
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   207
        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: 36074
diff changeset
   208
        yields ``None`` if no I/O redirection occurs.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   209
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   210
        The intent of this context manager is to capture stdio output
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   211
        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: 36074
diff changeset
   212
        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: 36074
diff changeset
   213
        won't be captured.
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   214
        """
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   215
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   216
    def client():
36371
0c231df1ffdc wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36074
diff changeset
   217
        """Returns a string representation of this client (as bytes)."""
36613
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   218
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   219
    def addcapabilities(repo, caps):
36613
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   220
        """Adds advertised capabilities specific to this protocol.
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   221
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   222
        Receives the list of capabilities collected so far.
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   223
6e585bca962e wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36609
diff changeset
   224
        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: 36609
diff changeset
   225
        """
36801
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36613
diff changeset
   226
37296
78103e4138b1 wireproto: port protocol handler to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37294
diff changeset
   227
    def checkperm(perm):
36801
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36613
diff changeset
   228
        """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: 36613
diff changeset
   229
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36613
diff changeset
   230
        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: 36613
diff changeset
   231
        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: 36613
diff changeset
   232
        in a protocol specific manner.
66de4555cefd wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36613
diff changeset
   233
        """
37781
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   234
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   235
class commandentry(object):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   236
    """Represents a declared wire protocol command."""
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   237
    def __init__(self, func, args='', transports=None,
40172
30f70d11c224 wireprotov2: advertise recommended batch size for requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40074
diff changeset
   238
                 permission='push', cachekeyfn=None, extracapabilitiesfn=None):
37781
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   239
        self.func = func
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   240
        self.args = args
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   241
        self.transports = transports or set()
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   242
        self.permission = permission
40021
c537144fdbef wireprotov2: support response caching
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40020
diff changeset
   243
        self.cachekeyfn = cachekeyfn
40172
30f70d11c224 wireprotov2: advertise recommended batch size for requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40074
diff changeset
   244
        self.extracapabilitiesfn = extracapabilitiesfn
37781
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   245
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   246
    def _merge(self, func, args):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   247
        """Merge this instance with an incoming 2-tuple.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   248
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   249
        This is called when a caller using the old 2-tuple API attempts
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   250
        to replace an instance. The incoming values are merged with
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   251
        data not captured by the 2-tuple and a new instance containing
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   252
        the union of the two objects is returned.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   253
        """
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   254
        return commandentry(func, args=args, transports=set(self.transports),
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   255
                            permission=self.permission)
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   256
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   257
    # Old code treats instances as 2-tuples. So expose that interface.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   258
    def __iter__(self):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   259
        yield self.func
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   260
        yield self.args
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   261
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   262
    def __getitem__(self, i):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   263
        if i == 0:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   264
            return self.func
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   265
        elif i == 1:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   266
            return self.args
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   267
        else:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   268
            raise IndexError('can only access elements 0 and 1')
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   269
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   270
class commanddict(dict):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   271
    """Container for registered wire protocol commands.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   272
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   273
    It behaves like a dict. But __setitem__ is overwritten to allow silent
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   274
    coercion of values from 2-tuples for API compatibility.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   275
    """
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   276
    def __setitem__(self, k, v):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   277
        if isinstance(v, commandentry):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   278
            pass
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   279
        # Cast 2-tuples to commandentry instances.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   280
        elif isinstance(v, tuple):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   281
            if len(v) != 2:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   282
                raise ValueError('command tuples must have exactly 2 elements')
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   283
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   284
            # It is common for extensions to wrap wire protocol commands via
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   285
            # e.g. ``wireproto.commands[x] = (newfn, args)``. Because callers
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   286
            # doing this aren't aware of the new API that uses objects to store
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   287
            # command entries, we automatically merge old state with new.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   288
            if k in self:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   289
                v = self[k]._merge(v[0], v[1])
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   290
            else:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   291
                # Use default values from @wireprotocommand.
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   292
                v = commandentry(v[0], args=v[1],
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   293
                                 transports=set(TRANSPORTS),
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   294
                                 permission='push')
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   295
        else:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   296
            raise ValueError('command entries must be commandentry instances '
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   297
                             'or 2-tuples')
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   298
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   299
        return super(commanddict, self).__setitem__(k, v)
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   300
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   301
    def commandavailable(self, command, proto):
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   302
        """Determine if a command is available for the requested protocol."""
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   303
        assert proto.name in TRANSPORTS
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   304
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   305
        entry = self.get(command)
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   306
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   307
        if not entry:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   308
            return False
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   309
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   310
        if proto.name not in entry.transports:
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   311
            return False
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   312
352932a11905 wireproto: move command registration types to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37728
diff changeset
   313
        return True
37783
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   314
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   315
def supportedcompengines(ui, role):
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   316
    """Obtain the list of supported compression engines for a request."""
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   317
    assert role in (util.CLIENTROLE, util.SERVERROLE)
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   318
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   319
    compengines = util.compengines.supportedwireengines(role)
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   320
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   321
    # Allow config to override default list and ordering.
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   322
    if role == util.SERVERROLE:
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   323
        configengines = ui.configlist('server', 'compressionengines')
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   324
        config = 'server.compressionengines'
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   325
    else:
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   326
        # This is currently implemented mainly to facilitate testing. In most
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   327
        # cases, the server should be in charge of choosing a compression engine
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   328
        # because a server has the most to lose from a sub-optimal choice. (e.g.
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   329
        # CPU DoS due to an expensive engine or a network DoS due to poor
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   330
        # compression ratio).
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   331
        configengines = ui.configlist('experimental',
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   332
                                      'clientcompressionengines')
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   333
        config = 'experimental.clientcompressionengines'
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   334
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   335
    # No explicit config. Filter out the ones that aren't supposed to be
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   336
    # advertised and return default ordering.
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   337
    if not configengines:
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   338
        attr = 'serverpriority' if role == util.SERVERROLE else 'clientpriority'
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   339
        return [e for e in compengines
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   340
                if getattr(e.wireprotosupport(), attr) > 0]
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   341
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   342
    # If compression engines are listed in the config, assume there is a good
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   343
    # reason for it (like server operators wanting to achieve specific
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   344
    # performance characteristics). So fail fast if the config references
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   345
    # unusable compression engines.
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   346
    validnames = set(e.name() for e in compengines)
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   347
    invalidnames = set(e for e in configengines if e not in validnames)
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   348
    if invalidnames:
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   349
        raise error.Abort(_('invalid compression engine defined in %s: %s') %
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   350
                          (config, ', '.join(sorted(invalidnames))))
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   351
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   352
    compengines = [e for e in compengines if e.name() in configengines]
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   353
    compengines = sorted(compengines,
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   354
                         key=lambda e: configengines.index(e.name()))
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   355
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   356
    if not compengines:
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   357
        raise error.Abort(_('%s config option does not specify any known '
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   358
                            'compression engines') % config,
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   359
                          hint=_('usable compression engines: %s') %
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   360
                          ', '.sorted(validnames))
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   361
9d818539abfa wireproto: move supportedcompengines out of wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37781
diff changeset
   362
    return compengines
40020
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   363
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   364
@attr.s
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   365
class encodedresponse(object):
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   366
    """Represents response data that is already content encoded.
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   367
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   368
    Wire protocol version 2 only.
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   369
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   370
    Commands typically emit Python objects that are encoded and sent over the
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   371
    wire. If commands emit an object of this type, the encoding step is bypassed
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   372
    and the content from this object is used instead.
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   373
    """
ed919b90acda wireprotov2: define type to represent pre-encoded object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39814
diff changeset
   374
    data = attr.ib()
40025
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   375
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   376
@attr.s
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   377
class alternatelocationresponse(object):
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   378
    """Represents a response available at an alternate location.
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   379
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   380
    Instances are sent in place of actual response objects when the server
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   381
    is sending a "content redirect" response.
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   382
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   383
    Only compatible with wire protocol version 2.
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   384
    """
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   385
    url = attr.ib()
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   386
    mediatype = attr.ib()
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   387
    size = attr.ib(default=None)
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   388
    fullhashes = attr.ib(default=None)
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   389
    fullhashseed = attr.ib(default=None)
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   390
    serverdercerts = attr.ib(default=None)
b099e6032f38 wireprotov2: server support for sending content redirects
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40021
diff changeset
   391
    servercadercerts = attr.ib(default=None)
40328
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   392
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   393
@attr.s
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   394
class indefinitebytestringresponse(object):
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   395
    """Represents an object to be encoded to an indefinite length bytestring.
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   396
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   397
    Instances are initialized from an iterable of chunks, with each chunk being
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   398
    a bytes instance.
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   399
    """
2c55716f8a1c wireprotov2: add response type that serializes to indefinite length bytestring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40176
diff changeset
   400
    chunks = attr.ib()