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_timezone_offset_to_utc(self):
dt = "2010-02-10T12:36:00+03:00"
l = Literal(dt,
datatype=URIRef('http://www.w3.org/2001/XMLSchema#dateTime'))
utc_dt = l.toPython().astimezone(UTC)
self.assertEqual(datetime_isoformat(utc_dt),
"2010-02-10T09:36:00Z")
def isostring(self):
if self.date is None:
return None
if isinstance(self.date, datetime.datetime):
return isodate.datetime_isoformat(self.date)
return isodate.date_isoformat(self.date)
def genDateRange(startDate, endDate, interval):
import isodate # https://github.com/gweis/isodate
dates = []
dateFrom = isodate.parse_datetime(startDate)
dateTo = isodate.parse_datetime(endDate)
dateInterval = isodate.parse_duration(interval)
currentDate = dateFrom
while currentDate <= dateTo:
datetime = isodate.datetime_isoformat(currentDate)
dates.append(datetime)
currentDate = currentDate + dateInterval
return dates
r += " \n"
r += " " + ofl.desc + "\n"
r += " " + ofl.name + "\n"
if ofl.boundedBy:
r += " \n"
r += " \n"
r += " " + str(ofl.boundedBy) + "\n"
r += " \n"
r += " \n"
if ofl.beginPosition and ofl.endPosition :
r += " <time>\n"
r += " \n"
r += " " + iso.datetime_isoformat(ofl.beginPosition) + "\n"
r += " " + iso.datetime_isoformat(ofl.endPosition) + "\n"
r += " \n"
r += " </time>\n"
else:
r += " \n"
for pr in ofl.procedures:
r += " \n"
for op in ofl.obsProp:
r += " \n"
for fo in ofl.fois:
r += " \n"
tmpBegin = begin
tmpEnd = end
if (end-begin) > step:
tmpEnd = tmpBegin + step
while tmpEnd <= end:
print(("%s - %s") % (tmpBegin, tmpEnd))
if tmpBegin == tmpEnd:
params["eventTime"] = iso.datetime_isoformat(tmpBegin)
else:
params["eventTime"] = "%s/%s" % (
iso.datetime_isoformat(tmpBegin),
iso.datetime_isoformat(tmpEnd))
res = req.get("%s?%s" % (url, urllib.parse.urlencode(params)), auth=auth)
makeFile(res, procedure, observedProperty, d, qi, filename)
tmpBegin = tmpEnd
tmpEnd = tmpBegin + step
print(" %s ************************** " % iso.datetime_isoformat(
tmpEnd))
if tmpBegin < end:
tmpEnd = end
if tmpBegin == tmpEnd:
params["eventTime"] = iso.datetime_isoformat(tmpBegin)
else:
params["eventTime"] = "%s/%s" % (
ON id_off = id_off_fk
GROUP BY
id_off, name_off, desc_off, expiration_off, active_off
ORDER BY
name_off; """ %((service,)*2)
rows = pgdb.select(sql,None)
if rows:
import isodate
return [
{
"id":row["id"],
"name":row["name"],
"description":row["description"],
"procedures":row["procedures"],
"expiration": (isodate.datetime_isoformat(row["expiration"])
if row["expiration"] else ""),
"active":row["active"]
} for row in rows
]
else:
return []
r += " \n"
r += " " + ofl.desc + "\n"
r += " " + ofl.name + "\n"
if ofl.boundedBy:
r += " \n"
r += " \n"
r += " " + str(ofl.boundedBy) + "\n"
r += " \n"
r += " \n"
if ofl.beginPosition and ofl.endPosition :
r += " <time>\n"
r += " \n"
r += " " + iso.datetime_isoformat(ofl.beginPosition) + "\n"
r += " " + iso.datetime_isoformat(ofl.endPosition) + "\n"
r += " \n"
r += " </time>\n"
else:
r += " \n"
for pr in ofl.procedures:
r += " \n"
for op in ofl.obsProp:
r += " \n"
for fo in ofl.fois:
r += " \n"
fcontent=""
names=["date"]
dtlis=[]
for key, tss in self.series.iteritems():
for id,tsi in enumerate(tss):
dtlis.append(tsi.tserie)
names.append(tsi.procedure)
stack=apply(ts.stack,dtlis)
dates=stack.dates.tolist()
if mode=="text":
txt = sep.join(names)
txt += "\n"
for l in range(stack.shape[0]):
txt += "%s" %(iso.datetime_isoformat(dates[l]))
txt += sosConfig.timezone + sep
txt += sep.join([str(st) for st in stack.data[l]])
txt += "\n"
fcontent += txt
if fname:
file = open(fname, 'w')
file.write(fcontent)
file.close()
else:
return fcontent
def isostring(self):
if self.date is None:
return None
if isinstance(self.date, datetime.datetime):
return isodate.datetime_isoformat(self.date)
return isodate.date_isoformat(self.date)
metadata[META_NUM_MEDIA_FILES] += 1
for subdir in subdirs:
add_files(storage, os.path.join((dirname, subdir)), destdir)
if include_media:
destdir = os.path.join(backup_dir, 'media')
for media_dir in MEDIA_WHITELIST:
if storage.exists(media_dir):
add_files(storage, media_dir, destdir)
else:
logger.warning('Not including media.')
# Store metadata file.
metadata[META_SERVER_NAME] = get_title()
metadata[META_SERVER_VERSION] = get_version()
metadata[META_CREATED_TIME] = isodate.datetime_isoformat(date)
metadata[META_DB_ENGINE] = db_impl.engine_name()
metadata[META_BACKUP_FORMAT] = BACKUP_FORMAT
metadata_filename = os.path.join(backup_dir, METADATA_FILENAME)
with open(metadata_filename, 'w') as outfile:
json.dump(metadata, outfile, sort_keys=True, indent=2)
valid = False
try:
verify_backup_directory(backup_dir)
valid = True
return backup_dir
finally:
if not valid:
shutil.rmtree(backup_dir)