コード例 #1
0
 def setUp(self, *args, **kwargs):
     super(LogSetupMiddlewareTest, self).setUp(*args, **kwargs)
     self.factory = RequestFactory()
     # LogSetupMiddleware only looks under this module
     logging_root = __name__
     self.middleware = LogSetupMiddleware(root=logging_root)
     self.filter = RequestFilter(request=None)
     # Create test logger with a placeholder logger
     self.logger = logging.getLogger(__name__)
     self.logger.filters = []
     self.logger.addFilter(self.filter)
     # Stub out original handlers
     self._original_handlers = logging._handlers
     self._original_handlerList = logging._handlerList
     logging._handlers = {}
     logging._handlerList = []
     # Create test handler
     self.handler = NullHandler()
     self.handler.filters = []
     self.handler.addFilter(self.filter)
     self.logger.addHandler(self.handler)
コード例 #2
0
from settings import SEARCH_ADMIN, SEARCH_INDEX_NAME, STATICFILES_DIRS
from sefaria.utils.hebrew import hebrew_term
import sefaria.model.queue as qu



pagerank_dict = {r: v for r, v in json.load(open(STATICFILES_DIRS[0] + "pagerank.json","rb"))}
sheetrank_dict = json.load(open(STATICFILES_DIRS[0] + "sheetrank.json", "rb"))
all_gemara_indexes = library.get_indexes_in_category("Bavli")
davidson_indexes = all_gemara_indexes[:all_gemara_indexes.index("Bava Batra") + 1]

es = ElasticSearch(SEARCH_ADMIN)
tracer = logging.getLogger('elasticsearch.trace')
tracer.setLevel(logging.INFO)
#tracer.addHandler(logging.FileHandler('/tmp/es_trace.log'))
tracer.addHandler(NullHandler())

doc_count = 0


def index_text(index_name, oref, version=None, lang=None, bavli_amud=True, merged=False):
    """
    Index the text designated by ref.
    If no version and lang are given, this function will be called for each available version.
    If `merged` is true, and lang is given, it will index a merged version of this document
   :param str index_name: The index name, as provided by `get_new_and_current_index_names`
    :param str oref: Currently assumes ref is at section level. :param str version: Version being indexed
    :param str lang: Language of version being indexed
    :param bool bavli_amud:  Is this Bavli? Bavli text is indexed by section, not segment.
    :param bool merged: is this a merged index?
    :return:
コード例 #3
0
import logging
from django.utils.log import NullHandler

logging.basicConfig()

logger = logging.getLogger(__name__)
if not logger.handlers:
    logger.addHandler(NullHandler())
コード例 #4
0
class LogSetupMiddlewareTest(TestCase):
    maxDiff = None

    def setUp(self, *args, **kwargs):
        super(LogSetupMiddlewareTest, self).setUp(*args, **kwargs)
        self.factory = RequestFactory()
        # LogSetupMiddleware only looks under this module
        logging_root = __name__
        self.middleware = LogSetupMiddleware(root=logging_root)
        self.filter = RequestFilter(request=None)
        # Create test logger with a placeholder logger
        self.logger = logging.getLogger(__name__)
        self.logger.filters = []
        self.logger.addFilter(self.filter)
        # Stub out original handlers
        self._original_handlers = logging._handlers
        self._original_handlerList = logging._handlerList
        logging._handlers = {}
        logging._handlerList = []
        # Create test handler
        self.handler = NullHandler()
        self.handler.filters = []
        self.handler.addFilter(self.filter)
        self.logger.addHandler(self.handler)

    def tearDown(self, *args, **kwargs):
        logging._handlers = self._original_handlers
        logging._handlerList = self._original_handlerList

    def bound_logger(self, request):
        loggers = self.middleware.find_loggers_with_filter(RequestFilter)
        bound_logger, bound_handler = False, False
        for logger, filters in loggers.items():
            if any(f.request == request for f in filters):
                return True
        return False

    def bound_handler(self, request):
        handlers = self.middleware.find_handlers_with_filter(RequestFilter)
        for handler, filters in handlers.items():
            if any(f.request == request for f in filters):
                return True
        return False

    def assertBound(self, request):
        self.assertTrue(self.bound_logger(request))
        self.assertTrue(self.bound_handler(request))

    def assertNotBound(self, request):
        self.assertFalse(self.bound_logger(request))
        self.assertFalse(self.bound_handler(request))

    def test_request(self):
        request = self.factory.get('/')
        self.assertNotBound(request)
        response = self.middleware.process_request(request)
        self.assertBound(request)
        self.middleware.process_response(request, response)

    def test_response(self):
        request = self.factory.get('/')
        self.assertNotBound(request)
        response = self.middleware.process_request(request)
        self.assertBound(request)
        self.middleware.process_response(request, response)
        self.assertNotBound(request)

    def test_exception(self):
        request = self.factory.get('/')
        self.assertNotBound(request)
        self.middleware.process_request(request)
        self.assertBound(request)
        self.middleware.process_exception(request, Exception())
        self.assertNotBound(request)

    def test_process_response_alone(self):
        request = self.factory.get('/')
        self.assertNotBound(request)
        self.middleware.process_response(request, HttpResponse(''))
        self.assertNotBound(request)

    def test_process_exception_alone(self):
        request = self.factory.get('/')
        self.assertNotBound(request)
        self.middleware.process_exception(request, Exception())
        self.assertNotBound(request)

    def test_find_loggers(self):
        # Find a subset of loggers
        self.assertEqual(self.middleware.find_loggers(),
                         {__name__: self.logger})
        # Look for all loggers
        self.middleware.root = ''
        loggers = self.middleware.find_loggers()
        self.assertEqual(loggers[''], logging.getLogger(''))
        self.assertEqual(loggers[__name__], self.logger)

    def test_find_loggers_with_filter(self):
        loggers = self.middleware.find_loggers_with_filter(RequestFilter)
        self.assertEqual(loggers.keys(), [self.logger])
        self.assertEqual([type(f) for f in loggers[self.logger]],
                         [RequestFilter],
                         loggers[self.logger])

    def test_find_handlers(self):
        # Find our handler
        self.assertTrue(self.handler in self.middleware.find_handlers())

    def test_find_handlers_with_filter(self):
        handlers = self.middleware.find_handlers_with_filter(RequestFilter)
        self.assertTrue(self.handler in handlers)
コード例 #5
0
from django.conf import settings
from django.core.cache import get_cache, InvalidCacheBackendError, DEFAULT_CACHE_ALIAS
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import smart_str
from django.utils.log import NullHandler
from hashlib import md5
from keyedcache.utils import is_string_like, is_list_or_tuple
from warnings import warn
import cPickle as pickle
import logging
import types

log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
log.addHandler(NullHandler())

# The debugging variable CACHED_KEYS is exact only with the the Django
# debugging server (or any single worker process server) and without restarting
# the server between restarts of the main cache (memcached).
# Keys in CACHED_KEYS variable never expire and can eat much memory on long
# running servers. Currently it is not confirmed in Satchmo.
# If more worker processes are used, the reported values of the following three
# variables can skip randomly upwards downwards.
CACHED_KEYS = {}
CACHE_CALLS = 0
CACHE_HITS = 0

KEY_DELIM = "::"
REQUEST_CACHE = {'enabled': False}