Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except ValueError:
utils.LOGGER.warning("Error while handling line %r. "
"Trying again", line)
proc = create_process(progname, fname_sensor)
procs[fname_sensor] = proc
# Second (and last) try
try:
proc.stdin.write(line)
utils.LOGGER.warning(" ... OK")
except ValueError:
handled_ok = False
utils.LOGGER.warning(" ... KO")
fdesc.close()
if handled_ok:
os.unlink(fname)
utils.LOGGER.debug(' ... OK')
else:
utils.LOGGER.debug(' ... KO')
# SHUTDOWN
for sensorjob in procs:
procs[sensorjob].stdin.close()
procs[sensorjob].wait()
last = len(self.queries) - 1
for i, q_query in enumerate(list(self.queries)):
self.commit(query=q_query, renew=True if i < last else renew)
return
q_query, params = self.queries.pop(query)
self.conn.execute(q_query, *params)
self.trans.commit()
newtime = time.time()
l_params = len(params)
try:
self.commited_counts[query] += l_params
except KeyError:
self.commited_counts[query] = l_params
rate = l_params / (newtime - self.start_time)
utils.LOGGER.debug("DB:%s", query)
utils.LOGGER.debug("DB:%d inserts, %f/sec (total %d)",
l_params, rate, self.commited_counts[query])
if renew:
self.start_time = newtime
self.trans = self.conn.begin()
try_count = self.retries
# Concurrent insertion handling
while True:
try:
transaction = self.db.begin()
for args, kargs in self.queries:
if len(args) > 1:
Neo4jDB.to_dbdict(args[1])
transaction.run(*args, **kargs)
transaction.commit()
break
# FIXME: there might be more exceptions to catch
except TransientError as e:
try_count -= 1
if self.retries == 0 or try_count > 0:
utils.LOGGER.debug(
"DB:Concurrent access error (%r), retrying.", e,
)
# Reduce contention with a little sleep
time.sleep(random.random() / 10)
else:
raise
MERGE (%s)
MERGE (new_f)-[:TO]->(d2)
MERGE (new_f)<-[:SEND]-(src)
%s
WITH *
%s
DETACH DELETE old_f
""" % (
self._gen_merge_elt("new_f", ["Flow"], {"__key__": new_key}),
set_clause,
"MATCH (old_f)-[:SEEN]->(t:Time)\n"
"MERGE (new_f)-[:SEEN]->(t)" if config.FLOW_TIME else "",
)
if config.DEBUG_DB:
utils.LOGGER.debug("DB:Second (slower) pass...")
tstamp = time.time()
self.db.run(q)
if config.DEBUG_DB:
utils.LOGGER.debug("DB:Took %f secs", time.time() - tstamp)
WITH *
MATCH (src)-[:SEND]->(df:Flow {sports: [sport]})-[:TO]->(dst)
%s
DETACH DELETE df
""" % (
self._gen_merge_elt("new_f", ["Flow"], {"__key__": new_key}),
set_clause,
"MATCH (df)-[:SEEN]->(t:Time)\n"
"MERGE (new_f)-[:SEEN]->(t)" if config.FLOW_TIME else "",
)
if config.DEBUG_DB:
utils.LOGGER.debug("DB:Fixing client/server ports...")
tstamp = time.time()
self.db.run(q)
if config.DEBUG_DB:
utils.LOGGER.debug("DB:Took %f secs", (time.time() - tstamp))
tstamp = time.time()
msg = 'Option%s not understood: %s' % (
's' if len(unused) > 1 else '',
', '.join(unused),
)
sys.stdout.write(webutils.js_alert("param-unused", "warning", msg))
utils.LOGGER.warning(msg)
elif callback is not None:
sys.stdout.write(webutils.js_del_alert("param-unused"))
if config.DEBUG:
msg = "filter: %r" % flt
sys.stdout.write(webutils.js_alert("filter", "info", msg))
utils.LOGGER.debug(msg)
msg = "user: %r" % webutils.get_user()
sys.stdout.write(webutils.js_alert("user", "info", msg))
utils.LOGGER.debug(msg)
version_mismatch = {}
if callback is None:
tab, sep = "", "\n"
else:
tab, sep = "\t", ",\n"
sys.stdout.write("%s([\n" % callback)
## XXX-WORKAROUND-PGSQL
# for rec in result:
for i, rec in enumerate(result):
for fld in ['_id', 'scanid']:
try:
del rec[fld]
except KeyError:
pass
if not ipsasnumbers:
for char in data:
if state == 0:
if char == ',':
values.append(''.join(curdata).strip())
curdata = []
else:
if char == '"':
state = 1 # inside " "
curdata.append(char)
elif state == 1:
if char == '"':
state = 0
curdata.append(char)
values.append(''.join(curdata).strip())
if state == 1:
utils.LOGGER.debug("Could not parse Digest auth data [%r]", data)
return values
def store_scan_doc(self, scan):
ident = self.db[self.colname_scans].insert(scan)
utils.LOGGER.debug("SCAN STORED: %r in %r", ident, self.colname_scans)
return ident