How to use the isodate.ISO8601Error function in isodate

To help you get started, we’ve selected a few isodate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulp / src / pulp / client / admin / plugins / repo.py View on Github external
def _timeout(self):
        timeout = self.opts.timeout
        if timeout is None:
            return {}
        try:
            delta = parse_iso8601_duration(timeout)
        except ISO8601Error:
            msg = _('Improperly formatted timeout: %(t)s') % {'t': timeout}
            utils.system_exit(os.EX_USAGE, msg)
        if not isinstance(delta, timedelta):
            utils.system_exit(os.EX_USAGE, 'Timeout may not contain months or years')
        return {'timeout': timeout}
github pulp / pulpcore / common / pulp / common / dateutils.py View on Github external
elif part.startswith('P'):
            if interval is not None:
                raise isodate.ISO8601Error('Multiple interval durations specified')
            interval = parse_iso8601_duration(part)
        else:
            if start_time is not None:
                raise isodate.ISO8601Error('Interval with start and end times is not supported')
            start_time = parse_iso8601_datetime(part)
    # the interval is the only required part
    if interval is None:
        raise isodate.ISO8601Error('No interval specification found')
    # if the interval contains months or years, isodate will use it's own
    # internal Duration class instead of timedelta
    # pulp cannot handle Duration instances if a start_time is not provided
    if isinstance(interval, isodate.Duration) and start_time is None:
        raise isodate.ISO8601Error('Intervals with year and month values are not valid without a start time')
    return (interval, start_time, recurrences)
github hashdist / hashdist / hashdist / deps / jsonschema / _format.py View on Github external
pass
else:
    @_checks_drafts("uri", raises=ValueError)
    def is_uri(instance):
        return rfc3987.parse(instance, rule="URI_reference")


try:
    import strict_rfc3339
except ImportError:
    try:
        import isodate
    except ImportError:
        pass
    else:
        _err = (ValueError, isodate.ISO8601Error)
        _checks_drafts("date-time", raises=_err)(isodate.parse_datetime)
else:
        _checks_drafts("date-time")(strict_rfc3339.validate_rfc3339)


_checks_drafts("regex", raises=re.error)(re.compile)


@_checks_drafts(draft3="date", raises=ValueError)
def is_date(instance):
    return datetime.datetime.strptime(instance, "%Y-%m-%d")


@_checks_drafts(draft3="time", raises=ValueError)
def is_time(instance):
    return datetime.datetime.strptime(instance, "%H:%M:%S")
github pulp / pulpcore / common / pulp / common / dateutils.py View on Github external
def parse_iso8601_datetime(datetime_str):
    """
    Parse an iso8601 datetime string.
    @type datetime_str: str
    @param datetime_str: iso8601 datetime string to parse
    @rtype: datetime.datetime instance
    """
    try:
        return isodate.parse_datetime(datetime_str)
    except (ValueError, isodate.ISO8601Error):
        msg = _('Malformed ISO8601 date-time string: %(d)s') % {'d': datetime_str}
        raise isodate.ISO8601Error(msg), None, sys.exc_info()[2]
github pulp / pulp / platform / src / pulp / server / managers / consumer / history.py View on Github external
invalid_values.append('limit')

        # Verify the sort direction is valid
        if not sort in SORT_DIRECTION:
            invalid_values.append('sort')

        # Verify that start_date and end_date is valid
        if start_date is not None: 
            try: 
                dateutils.parse_iso8601_date(start_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('start_date')
        if end_date is not None: 
            try: 
                dateutils.parse_iso8601_date(end_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('end_date')
                        
        if invalid_values:
            raise InvalidValue(invalid_values)

        # Assemble the mongo search parameters
        search_params = {}
        if consumer_id:
            search_params['consumer_id'] = consumer_id
        if event_type:
            search_params['type'] = event_type

        # Add in date range limits if specified
        date_range = {}
        if start_date:
            date_range['$gte'] = start_date
github pulp / pulpcore / client_lib / pulp / client / parsers.py View on Github external
def iso8601(value):
    """
    Makes sure that an incoming ISO8601 value is formatted in the standard way
    that datetime.isoformat() does, since when we do comparisons against dates
    in mongo, the comparison is actual alphabetical order.

    :param value: ISO8601 string
    :type  value: basestring
    :return: ISO 8601 string
    :rtype:  basestring
    """
    try:
        return dateutils.parse_iso8601_datetime_or_date(value).replace(microsecond=0).isoformat()
    except isodate.ISO8601Error:
        raise ValueError(_('invalid ISO8601 string'))
github assembl / assembl / assembl / views / api2 / discussion.py View on Github external
try:
        if start:
            start = parse_datetime(start)
        else:
            discussion = request.context._instance
            start = discussion.creation_date
            # TODO: Round down at day/week/month according to interval
        if end:
            end = parse_datetime(end)
        else:
            end = datetime.now()
        if interval:
            interval = isodate.parse_duration(interval)
        else:
            interval = end - start + timedelta(seconds=1)
    except isodate.ISO8601Error as e:
        raise HTTPBadRequest(e)
    return (start, end, interval)
github pulp / pulp / server / pulp / server / managers / repo / sync.py View on Github external
try:
                limit = int(limit)
                if limit < 1:
                    invalid_values.append('limit')
            except ValueError:
                invalid_values.append('limit')

        # Verify the sort direction is valid
        if sort not in constants.SORT_DIRECTION:
            invalid_values.append('sort')

        # Verify that start_date and end_date is valid
        if start_date is not None:
            try:
                dateutils.parse_iso8601_datetime(start_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('start_date')
        if end_date is not None:
            try:
                dateutils.parse_iso8601_datetime(end_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('end_date')

        # Report any invalid values
        if invalid_values:
            raise InvalidValue(invalid_values)

        # Assemble the mongo search parameters
        search_params = {'repo_id': repo_id}
        # Add in date range limits if specified
        date_range = {}
        if start_date:
github p1c2u / openapi-core / openapi_core / schema / schemas / _format.py View on Github external
from jsonschema._format import FormatChecker
from jsonschema.exceptions import FormatError
from six import binary_type, text_type, integer_types

DATETIME_HAS_STRICT_RFC3339 = False
DATETIME_HAS_ISODATE = False
DATETIME_RAISES = ()

try:
    import isodate
except ImportError:
    pass
else:
    DATETIME_HAS_ISODATE = True
    DATETIME_RAISES += (ValueError, isodate.ISO8601Error)

try:
    import strict_rfc3339
except ImportError:
    pass
else:
    DATETIME_HAS_STRICT_RFC3339 = True
    DATETIME_RAISES += (ValueError, TypeError)


class StrictFormatChecker(FormatChecker):

    def check(self, instance, format):
        if format not in self.checkers:
            raise FormatError(
                "Format checker for %r format not found" % (format, ))
github pulp / pulp / common / pulp / common / dateutils.py View on Github external
elif part.startswith('P'):
            if interval is not None:
                raise isodate.ISO8601Error('Multiple interval durations specified')
            interval = parse_iso8601_duration(part)
        else:
            if start_time is not None:
                raise isodate.ISO8601Error('Interval with start and end times is not supported')
            start_time = parse_iso8601_datetime(part)
    # the interval is the only required part
    if interval is None:
        raise isodate.ISO8601Error('No interval specification found')
    # if the interval contains months or years, isodate will use it's own
    # internal Duration class instead of timedelta
    # pulp cannot handle Duration instances if a start_time is not provided
    if isinstance(interval, isodate.Duration) and start_time is None:
        raise isodate.ISO8601Error('Intervals with year and month values are not valid without a start time')
    return (interval, start_time, recurrences)