<commit_before>'''
Utilities for client-side usage of the streaming log API
(http://wiki.dnanexus.com/API-Specification-v1.0.0/Logging#API-method%3A-%2Fjob-xxxx%2FstreamLog).
'''

import json, re

#from ws4py.client.threadedclient import WebSocketClient
from ws4py.client import WebSocketBaseClient
from ws4py.exc import HandshakeError

import dxpy
from dxpy.utils.describe import get_find_jobs_string

class DXJobLogStreamingException(Exception):
    pass

class DXJobLogStreamClient(WebSocketBaseClient):
    def __init__(self, job_id, input_params={}, msg_output_format="{job} {level} {msg}"):
        self.seen_jobs = set()
        self.input_params = input_params
        self.msg_output_format = msg_output_format
        self.closed_code, self.closed_reason = None, None
        url = "{server}/{job_id}/streamLog/websocket".format(server=dxpy.APISERVER, job_id=job_id)
        WebSocketBaseClient.__init__(self, url, protocols=None, extensions=None)

    def handshake_ok(self):
        self.run()

    def opened(self):
        args = {"access_token": dxpy.SECURITY_CONTEXT['auth_token'],
                "token_type": dxpy.SECURITY_CONTEXT['auth_token_type']}
        args.update(self.input_params)
        self.send(json.dumps(args))

    def closed(self, code, reason):
        self.closed_code, self.closed_reason = code, reason

        if self.closed_code != 1000:
            try:
                error = json.loads(self.closed_reason)<commit_msg>Fix configuration of wss protocol<commit_after>'''
Utilities for client-side usage of the streaming log API
(http://wiki.dnanexus.com/API-Specification-v1.0.0/Logging#API-method%3A-%2Fjob-xxxx%2FstreamLog).
'''

import json, re

#from ws4py.client.threadedclient import WebSocketClient
from ws4py.client import WebSocketBaseClient
from ws4py.exc import HandshakeError

import dxpy
from dxpy.utils.describe import get_find_jobs_string

class DXJobLogStreamingException(Exception):
    pass

class DXJobLogStreamClient(WebSocketBaseClient):
    def __init__(self, job_id, input_params={}, msg_output_format="{job} {level} {msg}"):
        self.seen_jobs = set()
        self.input_params = input_params
        self.msg_output_format = msg_output_format
        self.closed_code, self.closed_reason = None, None
        ws_proto = 'wss' if dxpy.APISERVER_PROTOCOL == 'https' else 'ws'
        url = "{protocol}://{host}:{port}/{job_id}/streamLog/websocket".format(protocol=ws_proto,
                                                                        host=dxpy.APISERVER_HOST,
                                                                        port=dxpy.APISERVER_PORT,
                                                                        job_id=job_id)
        WebSocketBaseClient.__init__(self, url, protocols=None, extensions=None)

    def handshake_ok(self):
        self.run()

    def opened(self):
        args = {"access_token": dxpy.SECURITY_CONTEXT['auth_token'],
                "token_type": dxpy.SECURITY_CONTEXT['auth_token_type']}
        args.update(self.input_params)
        self.send(json.dumps(args))

    def closed(self, code, reason):
        self.closed_code, self.closed_reason = code, reason

        if self.closed_code != 1000:
            try:
                error = json.loads(self.closed_reason)
{'fraction_non_alphanumeric': 0.10390790669494093, 'fraction_numerical': 0.007876401090578612, 'mean_word_length': 2.8306264501160094, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6257462', 'n_tokens_mistral': 1028, 'n_tokens_neox': 990, 'n_words': 186}