def __init__(self, cache: BaseCache = NullCache()) -> None:
     self.cache = cache
     self.max_page = {
         "general": 950,
         "gamer": 350,
         "otaku": 1300,
     }
Exemplo n.º 2
0
def github():
    """Provides the 'github' module with everything mocked"""
    original_cache = github_module.cache
    original_get_issues = github_module.get_issues

    github_module.cache = NullCache()
    github_module.get_issues = lambda self, *args, **kwargs: []

    yield github_module

    github_module.cache = original_cache
    github_module.get_issues = original_get_issues
Exemplo n.º 3
0
    def setUp(self):
        self.original_get_result = howdoi._get_result
        howdoi._get_result = self._get_result_mock

        # ensure no cache is used during testing.
        howdoi.cache = NullCache()

        self.queries = [
            'format date bash', 'print stack trace python',
            'convert mp4 to animated gif', 'create tar archive', 'cat'
        ]
        self.help_queries = howdoi.SUPPORTED_HELP_QUERIES
        self.pt_queries = [
            'abrir arquivo em python', 'enviar email em django',
            'hello world em c'
        ]
        self.bad_queries = ['moe', 'mel']
Exemplo n.º 4
0
    def setUp(self):
        self.patcher_get_result = patch.object(howdoi, '_get_result')
        self.mock_get_result = self.patcher_get_result.start()
        self.mock_get_result.side_effect = _get_result_mock
        # ensure no cache is used during testing.
        howdoi.cache = NullCache()

        self.queries = [
            'format date bash', 'print stack trace python',
            'convert mp4 to animated gif', 'create tar archive', 'cat'
        ]
        self.help_queries = howdoi.SUPPORTED_HELP_QUERIES
        self.pt_queries = [
            'abrir arquivo em python', 'enviar email em django',
            'hello world em c'
        ]
        self.bad_queries = ['moe', 'mel']
        self.query_without_code_or_pre_block = 'Difference between element node and Text Node'
Exemplo n.º 5
0
def perform_sanity_check():
    '''Perform sanity check.
    Returns exit code for program. An exit code of -1 means a validation error was encountered.
    '''
    global cache  # pylint: disable=global-statement,invalid-name
    # Disable cache to avoid cached answers while performing the checks
    cache = NullCache()

    exit_code = 0
    for engine in ['google']:  # 'bing' and 'duckduckgo' throw various block errors
        print('Checking {}...'.format(engine))
        try:
            _sanity_check(engine)
        except (GoogleValidationError, BingValidationError, DDGValidationError):
            logging.error('%s%s query failed%s', RED, engine, END_FORMAT)
            exit_code = -1
    if exit_code == 0:
        print(f'{GREEN}Ok{END_FORMAT}')
    return exit_code
Exemplo n.º 6
0
def perform_sanity_check():
    '''Perform sanity check.
    Returns exit code for program. An exit code of -1 means a validation error was encountered.
    '''
    global cache  # pylint: disable=global-statement,invalid-name
    # Disable cache to avoid cached answers while performing the checks
    cache = NullCache()

    exit_code = 0
    for engine in ('google', 'bing', 'duckduckgo'):
        print('Checking {}...'.format(engine))
        try:
            _sanity_check(engine)
        except (GoogleValidationError, BingValidationError, DDGValidationError):
            _print_err('{} query failed'.format(engine))
            exit_code = -1
    if exit_code == 0:
        print('Ok')
    return exit_code
Exemplo n.º 7
0
    'google': SCHEME + 'www.google.com/search?q=site:{0}%20{1}&hl=en',
    'duckduckgo': SCHEME + 'duckduckgo.com/?q=site:{0}%20{1}&t=hj&ia=web'
}


'''
set up cache
'''

# Set up cache 
CACHE_EMPTY_VAL = "NULL"
CACHE_DIR = appdirs.use_cache_dir('howdoi')
CACHE_ENTRY_MAX = 128

if os.getenv('HOWDOI_DISABLE_CACHE'):
    cache = NullCache()
else:
    cache = FileSystemCache(CACHE_DIR, CACHE_ENTRY_MAX, default_timeout=0)


# start a session
howdoi_session = requests.session()


'''
get data
'''
# result proxies 
def get_result(url):
    try:
        # here we can customize proxies and certificates 
Exemplo n.º 8
0
STAR_HEADER = u('\u2605')
ANSWER_HEADER = u('{2}  Answer from {0} {2}\n{1}')
NO_ANSWER_MSG = '< no answer given >'

CACHE_EMPTY_VAL = "NULL"
CACHE_DIR = appdirs.user_cache_dir('howdoi')
CACHE_ENTRY_MAX = 128

HTML_CACHE_PATH = 'cache_html'
SUPPORTED_HELP_QUERIES = [
    'use howdoi', 'howdoi', 'run howdoi', 'do howdoi', 'howdoi howdoi',
    'howdoi use howdoi'
]

if os.getenv('HOWDOI_DISABLE_CACHE'):
    cache = NullCache()  # works like an always empty cache
else:
    cache = FileSystemCache(CACHE_DIR, CACHE_ENTRY_MAX, default_timeout=0)

howdoi_session = requests.session()


class BlockError(RuntimeError):
    pass


def _random_int(width):
    bres = os.urandom(width)
    if sys.version < '3':
        ires = int(bres.encode('hex'), 16)
    else:
Exemplo n.º 9
0
def null(app, config, args, kwargs):
    return NullCache()
Exemplo n.º 10
0
 def _null(self, **kwargs):
     """Returns a :class:`NullCache` instance"""
     return NullCache()
Exemplo n.º 11
0
elif "WEBFAF_ENVIRON_TEST" in os.environ:
    app.config.from_object("webfaf.config.TestingConfig")
else:
    app.config.from_object("webfaf.config.DevelopmentConfig")

db = SQLAlchemy(app)

if app.config["CACHE_TYPE"].lower() == "memcached":
    flask_cache = MemcachedCache(['{0}:{1}'.format(
        app.config["MEMCACHED_HOST"],
        app.config["MEMCACHED_PORT"])],
                                 key_prefix=app.config["MEMCACHED_KEY_PREFIX"])
elif app.config["CACHE_TYPE"].lower() == "simple":
    flask_cache = SimpleCache()
else:
    flask_cache = NullCache()

if app.config["PROXY_SETUP"]:
    app.wsgi_app = ProxyFix(app.wsgi_app)

if app.config["OPENID_ENABLED"]:
    from flask_openid import OpenID
    from openid_teams import teams
    oid = OpenID(app, safe_roots=[], extension_responses=[teams.TeamsResponse])
    from webfaf.login import login # pylint: disable=cyclic-import
    app.register_blueprint(login)
    from webfaf.user import user # pylint: disable=cyclic-import
    app.register_blueprint(user)

from webfaf.reports import reports # pylint: disable=wrong-import-position, cyclic-import
app.register_blueprint(reports, url_prefix="/reports")
Exemplo n.º 12
0
 def __init__(self,
              cache: BaseCache = NullCache(),
              max_search_results=100) -> None:
     self.cache = cache
     self.max_search_results = max_search_results
Exemplo n.º 13
0
def null(config, *args, **kwargs):
    return NullCache()
Exemplo n.º 14
0
def github():
    """Provides the 'github' module with caching disabled"""
    original_cache = github_module.cache
    github_module.cache = NullCache()
    yield github_module
    github_module.cache = original_cache