Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "isodate in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'isodate' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

return make_year_array(dates)
    except ValueError:
        pass

    try:
        dates = str(dates).upper()  # Ambry tends to lowercase things
        parts = dates.replace('E', '/').split('/')  # / is in std; ambry uses 'e' to be compat with urls.

        rparts = []

        for p in parts:
            try:
                rparts.append(isodate.parse_date(p))
            except isodate.isoerror.ISO8601Error:
                try:
                    rparts.append(isodate.parse_duration(p))
                except:
                    raise

        types = tuple(type(x) for x in rparts)

        if types == (datetime.date, isodate.duration.Duration):
            start = rparts[0].year
            end = start + int(rparts[1].years)
        elif types == (isodate.duration.Duration, datetime.date):
            end = rparts[1].year + 1
            start = end - int(rparts[0].years)
        elif types == (datetime.date, datetime.date):
            start = rparts[0].year
            end = rparts[1].year + 1

        else:
def test_expired():
    # valid
    expiration = dt.utcnow() + timedelta(seconds=10)
    expiration = expiration.replace(tzinfo=isodate.UTC)
    expiration = isodate.strftime(expiration, isodate.DT_EXT_COMPLETE)
    agent = Agent(expiration=expiration)
    admin = agent.Admin()
    print admin.echo('FUTURE')
    # invalid
    agent = Agent(expiration='12345')
    admin = agent.Admin()
    print admin.echo('INVALID')
    # expired
    expiration = dt.utcnow() - timedelta(seconds=10)
    expiration = expiration.replace(tzinfo=isodate.UTC)
    expiration = isodate.strftime(expiration, isodate.DT_EXT_COMPLETE)
    agent = Agent(wait=0, expiration=expiration)
    admin = agent.Admin()
    print admin.echo('EXPIRED')
    sys.exit(0)
def test_expired():
    # valid
    expiration = dt.utcnow() + timedelta(seconds=10)
    expiration = expiration.replace(tzinfo=isodate.UTC)
    expiration = isodate.strftime(expiration, isodate.DT_EXT_COMPLETE)
    agent = Agent(expiration=expiration)
    admin = agent.Admin()
    print admin.echo('FUTURE')
    # invalid
    agent = Agent(expiration='12345')
    admin = agent.Admin()
    print admin.echo('INVALID')
    # expired
    expiration = dt.utcnow() - timedelta(seconds=10)
    expiration = expiration.replace(tzinfo=isodate.UTC)
    expiration = isodate.strftime(expiration, isodate.DT_EXT_COMPLETE)
    agent = Agent(wait=0, expiration=expiration)
    admin = agent.Admin()
    print admin.echo('EXPIRED')
    sys.exit(0)
_validation = {}
            _attribute_map = {'p1':{'key':'p1','type':'str'},
                              'p2':{'key':'p2','type':'str'},
                              'top_date':{'key':'top_date', 'type':'iso-8601'},
                              'top_dates':{'key':'top_dates', 'type':'[iso-8601]'},
                              'insider':{'key':'insider','type':'{iso-8601}'},
                              'top_complex':{'key':'top_complex','type':'ComplexId'}}

            p1 = 'value1'
            p2 = 'value2'
            top_date = isodate.parse_datetime('2014-01-01T00:00:00')
            top_dates = [isodate.parse_datetime('1900-01-01T00:00:00'), isodate.parse_datetime('1901-01-01T00:00:00')]
            insider = {
                'k1': isodate.parse_datetime('2015-01-01T00:00:00'),
                'k2': isodate.parse_datetime('2016-01-01T00:00:00'),
                'k3': isodate.parse_datetime('2017-01-01T00:00:00')}
            top_complex = ComplexId()

        message =self.s._serialize(ComplexJson())

        output = {
            'p1': 'value1',
            'p2': 'value2',
            'top_date': '2014-01-01T00:00:00.000Z',
            'top_dates': [
                '1900-01-01T00:00:00.000Z',
                '1901-01-01T00:00:00.000Z'
            ],
            'insider': {
                'k1': '2015-01-01T00:00:00.000Z',
                'k2': '2016-01-01T00:00:00.000Z',
                'k3': '2017-01-01T00:00:00.000Z'
# GET primitive/date
        dateResult = client.primitive.get_date()
        self.assertEqual(isodate.parse_date("0001-01-01"), dateResult.field)
        self.assertEqual(isodate.parse_date("2016-02-29"), dateResult.leap)
        dateRequest = DateWrapper
        dateRequest.field = isodate.parse_date('0001-01-01')
        dateRequest.leap = isodate.parse_date('2016-02-29')
        client.primitive.put_date(dateRequest)
        # GET primitive/datetime
        datetimeResult = client.primitive.get_date_time()
        min_date = datetime.datetime.min
        min_date = min_date.replace(tzinfo=UTC())
        self.assertEqual(min_date, datetimeResult.field)
        
        datetime_request = DatetimeWrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T18:38:00Z"))
        client.primitive.put_date_time(datetime_request)
        
        # GET primitive/datetimerfc1123
        datetimeRfc1123Result = client.primitive.get_date_time_rfc1123()
        self.assertEqual(min_date, datetimeRfc1123Result.field)

        datetime_request = Datetimerfc1123Wrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T11:38:00Z"))
        client.primitive.put_date_time_rfc1123(datetime_request)

        # GET primitive/duration
        #TimeSpan expectedDuration = new TimeSpan(123, 22, 14, 12, 11);
        durationResult = client.primitive.get_duration();
        self.assertEqual(123, durationResult.field.days)
min_date = datetime.min
        min_date = min_date.replace(tzinfo=UTC())
        self.assertEqual(min_date, datetimeResult.field)

        datetime_request = DatetimeWrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T18:38:00Z"))
        client.primitive.put_date_time(datetime_request)

        # GET primitive/datetimerfc1123
        datetimeRfc1123Result = client.primitive.get_date_time_rfc1123()
        self.assertEqual(min_date, datetimeRfc1123Result.field)

        datetime_request = Datetimerfc1123Wrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T11:38:00Z"))
        client.primitive.put_date_time_rfc1123(datetime_request)

        # GET primitive/duration
        expected = timedelta(days=123, hours=22, minutes=14, seconds=12, milliseconds=11)
        self.assertEqual(expected, client.primitive.get_duration().field)

        client.primitive.put_duration(expected)

        # GET primitive/byte
        byteResult = client.primitive.get_byte()
        valid_bytes = bytearray([0x0FF, 0x0FE, 0x0FD, 0x0FC, 0x000, 0x0FA, 0x0F9, 0x0F8, 0x0F7, 0x0F6])
        self.assertEqual(valid_bytes, byteResult.field)

        # PUT primitive/byte
        client.primitive.put_byte(valid_bytes)
client.array.get_long_invalid_string()

        self.assertEqual(client.array.get_float_invalid_null(), [0.0, None, -1.2e20])

        with self.assertRaises(DeserializationError):
            client.array.get_float_invalid_string()

        self.assertEqual(client.array.get_double_invalid_null(), [0.0, None, -1.2e20])

        with self.assertRaises(DeserializationError):
            client.array.get_double_invalid_string()

        self.assertEqual(client.array.get_string_with_invalid(), ["foo", "123", "foo2"])

        d_array = client.array.get_date_invalid_null()
        self.assertEqual(d_array, [isodate.parse_date("2012-01-01"), None, isodate.parse_date("1776-07-04")])

        with self.assertRaises(DeserializationError):
            client.array.get_date_invalid_chars()

        dt_array = client.array.get_date_time_invalid_null()
        self.assertEqual(dt_array, [isodate.parse_datetime("2000-12-01T00:00:01Z"), None])

        with self.assertRaises(DeserializationError):
            client.array.get_date_time_invalid_chars()

        test_array = ['a string that gets encoded with base64url'.encode(),
                      'test string'.encode(),
                      'Lorem ipsum'.encode()]
        self.assertEqual(client.array.get_base64_url(), test_array)
def test_date(self):
        client = AutoRestDateTestService(base_url="http://localhost:3000")

        max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z")
        min_date = isodate.parse_date("0001-01-01T00:00:00Z")
        client.date_model.put_max_date(max_date)
        client.date_model.put_min_date(min_date)

        self.assertEqual(max_date, client.date_model.get_max_date())
        self.assertEqual(min_date, client.date_model.get_min_date())
        self.assertIsNone(client.date_model.get_null())

        # Python isodate.parse support too wild input, and won't raise error
        #with self.assertRaises(DeserializationError):
        #    client.date_model.get_invalid_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_overflow_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_underflow_date()
self.assertEqual("goodrequest", stringResult.field)
        self.assertEqual("", stringResult.empty)
        self.assertIsNone(stringResult.null)

        # PUT primitive/string
        stringRequest = StringWrapper(null=None, empty="", field="goodrequest")
        client.primitive.put_string(stringRequest);

        # GET primitive/date
        dateResult = client.primitive.get_date()
        self.assertEqual(isodate.parse_date("0001-01-01"), dateResult.field)
        self.assertEqual(isodate.parse_date("2016-02-29"), dateResult.leap)

        dateRequest = DateWrapper(
            field=isodate.parse_date('0001-01-01'), 
            leap=isodate.parse_date('2016-02-29'))
        client.primitive.put_date(dateRequest)

        # GET primitive/datetime
        datetimeResult = client.primitive.get_date_time()
        min_date = datetime.min
        min_date = min_date.replace(tzinfo=UTC())
        self.assertEqual(min_date, datetimeResult.field)
        
        datetime_request = DatetimeWrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T18:38:00Z"))
        client.primitive.put_date_time(datetime_request)
        
        # GET primitive/datetimerfc1123
        datetimeRfc1123Result = client.primitive.get_date_time_rfc1123()
        self.assertEqual(min_date, datetimeRfc1123Result.field)
def test_date(self):
        client = AutoRestDateTestService(base_url="http://localhost:3000")

        max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z")
        min_date = isodate.parse_date("0001-01-01T00:00:00Z")
        client.date_model.put_max_date(max_date)
        client.date_model.put_min_date(min_date)

        self.assertEqual(max_date, client.date_model.get_max_date())
        self.assertEqual(min_date, client.date_model.get_min_date())
        self.assertIsNone(client.date_model.get_null())

        # Python isodate.parse support too wild input, and won't raise error
        #with self.assertRaises(DeserializationError):
        #    client.date_model.get_invalid_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_overflow_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_underflow_date()

Is your System Free of Underlying Vulnerabilities?
Find Out Now