当前位置: 首页>>代码示例>>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;未经允许,请勿转载。