<commit_before># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Jupyter server extension which supports HTTP-over-websocket communication."""

import base64
import json

from distutils import version

from notebook.base import handlers
from six.moves import urllib_parse as urlparse
from tornado import gen
from tornado import httpclient
from tornado import httputil
from tornado import stack_context
from tornado import websocket

HANDLER_VERSION = version.StrictVersion('0.0.1a1')


class HttpOverWebSocketHandler(websocket.WebSocketHandler,
                               handlers.IPythonHandler):
  """Socket handler that forwards requests via HTTP to the notebook server."""

  _REQUIRED_KEYS = {'path', 'method', 'message_id'}

  _REQUIRE_XSRF_FORWARDING_METHODS = {'POST', 'PATCH'}

  _REQUIRE_NO_BODY_METHODS = {'GET', 'HEAD'}

  def __init__(self, *args, **kwargs):
    websocket.WebSocketHandler.__init__(self, *args, **kwargs)
    handlers.IPythonHandler.__init__(self, *args, **kwargs)

    ca_certs = None
    if self.request.protocol == 'https':
      ca_certs = self.config.get('NotebookApp', {}).get('certfile')
      if not ca_certs:
        raise ValueError('HTTPS requires the NotebookApp.certfile setting to '
                         'be present.')
    self.ca_certs = ca_certs

  def check_origin(self, origin):
    # The IPythonHandler implementation of check_origin uses the
    # NotebookApp.allow_origin setting.
    return handlers.IPythonHandler.check_origin(self, origin)

  def _write_error(self, msg, status=500):<commit_msg>Project import generated by Copybara.<commit_after># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Jupyter server extension which supports HTTP-over-websocket communication."""

import base64
import json

from distutils import version

from notebook.base import handlers
from six.moves import urllib_parse as urlparse
from tornado import gen
from tornado import httpclient
from tornado import httputil
from tornado import stack_context
from tornado import websocket

HANDLER_VERSION = version.StrictVersion('0.0.1a1')


class HttpOverWebSocketHandler(websocket.WebSocketHandler,
                               handlers.IPythonHandler):
  """Socket handler that forwards requests via HTTP to the notebook servers."""

  _REQUIRED_KEYS = {'path', 'method', 'message_id'}

  _REQUIRE_XSRF_FORWARDING_METHODS = {'POST', 'PATCH'}

  _REQUIRE_NO_BODY_METHODS = {'GET', 'HEAD'}

  def __init__(self, *args, **kwargs):
    websocket.WebSocketHandler.__init__(self, *args, **kwargs)
    handlers.IPythonHandler.__init__(self, *args, **kwargs)

    ca_certs = None
    if self.request.protocol == 'https':
      ca_certs = self.config.get('NotebookApp', {}).get('certfile')
      if not ca_certs:
        raise ValueError('HTTPS requires the NotebookApp.certfile setting to '
                         'be present.')
    self.ca_certs = ca_certs

  def check_origin(self, origin):
    # The IPythonHandler implementation of check_origin uses the
    # NotebookApp.allow_origin setting.
    return handlers.IPythonHandler.check_origin(self, origin)

  def _write_error(self, msg, status=500):
{'fraction_non_alphanumeric': 0.08557806912991657, 'fraction_numerical': 0.008104886769964244, 'mean_word_length': 4.12958435207824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4717094', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1165, 'n_words': 413}