This file is indexed.

/usr/lib/python2.7/dist-packages/autobahn/websocket/types.py is in python-autobahn 17.10.1+dfsg1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) Crossbar.io Technologies GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
###############################################################################

from __future__ import absolute_import

from autobahn.util import public

import json
import six

__all__ = (
    'ConnectionRequest',
    'ConnectionResponse',
    'ConnectionAccept',
    'ConnectionDeny',
    'Message',
    'IncomingMessage',
    'OutgoingMessage',
)


@public
class ConnectionRequest(object):
    """
    Thin-wrapper for WebSocket connection request information provided in
    :meth:`autobahn.websocket.protocol.WebSocketServerProtocol.onConnect` when
    a WebSocket client want to establish a connection to a WebSocket server.
    """

    __slots__ = (
        'peer',
        'headers',
        'host',
        'path',
        'params',
        'version',
        'origin',
        'protocols',
        'extensions'
    )

    def __init__(self, peer, headers, host, path, params, version, origin, protocols, extensions):
        """

        :param peer: Descriptor of the connecting client (e.g. IP address/port
            in case of TCP transports).
        :type peer: str

        :param headers: HTTP headers from opening handshake request.
        :type headers: dict

        :param host: Host from opening handshake HTTP header.
        :type host: str

        :param path: Path from requested HTTP resource URI. For example, a resource URI of
            ``/myservice?foo=23&foo=66&bar=2`` will be parsed to ``/myservice``.
        :type path: str

        :param params: Query parameters (if any) from requested HTTP resource URI.
            For example, a resource URI of ``/myservice?foo=23&foo=66&bar=2`` will be
            parsed to ``{'foo': ['23', '66'], 'bar': ['2']}``.
        :type params: dict

        :param version: The WebSocket protocol version the client announced (and will be
            spoken, when connection is accepted).
        :type version: int

        :param origin: The WebSocket origin header or None. Note that this only
            a reliable source of information for browser clients!
        :type origin: str

        :param protocols: The WebSocket (sub)protocols the client announced. You must
            select and return one of those (or ``None``) in
            :meth:`autobahn.websocket.WebSocketServerProtocol.onConnect`.
        :type protocols: list

        :param extensions: The WebSocket extensions the client requested and the
            server accepted, and thus will be spoken, once the WebSocket connection
            has been fully established.
        :type extensions: list
        """
        self.peer = peer
        self.headers = headers
        self.host = host
        self.path = path
        self.params = params
        self.version = version
        self.origin = origin
        self.protocols = protocols
        self.extensions = extensions

    def __json__(self):
        return {'peer': self.peer,
                'headers': self.headers,
                'host': self.host,
                'path': self.path,
                'params': self.params,
                'version': self.version,
                'origin': self.origin,
                'protocols': self.protocols,
                'extensions': self.extensions}

    def __str__(self):
        return json.dumps(self.__json__())


@public
class ConnectionResponse(object):
    """
    Thin-wrapper for WebSocket connection response information provided in
    :meth:`autobahn.websocket.protocol.WebSocketClientProtocol.onConnect` when
    a WebSocket server has accepted a connection request by a client.
    """

    __slots__ = (
        'peer',
        'headers',
        'version',
        'protocol',
        'extensions'
    )

    def __init__(self, peer, headers, version, protocol, extensions):
        """
        Constructor.

        :param peer: Descriptor of the connected server (e.g. IP address/port in case of TCP transport).
        :type peer: str

        :param headers: HTTP headers from opening handshake response.
        :type headers: dict

        :param version: The WebSocket protocol version that is spoken.
        :type version: int

        :param protocol: The WebSocket (sub)protocol in use.
        :type protocol: str

        :param extensions: The WebSocket extensions in use.
        :type extensions: list of str
        """
        self.peer = peer
        self.headers = headers
        self.version = version
        self.protocol = protocol
        self.extensions = extensions

    def __json__(self):
        return {'peer': self.peer,
                'headers': self.headers,
                'version': self.version,
                'protocol': self.protocol,
                'extensions': self.extensions}

    def __str__(self):
        return json.dumps(self.__json__())


@public
class ConnectionAccept(object):
    """
    Used by WebSocket servers to accept an incoming WebSocket connection.
    If the client announced one or multiple subprotocols, the server MUST
    select one of the subprotocols announced by the client.
    """

    __slots__ = ('subprotocol', 'headers')

    def __init__(self, subprotocol=None, headers=None):
        """

        :param subprotocol: The WebSocket connection is accepted with the
            this WebSocket subprotocol chosen. The value must be a token
            as defined by RFC 2616.
        :type subprotocol: unicode or None

        :param headers: Additional HTTP headers to send on the WebSocket
            opening handshake reply, e.g. cookies. The keys must be unicode,
            and the values either unicode or tuple/list. In the latter case
            a separate HTTP header line will be sent for each item in
            tuple/list.
        :type headers: dict or None
        """
        assert(subprotocol is None or type(subprotocol) == six.text_type)
        assert(headers is None or type(headers) == dict)
        if headers is not None:
            for k, v in headers.items():
                assert(type(k) == six.text_type)
                assert(type(v) == six.text_type or type(v) == list or type(v) == tuple)
                if type(v) == list or type(v) == tuple:
                    for vv in v:
                        assert(type(vv) == six.text_type)

        self.subprotocol = subprotocol
        self.headers = headers


@public
class ConnectionDeny(Exception):
    """
    Throw an instance of this class to deny a WebSocket connection
    during handshake in :meth:`autobahn.websocket.protocol.WebSocketServerProtocol.onConnect`.
    """

    __slots__ = ('code', 'reason')

    BAD_REQUEST = 400
    """
    Bad Request. The request cannot be fulfilled due to bad syntax.
    """

    FORBIDDEN = 403
    """
    Forbidden. The request was a legal request, but the server is refusing to respond to it.[2] Unlike a 401 Unauthorized response, authenticating will make no difference.
    """

    NOT_FOUND = 404
    """
    Not Found. The requested resource could not be found but may be available again in the future.[2] Subsequent requests by the client are permissible.
    """

    NOT_ACCEPTABLE = 406
    """
    Not Acceptable. The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
    """

    REQUEST_TIMEOUT = 408
    """
    Request Timeout. The server timed out waiting for the request. According to W3 HTTP specifications: 'The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.
    """

    INTERNAL_SERVER_ERROR = 500
    """
    Internal Server Error. A generic error message, given when no more specific message is suitable.
    """

    NOT_IMPLEMENTED = 501
    """
    Not Implemented. The server either does not recognize the request method, or it lacks the ability to fulfill the request.
    """

    SERVICE_UNAVAILABLE = 503
    """
    Service Unavailable. The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.
    """

    def __init__(self, code, reason=None):
        """

        :param code: HTTP error code.
        :type code: int

        :param reason: HTTP error reason.
        :type reason: unicode
        """
        assert(type(code) == int)
        assert(reason is None or type(reason) == six.text_type)

        self.code = code
        self.reason = reason


class Message(object):
    """
    Abstract base class for WebSocket messages.
    """

    __slots__ = ()


class IncomingMessage(Message):
    """
    An incoming WebSocket message.
    """

    __slots__ = ('payload', 'is_binary')

    def __init__(self, payload, is_binary=False):
        """

        :param payload: The WebSocket message payload, which can be UTF-8
            encoded text or a binary string.
        :type payload: bytes

        :param is_binary: ``True`` for binary payload, else the payload
            contains UTF-8 encoded text.
        :type is_binary: bool
        """
        assert(type(payload) == bytes)
        assert(type(is_binary) == bool)

        self.payload = payload
        self.is_binary = is_binary


class OutgoingMessage(Message):
    """
    An outgoing WebSocket message.
    """

    __slots__ = ('payload', 'is_binary', 'skip_compress')

    def __init__(self, payload, is_binary=False, skip_compress=False):
        """

        :param payload: The WebSocket message payload, which can be UTF-8
            encoded text or a binary string.
        :type payload: bytes

        :param is_binary: ``True`` iff payload is binary, else the payload
            contains UTF-8 encoded text.
        :type is_binary: bool

        :param skip_compress: If ``True``, never compress this message.
            This only has an effect when WebSocket compression has been negotiated
            on the WebSocket connection. Use when you know the payload is
            incompressible (e.g. encrypted or already compressed).
        :type skip_compress: bool
        """
        assert(type(payload) == bytes)
        assert(type(is_binary) == bool)
        assert(type(skip_compress) == bool)

        self.payload = payload
        self.is_binary = is_binary
        self.skip_compress = skip_compress


class Ping(object):
    """
    A WebSocket ping message.
    """

    __slots__ = ('payload')

    def __init__(self, payload=None):
        """

        :param payload: The WebSocket ping message payload.
        :type payload: bytes or None
        """
        assert(payload is None or type(payload) == bytes), \
            ("invalid type {} for WebSocket ping payload - must be None or bytes".format(type(payload)))
        if payload is not None:
            assert(len(payload) < 126), \
                ("WebSocket ping payload too long ({} bytes) - must be <= 125 bytes".format(len(payload)))

        self.payload = payload