Skip to content

Commit

Permalink
halflife.py: raise DisabledError for regex queries
Browse files Browse the repository at this point in the history
These have been disabled in Metasmoke for the time being
  • Loading branch information
tripleee committed Feb 20, 2019
1 parent fab47fd commit de3f5a2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions halflife.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ class FetchError (Exception):
pass


class DisabledError(Exception):
"""
Regex queries are disabled for now.
"""
pass


class HalflifeClient (ActionCableClient):
def init_hook (self):
self.flagged = set()
Expand Down Expand Up @@ -169,8 +176,11 @@ def on_event_post_create (self, ws, arg):
if 'object' in arg['message']:
link = arg['message']['object']['link']
if link not in self.flagged:
self.checker.check(arg['message']['object'])
self.flagged.update([link])
try:
self.checker.check(arg['message']['object'])
self.flagged.update([link])
except DisabledError as e:
logging.warning('Untrapped DisabledError {0!r}'.format(e))
else:
logging.info(
'Already flagged {link}, not checking again'.format(
Expand Down Expand Up @@ -385,7 +395,7 @@ def host_report(url_result, url, post_id):
re=tail.replace('-', r'\W?'),
tp=tail_query['tp_count'],
all=len(tail_query['hits'])))
except MetasmokeApiError as err:
except (MetasmokeApiError, DisabledError) as err:
logging.error('Could not perform query for {0}'
' ({1})'.format(tail_re, err))

Expand Down Expand Up @@ -695,7 +705,7 @@ def _fetch (url):
result[url]['domain_check'] = {host: None}
try:
result[url]['metasmoke'] = self.domain_query(host)
except MetasmokeApiError as err:
except (MetasmokeApiError, DisabledError) as err:
logging.error('Could not perform domain query for {0}'
' ({1})'.format(host, err))

Expand Down Expand Up @@ -817,6 +827,7 @@ def tp_query (self, regex):
"""
Return hits, timespan, tp_count, below auto for a word-bounded regex.
"""
raise DisabledError('sorry, regex query is disabled')
hits_query = self.word_query(regex)
hits = hits_query['items']
tp = [x for x in hits
Expand Down

0 comments on commit de3f5a2

Please sign in to comment.