Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_invalid_date():
try:
iso8601.parse_date(None)
except iso8601.ParseError:
pass
else:
assert 1 == 2
def test_query2_query_categorize(datastore):
bid = "test_bucket"
qname = "test"
starttime = iso8601.parse_date("1970")
endtime = starttime + timedelta(hours=1)
example_query = """
events = query_bucket("{bid}");
events = sort_by_timestamp(events);
events = categorize(events, [[["test"], {{"regex": "test"}}], [["test", "subtest"], {{"regex": "test2"}}]]);
events_by_cat = merge_events_by_keys(events, ["$category"]);
RETURN = {{"events": events, "events_by_cat": events_by_cat}};
""".format(
bid=bid, bid_escaped=bid.replace("'", "\\'")
)
try:
bucket = datastore.create_bucket(
bucket_id=bid, type="test", client="test", hostname="test", name="asd"
)
events = [
def test_query2_return_value():
qname = "asd"
starttime = iso8601.parse_date("1970-01-01")
endtime = iso8601.parse_date("1970-01-02")
example_query = "RETURN = 1;"
result = query(qname, example_query, starttime, endtime, None)
assert result == 1
example_query = "RETURN = 'testing 123'"
result = query(qname, example_query, starttime, endtime, None)
assert result == "testing 123"
example_query = "RETURN = {'a': 1}"
result = query(qname, example_query, starttime, endtime, None)
assert result == {"a": 1}
# Nothing to return
with pytest.raises(QueryParseException):
example_query = "a=1"
def read(self, _re_sanitize=re.compile('\s+|-')):
# Cron
if self.log_tailer:
for line in iter(self.log_tailer.next, u''):
# log.debug('LINE: {!r}'.format(line))
ts, line = line.strip().split(None, 1)
ts = calendar.timegm(iso8601.parse_date(ts).utctimetuple())
matched = False
for ev, regex in self.lines.viewitems():
if not regex: continue
match = regex.search(line)
if match:
matched = True
job = match.group('job')
for alias, regex in self.aliases:
group = alias[1:] if alias.startswith('_') else None
alias_match = regex.search(job)
if alias_match:
if group is not None:
job = _re_sanitize.sub('_', alias_match.group(group))
else: job = alias
break
else:
for msg in sorted(new_messages, key=lambda x: iso8601.parse_date(
x.find('{http://www.w3.org/2005/Atom}published').text).timestamp()):
self.callback(NewAtomEntry(msg, http_time_now))
def timestamp(self):
return iso8601.parse_date(self["timestamp"])
def validateInput(self, value):
"""
Checks if the provided value is a valid and ISO8601 compliant date string.
"""
try:
iso8601.parse_date(value)
return True
except iso8601.iso8601.ParseError:
return False
def get_submission_status(self, config=None, filter_active=True, show_namespaces=False):
"""
Get status of all submissions in the workspace (replicates UI Monitor)
"""
# filter submissions by configuration
submissions = self.list_submissions(config=config)
statuses = ['Succeeded', 'Running', 'Failed', 'Aborted', 'Aborting', 'Submitted', 'Queued']
df = []
for s in submissions:
d = {
'entity_id':s['submissionEntity']['entityName'],
'status':s['status'],
'submission_id':s['submissionId'],
'date':iso8601.parse_date(s['submissionDate']).strftime('%H:%M:%S %m/%d/%Y'),
}
d.update({i:s['workflowStatuses'].get(i,0) for i in statuses})
if show_namespaces:
d['configuration'] = s['methodConfigurationNamespace']+'/'+s['methodConfigurationName']
else:
d['configuration'] = s['methodConfigurationName']
df.append(d)
df = pd.DataFrame(df)
df.set_index('entity_id', inplace=True)
df['date'] = pd.to_datetime(df['date'])
df = df[['configuration', 'status']+statuses+['date', 'submission_id']]
if filter_active:
df = df[(df['Running']!=0) | (df['Submitted']!=0)]
return df.sort_values('date')[::-1]
def get_asn1time(when):
"""Return an ASN1 normalized time from a datetime object or ISO 8601
string.
"""
if when is None:
when = now_utc()
if isinstance(when, str):
import iso8601
when = iso8601.parse_date(when)
assert type(when) is datetime
return when.strftime("%Y%m%d%H%M%S%z")
def epoch_from_iso(datestring):
return (iso8601.parse_date(datestring) - datetime.datetime(1970,1,1, tzinfo=pytz.utc)).total_seconds()