# Path: jarr/lib/utils.py
# def jarr_get(url, timeout=None, user_agent=None, headers=None, **kwargs):
#     from jarr.bootstrap import conf  # circular import otherwise
#     timeout = timeout or conf.crawler.timeout
#     user_agent = user_agent or conf.crawler.user_agent
#     def_headers = {'User-Agent': user_agent}
#     if headers is not None:
#         def_headers.update(headers)
#     request_kwargs = {'verify': False, 'allow_redirects': True,
#                       'timeout': timeout, 'headers': def_headers}
#     request_kwargs.update(kwargs)
#     return requests.get(url, **request_kwargs)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)


import logging
from jarr.lib.utils import jarr_get as common_get
from jarr.bootstrap import conf



logger = logging.getLogger(__name__)


def jarr_get(*args, **kwargs):
    kwargs['timeout'] = conf.crawler.timeout
    kwargs['user_agent'] = conf.crawler.user_agent
    return common_get(*args, **kwargs)


def get_tfidf_pref(feed, pref_name):
    """Tool to figure out clustering setting for a feed.

    For a given feed and a given attribute name will return a boolean
    If this same attribute is set to false on feed's user false will be
    returned, if it's set to false on feed's category false will also be
    returned. If not the value be returned from feed configuration.
    Defaults are set in configurations
    """
    objs = feed.user, feed.category, feed
    for obj in objs:
        if obj is None:
            continue
        if not obj.cluster_conf or pref_name not in obj.cluster_conf:
            continue
        if not obj.cluster_conf[pref_name] and obj is not feed:
            continue
        return obj.cluster_conf.get(pref_name)

# Path: jarr/lib/utils.py
# def jarr_get(url, timeout=None, user_agent=None, headers=None, **kwargs):
#     from jarr.bootstrap import conf  # circular import otherwise
#     timeout = timeout or conf.crawler.timeout
#     user_agent = user_agent or conf.crawler.user_agent
#     def_headers = {'User-Agent': user_agent}
#     if headers is not None:
#         def_headers.update(headers)
#     request_kwargs = {'verify': False, 'allow_redirects': True,
#                       'timeout': timeout, 'headers': def_headers}
#     request_kwargs.update(kwargs)
#     return requests.get(url, **request_kwargs)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)


# Path: jarr/utils.py
import logging
from jarr.lib.utils import jarr_get as common_get
from jarr.bootstrap import conf




logger = logging.getLogger(__name__)


def jarr_get(*args, **kwargs):
    kwargs['timeout'] = conf.crawler.timeout
    kwargs['user_agent'] = conf.crawler.user_agent
    return common_get(*args, **kwargs)


def get_tfidf_pref(feed, pref_name):
    """Tool to figure out clustering setting for a feed.

    For a given feed and a given attribute name will return a boolean
    If this same attribute is set to false on feed's user false will be
    returned, if it's set to false on feed's category false will also be
    returned. If not the value be returned from feed configuration.
    Defaults are set in configurations
    """
    objs = feed.user, feed.category, feed
    for obj in objs:
        if obj is None:
            continue
        if not obj.cluster_conf or pref_name not in obj.cluster_conf:
            continue
        if not obj.cluster_conf[pref_name] and obj is not feed:
            continue
        return obj.cluster_conf.get(pref_name)

    return getattr(conf.clustering.tfidf, pref_name)