Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generateSwissnumber(bits):
bytes = os.urandom(bits//8)
return base32.encode(bytes)
def short_tubid_b2a(tubid):
return base32.encode(tubid)[:8]
def incident_declared(self, triggering_event):
self.trigger = triggering_event
# choose a name for the logfile
now = time.time()
unique = os.urandom(4)
unique_s = base32.encode(unique)
self.name = "incident-%s-%s" % (self.format_time(now), unique_s)
filename = self.name + ".flog"
self.abs_filename = os.path.join(self.basedir, filename)
self.abs_filename_bz2 = self.abs_filename + ".bz2"
self.abs_filename_bz2_tmp = self.abs_filename + ".bz2.tmp"
# open logfile. We use both an uncompressed one and a compressed one.
try:
self.f1 = open(self.abs_filename, "wb")
self.f2 = bz2.BZ2File(self.abs_filename_bz2_tmp, "wb")
except EnvironmentError as e:
raise IncidentDeclarationError(e)
# write header with triggering_event
flogfile.serialize_header(self.f1, "incident",
trigger=triggering_event,
versions=app_versions.versions,
def __init__(self, e):
self.e = e
self.parent = None
self.children = []
self.index = None
self.anchor_index = "no-number"
self.incarnation = base32.encode(e['d']['incarnation'][0].encode("utf-8"))
if 'num' in e['d']:
self.index = (e['from'], e['d']['num'])
self.anchor_index = "%s_%s_%d" % (quote(e['from'].encode("utf-8")),
self.incarnation.encode("utf-8"),
e['d']['num'])
self.parent_index = None
if 'parent' in e['d']:
self.parent_index = (e['from'], e['d']['parent'])
self.is_trigger = False