<commit_before># -*- coding: utf-8 -*-
import logging
import os
import copy
import time
import functools
import errno
import imp

import thriftpy
from thriftpy.thrift import TProcessor

from .config import ConfigAttribute, import_string
from .event import before_api_call, after_api_call, tear_down_api_call
from ._server import run_simple
from .test import TestClient, FakeClient
from ._compat import PY2, iteritems, string_types


class ApiMeta(object):
    def __init__(self, app, name, f, args, kwargs):
        """
        meta object represent related info for an api

        :param app:  the archer app instance
        :param name: name of the api
        :param f:    function instance of the api
        :param args:  positional arguments
        :param kwargs:  keyword arguments

        """
        self.app = app
        self.name = name
        self.f = f
        self.args = args
        self.kwargs = kwargs
        self.start_time = time.time()


class ApiResultMeta(object):
    def __init__(self, result=None, error=None):
        """

        :param result: return value of api, if exception occurred, set None
        :param error: the exception instance raised in the api if any

        """
        self.result = result
        self.error = error
        self.end_time = time.time()


class Archer(object):
    debug = ConfigAttribute('DEBUG')
    testing = ConfigAttribute('TESTING')
    logger_name = ConfigAttribute('LOGGER_NAME')
    default_config = {
        'DEBUG': False,
        'TESTING': False,
        'LOGGER_NAME': None
    }

    def __init__(self, service_name, thrift_file=None, root_path=None,
            name=None):
        """
        initialize an archer application

        :param name:  app name
        :param thrift_file:  the thrift file to load by thriftpy, if not set
                             ,archer will automatically find a .thrift file
                             under root path
        :param service: service name of the thrift app
        :param root_path:  root path for file searching, default is pwd

        """
        self.root_path = root_path or os.getcwd()

        self.thrift_file = thrift_file or self._find_thrift_file()

        self.thrift = thriftpy.load(self.thrift_file)

        self.service_name = service_name
        self.service = getattr(self.thrift, service_name)
        self.name = name
        self.app = TProcessor(self.service, self)
<commit_msg>Allow archer to pass module_name to thriftpy<commit_after># -*- coding: utf-8 -*-
import logging
import os
import copy
import time
import functools
import errno
import imp

import thriftpy
from thriftpy.thrift import TProcessor

from .config import ConfigAttribute, import_string
from .event import before_api_call, after_api_call, tear_down_api_call
from ._server import run_simple
from .test import TestClient, FakeClient
from ._compat import PY2, iteritems, string_types


class ApiMeta(object):
    def __init__(self, app, name, f, args, kwargs):
        """
        meta object represent related info for an api

        :param app:  the archer app instance
        :param name: name of the api
        :param f:    function instance of the api
        :param args:  positional arguments
        :param kwargs:  keyword arguments

        """
        self.app = app
        self.name = name
        self.f = f
        self.args = args
        self.kwargs = kwargs
        self.start_time = time.time()


class ApiResultMeta(object):
    def __init__(self, result=None, error=None):
        """

        :param result: return value of api, if exception occurred, set None
        :param error: the exception instance raised in the api if any

        """
        self.result = result
        self.error = error
        self.end_time = time.time()


class Archer(object):
    debug = ConfigAttribute('DEBUG')
    testing = ConfigAttribute('TESTING')
    logger_name = ConfigAttribute('LOGGER_NAME')
    default_config = {
        'DEBUG': False,
        'TESTING': False,
        'LOGGER_NAME': None
    }

    def __init__(self, service_name, thrift_file=None, root_path=None,
            name=None, module_name=None):
        """
        initialize an archer application

        :param name:  app name
        :param thrift_file:  the thrift file to load by thriftpy, if not set
                             ,archer will automatically find a .thrift file
                             under root path
        :param module_name: module name of the thrift module to be loaded,
                            enables us to pickle the module objects
        :param service: service name of the thrift app
        :param root_path:  root path for file searching, default is pwd

        """
        self.root_path = root_path or os.getcwd()

        self.thrift_file = thrift_file or self._find_thrift_file()

        self.thrift = thriftpy.load(self.thrift_file, module_name=module_name)

        self.service_name = service_name
        self.service = getattr(self.thrift, service_name)
        self.name = name
        self.app = TProcessor(self.service, self)

{'fraction_non_alphanumeric': 0.07538672410417074, 'fraction_numerical': 0.0007832386919913843, 'mean_word_length': 2.3671720500988793, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6089331', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1420, 'n_words': 482}