<commit_before>"""
Base classes and utility functions for Data API service classes.
"""
__author__ = '<NAME> <<EMAIL>>'
__date__ = '12/24/15'

# Imports
# -------

# Stdlib
import time
import traceback

# Third party
import twisted.internet
import twisted.web
from thrift.transport import THttpClient
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTwisted

# Local
from doekbase.data_api import exceptions

# Global constants and variables
# ------------------------------

DEFAULT_WS_URL = 'https://ci.kbase.us/services/ws/'
DEFAULT_SHOCK_URL = 'https://ci.kbase.us/services/shock-api/'

SERVICES_DICT = {'workspace_service_url': DEFAULT_WS_URL,
                 'shock_service_url': DEFAULT_SHOCK_URL}

# Functions and classes
# ---------------------

def server_method(func):
    """Decorator for service methods.

    The wrapper depends on the existence of two attributes in the
    class being wrapped:
        - ttypes (module): Thrift type module, containing exception classes
        - log (logging.Logger): Logger instance

    Args:
        func (function): Function being wrapped
    """
    def wrapper(self, token, ref, *args, **kwargs):
        error, result = None, None
        self.log.debug('method={meth} state=begin token={tok} ref={ref} args={'
                       'args} kwargs={kw}'
                   .format(meth=func.__name__, tok=token, ref=ref,
                           args=args, kw=kwargs))
        t0 = time.time()
        try:
            result = func(self, token, ref, *args, **kwargs)
        except AttributeError, e:
            error = e
            raise self.self.ttypes.AttributeException(e.message,
                                                      traceback.print_exc())
        except exceptions.AuthenticationError, e:
            error = e
            raise self.self.ttypes.AuthenticationException(e.message,
                                                           traceback.print_exc())
        except exceptions.AuthorizationError, e:
            error = e
            raise self.ttypes.AuthorizationException(e.message,
                                                     traceback.print_exc())
        except exceptions.TypeError, e:
            error = e
            raise self.ttypes.TypeException(e.message, traceback.print_exc())<commit_msg>fix typo 'self.self.'<commit_after>"""
Base classes and utility functions for Data API service classes.
"""
__author__ = '<NAME> <<EMAIL>>'
__date__ = '12/24/15'

# Imports
# -------

# Stdlib
import time
import traceback

# Third party
import twisted.internet
import twisted.web
from thrift.transport import THttpClient
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTwisted

# Local
from doekbase.data_api import exceptions

# Global constants and variables
# ------------------------------

DEFAULT_WS_URL = 'https://ci.kbase.us/services/ws/'
DEFAULT_SHOCK_URL = 'https://ci.kbase.us/services/shock-api/'

SERVICES_DICT = {'workspace_service_url': DEFAULT_WS_URL,
                 'shock_service_url': DEFAULT_SHOCK_URL}

# Functions and classes
# ---------------------

def server_method(func):
    """Decorator for service methods.

    The wrapper depends on the existence of two attributes in the
    class being wrapped:
        - ttypes (module): Thrift type module, containing exception classes
        - log (logging.Logger): Logger instance

    Args:
        func (function): Function being wrapped
    """
    def wrapper(self, token, ref, *args, **kwargs):
        error, result = None, None
        self.log.debug('method={meth} state=begin token={tok} ref={ref} args={'
                       'args} kwargs={kw}'
                   .format(meth=func.__name__, tok=token, ref=ref,
                           args=args, kw=kwargs))
        t0 = time.time()
        try:
            result = func(self, token, ref, *args, **kwargs)
        except AttributeError, e:
            error = e
            raise self.ttypes.AttributeException(e.message,
                                                      traceback.print_exc())
        except exceptions.AuthenticationError, e:
            error = e
            raise self.ttypes.AuthenticationException(e.message,
                                                           traceback.print_exc())
        except exceptions.AuthorizationError, e:
            error = e
            raise self.ttypes.AuthorizationException(e.message,
                                                     traceback.print_exc())
        except exceptions.TypeError, e:
            error = e
            raise self.ttypes.TypeException(e.message, traceback.print_exc())
{'fraction_non_alphanumeric': 0.11574074074074074, 'fraction_numerical': 0.002946127946127946, 'mean_word_length': 2.006325110689437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632904', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1207, 'n_words': 333}