Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _publish(self):
elapse_time = None
if self._request_time and self._response_time:
elapse_time = self._response_time - self._request_time
self._ctx.broker.publish(
broker.TOPICS.SQL_COMMAND,
sql.SQL_INSERT_RAW_TRAFFIC,
self._request_buffer,
self._response_buffer,
elapse_time,
self._current_key,
)
self._ctx.broker.publish(
broker.TOPICS.RAW_TRAFFIC,
self._current_key,
self._request_buffer,
self._response_buffer,
)
row = dict(zip(result.title(), row))
if self._ctx.delimiter:
delimiter_packet = self._ctx.delimiter.get_delimiter_packet(
row["traffic_id"])
delimiter_packet = pywb.ftwhelper.get(
delimiter_packet, pywb.ftwhelper.FTW_TYPE.PACKETS)
dumper.dump(delimiter_packet)
dumper.dump(row["request"])
if self._ctx.delimiter:
delimiter_packet = self._ctx.delimiter.get_delimiter_packet(
row["traffic_id"])
delimiter_packet = pywb.ftwhelper.get(
delimiter_packet, pywb.ftwhelper.FTW_TYPE.PACKETS)
dumper.dump(delimiter_packet)
self._ctx.broker.publish(
broker.TOPICS.SQL_COMMAND,
request_sql_script
if request_sql_script else sql.SQL_QUERY_REQUEST,
*args,
callback=gen_requests)
def __init__(self, context):
""" Create a Database,
subscribe itself to SQL_COMMAND,
query for initializing database.
"""
self.context = context
self.context.broker.subscribe(broker.TOPICS.SQL_COMMAND, self._query)
try:
self.query(sql.SQL_INITIALIZE_DATABASE)
except sqlite3.OperationalError:
# ignore repeatedly initialize error
pass
def __del__(self):
self.context.broker.unsubscribe(broker.TOPICS.SQL_COMMAND, self._query)
log_buffer = []
# Remove logs generated by dummy request
start_unique_id = '[unique_id "{unique_id}"]'.format(
unique_id = self._get_unique_id(collected_buffer[0])
)
end_unique_id = '[unique_id "{unique_id}"]'.format(
unique_id = self._get_unique_id(collected_buffer[-1])
)
for line in collected_buffer:
if start_unique_id not in line and end_unique_id not in line:
log_buffer.append(line)
if log_buffer:
self._ctx.broker.publish(
broker.TOPICS.SQL_COMMAND,
sql.SQL_INSERT_LOG,
"\n".join(log_buffer),
key,
)