Python iso8601.ParseError() Examples
The following are 12
code examples of iso8601.ParseError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
iso8601
, or try the search function
.
Example #1
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: models.py From rdmo with Apache License 2.0 | 6 votes |
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
Example #4
Source File: pipeline.py From series-tiempo-ar-api with MIT License | 6 votes |
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
Example #5
Source File: views.py From coursys with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: __init__.py From OpenMTC with Eclipse Public License 1.0 | 5 votes |
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)
Example #7
Source File: receive_notifications.py From notifications-api with MIT License | 5 votes |
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()
Example #8
Source File: __init__.py From notifications-api with MIT License | 5 votes |
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
Example #9
Source File: models.py From openprocurement.api with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: functions.py From aw-core with Mozilla Public License 2.0 | 5 votes |
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)
Example #11
Source File: filters.py From avos with Apache License 2.0 | 5 votes |
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 ''
Example #12
Source File: timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
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))