本文整理汇总了Python中iso8601.ParseError方法的典型用法代码示例。如果您正苦于以下问题:Python iso8601.ParseError方法的具体用法?Python iso8601.ParseError怎么用?Python iso8601.ParseError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iso8601
的用法示例。
在下文中一共展示了iso8601.ParseError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calendar_data
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def calendar_data(request):
"""
AJAX JSON results for the calendar (rendered by dashboard.views.calendar)
"""
try:
st = iso8601.parse_date(request.GET['start'])
en = iso8601.parse_date(request.GET['end'])
except (KeyError, ValueError, iso8601.ParseError):
return NotFoundResponse(request, errormsg="Bad request")
user = get_object_or_404(Person, userid=request.user.username)
local_tz = pytz.timezone(settings.TIME_ZONE)
start = st - datetime.timedelta(days=1)
end = en + datetime.timedelta(days=1)
resp = HttpResponse(content_type="application/json")
events = _calendar_event_data(user, start, end, local_tz, dt_string=True, colour=True,
due_before=datetime.timedelta(minutes=1), due_after=datetime.timedelta(minutes=30))
json.dump(list(events), resp, indent=1)
return resp
示例2: _offering_meeting_time_data
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def _offering_meeting_time_data(request, offering):
"""
fullcalendar.js data for this offering's events
"""
try:
st = iso8601.parse_date(request.GET['start'])
en = iso8601.parse_date(request.GET['end'])
except (KeyError, ValueError, iso8601.ParseError):
return NotFoundResponse(request, errormsg="Bad request")
local_tz = pytz.timezone(settings.TIME_ZONE)
start = st - datetime.timedelta(days=1)
end = en + datetime.timedelta(days=1)
response = HttpResponse(content_type='application/json')
data = list(_offerings_calendar_data([offering], None, start, end, local_tz,
dt_string=True, colour=True, browse_titles=True))
json.dump(data, response, indent=1)
return response
示例3: value
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def value(self):
if self.option:
value = self.option.text or ''
if self.option.additional_input and self.text:
value += ': ' + self.text
return value
elif self.text:
if self.value_type == VALUE_TYPE_DATETIME:
try:
return iso8601.parse_date(self.text).date()
except iso8601.ParseError:
return self.text
elif self.value_type == VALUE_TYPE_BOOLEAN:
if self.text == '1':
return _('Yes')
else:
return _('No')
else:
return self.text
else:
return None
示例4: validate_date
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def validate_date(self, _date, param):
"""Valida y parsea la fecha pasada.
Args:
_date (str): date string, ISO 8601
param (str): Parámetro siendo parseado
Returns:
date con la fecha parseada
Raises:
ValueError: si el formato no es válido
"""
try:
parsed_date = iso8601.parse_date(_date)
except iso8601.ParseError:
self._append_error(strings.INVALID_DATE.format(param, _date))
raise ValueError
return parsed_date
示例5: get
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def get(self, request):
# Override to catch exceptions caused by CAS server not responding, which happens and is beyond our control.
try:
return super().get(request)
except IOError as e:
# Ignore a minimal set of errors we have actually seen result from CAS outages
if e.errno in [104, 110, 'socket error']:
pass
# HTTPError is a subclass of OSError, which IOError is an alias for.
# Sometimes, the CAS server seems to just return a 500 internal server error. Let's handle that the
# same way as the above case.
elif isinstance(e, HTTPError):
if e.code == 500:
pass
else:
# Any other HTTPError should bubble up and let us know something horrible has happened.
raise HTTPError("Got an HTTP Error when authenticating. The error is: {0!s}.".format(e))
else:
raise IOError("The errno is %r: %s." % (e.errno, str(e)))
except ParseError:
pass
error = "<h1>Forbidden</h1><p>Login failed because of a CAS error.</p>"
return HttpResponseForbidden(error)
示例6: convert
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def convert(self, value, instance):
if isinstance(value, str):
try:
return parse_date(value)
except ParseError as e:
raise ValueError(str(e))
return super(DatetimeAttribute, self).convert(value, instance)
示例7: format_mmg_datetime
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def format_mmg_datetime(date):
"""
We expect datetimes in format 2017-05-21+11%3A56%3A11 - ie, spaces replaced with pluses, and URI encoded
and in UTC
"""
try:
orig_date = format_mmg_message(date)
parsed_datetime = iso8601.parse_date(orig_date).replace(tzinfo=None)
return parsed_datetime
except iso8601.ParseError:
return datetime.utcnow()
示例8: validate_schema_date_with_hour
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def validate_schema_date_with_hour(instance):
if isinstance(instance, str):
try:
dt = iso8601.parse_date(instance).replace(tzinfo=None)
if dt < datetime.utcnow():
raise ValidationError("datetime can not be in the past")
if dt > datetime.utcnow() + timedelta(hours=24):
raise ValidationError("datetime can only be 24 hours in the future")
except ParseError:
raise ValidationError("datetime format is invalid. It must be a valid ISO8601 date time format, "
"https://en.wikipedia.org/wiki/ISO_8601")
return True
示例9: to_native
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def to_native(self, value, context=None):
if isinstance(value, datetime):
return value
try:
date = parse_date(value, None)
if not date.tzinfo:
date = TZ.localize(date)
return date
except ParseError:
raise ConversionError(self.messages['parse'].format(value))
except OverflowError as e:
raise ConversionError(e.message)
示例10: q2_query_bucket
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def q2_query_bucket(
datastore: Datastore, namespace: TNamespace, bucketname: str
) -> List[Event]:
_verify_bucket_exists(datastore, bucketname)
try:
starttime = iso8601.parse_date(namespace["STARTTIME"])
endtime = iso8601.parse_date(namespace["ENDTIME"])
except iso8601.ParseError:
raise QueryFunctionException(
"Unable to parse starttime/endtime for query_bucket"
)
return datastore[bucketname].get(starttime=starttime, endtime=endtime)
示例11: parse_isotime
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def parse_isotime(timestr, default=None):
"""This duplicates oslo timeutils parse_isotime but with a
@register.filter annotation and a silent fallback on error.
"""
try:
return iso8601.parse_date(timestr)
except (iso8601.ParseError, TypeError):
return default or ''
示例12: parse_isotime
# 需要导入模块: import iso8601 [as 别名]
# 或者: from iso8601 import ParseError [as 别名]
def parse_isotime(timestr):
"""Parse time from ISO 8601 format."""
try:
return iso8601.parse_date(timestr)
except iso8601.ParseError as e:
raise ValueError(six.text_type(e))
except TypeError as e:
raise ValueError(six.text_type(e))