當前位置: 首頁>>代碼示例>>Python>>正文


Python iso8601.ParseError方法代碼示例

本文整理匯總了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 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:22,代碼來源:views.py

示例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 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:21,代碼來源:views.py

示例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 
開發者ID:rdmorganiser,項目名稱:rdmo,代碼行數:24,代碼來源:models.py

示例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 
開發者ID:datosgobar,項目名稱:series-tiempo-ar-api,代碼行數:22,代碼來源:pipeline.py

示例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) 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:29,代碼來源:views.py

示例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) 
開發者ID:OpenMTC,項目名稱:OpenMTC,代碼行數:9,代碼來源:__init__.py

示例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() 
開發者ID:alphagov,項目名稱:notifications-api,代碼行數:13,代碼來源:receive_notifications.py

示例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 
開發者ID:alphagov,項目名稱:notifications-api,代碼行數:14,代碼來源:__init__.py

示例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) 
開發者ID:openprocurement,項目名稱:openprocurement.api,代碼行數:14,代碼來源:models.py

示例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) 
開發者ID:ActivityWatch,項目名稱:aw-core,代碼行數:14,代碼來源:functions.py

示例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 '' 
開發者ID:CiscoSystems,項目名稱:avos,代碼行數:10,代碼來源:filters.py

示例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)) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:10,代碼來源:timeutils.py


注:本文中的iso8601.ParseError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。