Lines Matching full:util

9 from asn1crypto import util
28 utc = util.timezone.utc
35 self.assertEqual(util.int_to_bytes(0, False, 0), b'')
36 self.assertEqual(util.int_to_bytes(0, False), b'\x00')
37 self.assertEqual(util.int_to_bytes(0, False, 3), b'\x00\x00\x00')
38 self.assertEqual(util.int_to_bytes(0, True, 0), b'')
39 self.assertEqual(util.int_to_bytes(0, True), b'\x00')
40 self.assertEqual(util.int_to_bytes(0, True, 3), b'\x00\x00\x00')
42 self.assertEqual(util.int_to_bytes(128, False), b'\x80')
43 self.assertEqual(util.int_to_bytes(128, False, 3), b'\x00\x00\x80')
44 self.assertEqual(util.int_to_bytes(-128, True), b'\x80')
45 self.assertEqual(util.int_to_bytes(-128, True, 3), b'\xff\xff\x80')
47 self.assertEqual(util.int_to_bytes(255, False), b'\xff')
48 self.assertEqual(util.int_to_bytes(255, False, 3), b'\x00\x00\xff')
49 self.assertEqual(util.int_to_bytes(-1, True), b'\xff')
50 self.assertEqual(util.int_to_bytes(-1, True, 3), b'\xff\xff\xff')
52 self.assertEqual(util.int_to_bytes(12345678, False), b'\xbc\x61\x4e')
53 self.assertEqual(util.int_to_bytes(12345678, False, 3), b'\xbc\x61\x4e')
54 self.assertEqual(util.int_to_bytes(12345678, False, 5), b'\x00\x00\xbc\x61\x4e')
55 self.assertEqual(util.int_to_bytes(12345678 - 2 ** 24, True), b'\xbc\x61\x4e')
56 self.assertEqual(util.int_to_bytes(12345678 - 2 ** 24, True, 3), b'\xbc\x61\x4e')
57 self.assertEqual(util.int_to_bytes(12345678 - 2 ** 24, True, 5), b'\xff\xff\xbc\x61\x4e')
60 util.int_to_bytes(123456789, width=3)
62 util.int_to_bytes(50000, signed=True, width=2)
65 self.assertEqual(util.int_from_bytes(b'', False), 0)
66 self.assertEqual(util.int_from_bytes(b'', True), 0)
67 self.assertEqual(util.int_from_bytes(b'\x00', False), 0)
68 self.assertEqual(util.int_from_bytes(b'\x00', True), 0)
69 self.assertEqual(util.int_from_bytes(b'\x80', False), 128)
70 self.assertEqual(util.int_from_bytes(b'\x80', True), -128)
71 self.assertEqual(util.int_from_bytes(b'\xff', False), 255)
72 self.assertEqual(util.int_from_bytes(b'\xff', True), -1)
73 self.assertEqual(util.int_from_bytes(b'\xbc\x61\x4e', False), 12345678)
74 self.assertEqual(util.int_from_bytes(b'\xbc\x61\x4e', True), 12345678 - 2 ** 24)
78 self.assertEqual(i, util.int_from_bytes(util.int_to_bytes(i, True), True))
80 self.assertEqual(i, util.int_from_bytes(util.int_to_bytes(i, False), False))
88 util.timezone(delta_plus_5_42 * 5)
92 util.timezone(delta_minus_5_42 * 5)
97 util.timezone(timedelta(hours=5, minutes=42, seconds=13))
100 util.timezone(timedelta(hours=5, minutes=42, microseconds=13))
103 tz0 = util.timezone(delta_plus_5_42)
104 tz1 = util.timezone(delta_minus_5_42)
111 self.assertEqual('5_42', util.timezone(delta_plus_5_42, '5_42').tzname(None))
112 self.assertEqual('UTC+05:42', util.timezone(delta_plus_5_42).tzname(None))
113 self.assertEqual('UTC-05:42', util.timezone(delta_minus_5_42).tzname(None))
116 self.assertEqual('UTC', util.timezone(timedelta(0)).tzname(None))
119 self.assertEqual(delta_minus_5_42, util.timezone(delta_minus_5_42).utcoffset(None))
122 self.assertTrue(util.timezone(delta_minus_5_42).dst(None) in set((timedelta(0), None)))
125 …self.assertTrue(util.create_timezone(delta_plus_5_42) is util.create_timezone(timedelta(hours=5, m…
126 … self.assertFalse(util.create_timezone(delta_plus_5_42) is util.create_timezone(delta_minus_5_42))
129 self.assertEqual('UTC', util.utc_with_dst.tzname(None))
132 self.assertEqual('0000-01-01', util.extended_date(0, 1, 1).strftime('%Y-%m-%d'))
133 … self.assertEqual('Sat Saturday Jan January', util.extended_date(0, 1, 1).strftime('%a %A %b %B'))
134 …self.assertEqual('Tue Tuesday Feb February 29', util.extended_date(0, 2, 29).strftime('%a %A %b %B…
136 self.assertEqual('01/01/00 00:00:00', util.extended_date(0, 1, 1).strftime('%c'))
138 self.assertEqual('Sat Jan 1 00:00:00 0000', util.extended_date(0, 1, 1).strftime('%c'))
139 self.assertEqual('01/01/00', util.extended_date(0, 1, 1).strftime('%x'))
143 util.extended_datetime(2000, 11, 27)
147 util.extended_date(2000, 11, 27)
150 zone = util.create_timezone(timedelta(hours=12, minutes=45))
151 dt = util.extended_datetime(0, 11, 27, 5, 44, 31, 14889, zone)
162 ext_date = util.extended_date(0, 11, 27)
168 self.assertEqual('0000-01-01T00:00:00', util.extended_datetime(0, 1, 1).isoformat())
169 …self.assertEqual('0000-01-01T00:00:00.001000', util.extended_datetime(0, 1, 1, microsecond=1000).i…
170 self.assertEqual('0000-01-01%00:00:00', util.extended_datetime(0, 1, 1).isoformat(sep='%'))
173 self.assertEqual('0000-01-01', util.extended_date(0, 1, 1).isoformat())
174 self.assertEqual('0000-11-27', util.extended_date(0, 11, 27).isoformat())
177 …self.assertEqual('0000-01-01 00:00:00', util.extended_datetime(0, 1, 1).strftime('%Y-%m-%d %H:%M:%…
178 …self.assertEqual('Sat Saturday Jan January', util.extended_datetime(0, 1, 1).strftime('%a %A %b %B…
179 …self.assertEqual('Tue Tuesday Feb February 29', util.extended_datetime(0, 2, 29).strftime('%a %A %…
181 self.assertEqual('01/01/00 00:00:00', util.extended_datetime(0, 1, 1).strftime('%c'))
183 … self.assertEqual('Sat Jan 1 00:00:00 0000', util.extended_datetime(0, 1, 1).strftime('%c'))
184 self.assertEqual('01/01/00', util.extended_datetime(0, 1, 1).strftime('%x'))
185 self.assertEqual('%Y', util.extended_datetime(0, 1, 1).strftime('%%Y'))
188 zone = util.create_timezone(timedelta(hours=12, minutes=45))
189 ext_dt = util.extended_datetime(0, 1, 1, 23, tzinfo=zone)
191 … self.assertEqual(ext_dt.replace(minute=59), util.extended_datetime(0, 1, 1, 23, 59, tzinfo=zone))
194 ext_date = util.extended_date(0, 2, 27)
196 self.assertEqual(ext_date.replace(day=29), util.extended_date(0, 2, 29))
201 zone = util.create_timezone(timedelta(hours=12, minutes=45))
204 ext_dt = util.extended_datetime(0, 2, 29, 9, 17, 45, 14889, zone)
210 ext_dt = util.extended_datetime(0, 2, 29, 9, 17, 45, 0, zone)
216 ext_date = util.extended_date(0, 2, 29)
223 zone = util.create_timezone(timedelta(hours=12, minutes=45))
224 ext_dt = util.extended_datetime(0, 12, 31, 23, 0, 0, 14889, zone)
229 self.assertTrue(util.extended_date(0, 1, 1) < date(1, 1, 1))
230 self.assertTrue(util.extended_date(0, 1, 1) <= date(1, 1, 1))
231 self.assertTrue(util.extended_date(0, 1, 1) != date(1, 1, 1))
232 self.assertFalse(util.extended_date(0, 1, 1) == date(1, 1, 1))
233 self.assertFalse(util.extended_date(0, 1, 1) >= date(1, 1, 1))
234 self.assertFalse(util.extended_date(0, 1, 1) > date(1, 1, 1))
236 self.assertFalse(util.extended_date(0, 1, 1) < util.extended_date(0, 1, 1))
237 self.assertTrue(util.extended_date(0, 1, 1) <= util.extended_date(0, 1, 1))
238 self.assertFalse(util.extended_date(0, 1, 1) != util.extended_date(0, 1, 1))
239 self.assertTrue(util.extended_date(0, 1, 1) == util.extended_date(0, 1, 1))
240 self.assertTrue(util.extended_date(0, 1, 1) >= util.extended_date(0, 1, 1))
241 self.assertFalse(util.extended_date(0, 1, 1) > util.extended_date(0, 1, 1))
243 self.assertTrue(util.extended_date(0, 1, 1) < util.extended_date(0, 1, 2))
244 self.assertTrue(util.extended_date(0, 1, 1) <= util.extended_date(0, 1, 2))
245 self.assertTrue(util.extended_date(0, 1, 1) != util.extended_date(0, 1, 2))
246 self.assertFalse(util.extended_date(0, 1, 1) == util.extended_date(0, 1, 2))
247 self.assertFalse(util.extended_date(0, 1, 1) >= util.extended_date(0, 1, 2))
248 self.assertFalse(util.extended_date(0, 1, 1) > util.extended_date(0, 1, 2))
250 self.assertFalse(util.extended_date(0, 1, 3) < util.extended_date(0, 1, 2))
251 self.assertFalse(util.extended_date(0, 1, 3) <= util.extended_date(0, 1, 2))
252 self.assertTrue(util.extended_date(0, 1, 3) != util.extended_date(0, 1, 2))
253 self.assertFalse(util.extended_date(0, 1, 3) == util.extended_date(0, 1, 2))
254 self.assertTrue(util.extended_date(0, 1, 3) >= util.extended_date(0, 1, 2))
255 self.assertTrue(util.extended_date(0, 1, 3) > util.extended_date(0, 1, 2))
258 util.extended_date(0, 1, 1) < "0000-01-02"
261 self.assertTrue(util.extended_datetime(0, 1, 1) < datetime(1, 1, 1))
262 self.assertTrue(util.extended_datetime(0, 1, 1) <= datetime(1, 1, 1))
263 self.assertTrue(util.extended_datetime(0, 1, 1) != datetime(1, 1, 1))
264 self.assertFalse(util.extended_datetime(0, 1, 1) == datetime(1, 1, 1))
265 self.assertFalse(util.extended_datetime(0, 1, 1) >= datetime(1, 1, 1))
266 self.assertFalse(util.extended_datetime(0, 1, 1) > datetime(1, 1, 1))
268 self.assertFalse(util.extended_datetime(0, 1, 1) < util.extended_datetime(0, 1, 1))
269 self.assertTrue(util.extended_datetime(0, 1, 1) <= util.extended_datetime(0, 1, 1))
270 self.assertFalse(util.extended_datetime(0, 1, 1) != util.extended_datetime(0, 1, 1))
271 self.assertTrue(util.extended_datetime(0, 1, 1) == util.extended_datetime(0, 1, 1))
272 self.assertTrue(util.extended_datetime(0, 1, 1) >= util.extended_datetime(0, 1, 1))
273 self.assertFalse(util.extended_datetime(0, 1, 1) > util.extended_datetime(0, 1, 1))
275 self.assertTrue(util.extended_datetime(0, 1, 1) < util.extended_datetime(0, 1, 2))
276 self.assertTrue(util.extended_datetime(0, 1, 1) <= util.extended_datetime(0, 1, 2))
277 self.assertTrue(util.extended_datetime(0, 1, 1) != util.extended_datetime(0, 1, 2))
278 self.assertFalse(util.extended_datetime(0, 1, 1) == util.extended_datetime(0, 1, 2))
279 self.assertFalse(util.extended_datetime(0, 1, 1) >= util.extended_datetime(0, 1, 2))
280 self.assertFalse(util.extended_datetime(0, 1, 1) > util.extended_datetime(0, 1, 2))
282 self.assertFalse(util.extended_datetime(0, 1, 3) < util.extended_datetime(0, 1, 2))
283 self.assertFalse(util.extended_datetime(0, 1, 3) <= util.extended_datetime(0, 1, 2))
284 self.assertTrue(util.extended_datetime(0, 1, 3) != util.extended_datetime(0, 1, 2))
285 self.assertFalse(util.extended_datetime(0, 1, 3) == util.extended_datetime(0, 1, 2))
286 self.assertTrue(util.extended_datetime(0, 1, 3) >= util.extended_datetime(0, 1, 2))
287 self.assertTrue(util.extended_datetime(0, 1, 3) > util.extended_datetime(0, 1, 2))
289util.extended_datetime(0, 12, 31, 21, 4, 5, 6, util.create_timezone(timedelta(hours=-8)))
293util.extended_datetime(0, 12, 31, 21, 4, 5, 6, util.create_timezone(timedelta(hours=-8)))
294 == datetime(1, 1, 1, 5, 7, 5, 6, util.create_timezone(timedelta(hours=0, minutes=3)))
297util.extended_datetime(0, 12, 31, 21, 4, 5, 6, util.create_timezone(timedelta(hours=-7)))
300 … self.assertFalse(util.extended_datetime(0, 1, 1) == util.extended_datetime(0, 1, 1, tzinfo=utc))
301 self.assertFalse(util.extended_datetime(0, 1, 1) == "0000-01-01")
304 util.extended_datetime(0, 1, 1) < "0000-01-02"
307 zone = util.create_timezone(timedelta(hours=12, minutes=45))
308 ext_dt = util.extended_datetime(0, 12, 31, 9, 17, 45, 14889, zone)
310 …self.assertEqual(ext_dt - timedelta(hours=20), util.extended_datetime(0, 12, 30, 13, 17, 45, 14889…
313 zone2 = util.create_timezone(timedelta(hours=-8, minutes=-31))
314 ext_dt2 = util.extended_datetime(0, 11, 14, 13, 44, 20, 876543, zone2)
320 self.assertEqual(dt - ext_dt, timedelta(days=util.extended_datetime.DAYS_IN_400_YEARS))
321 self.assertEqual(ext_dt - dt, -timedelta(days=util.extended_datetime.DAYS_IN_400_YEARS))
328 self.assertTrue(util.extended_datetime(0, 1, 1, tzinfo=utc) < datetime(1, 1, 1))
330 self.assertTrue(util.extended_datetime(0, 1, 1) < datetime(1, 1, 1, tzinfo=utc))
333 self.assertEqual(util.extended_date(0, 1, 1), util.extended_datetime(0, 1, 1).date())
334 self.assertEqual(util.extended_date(0, 2, 29), util.extended_datetime(0, 2, 29).date())
335 self.assertEqual(time(0, 0, 0), util.extended_datetime(0, 1, 1).time())
341 util.iri_to_uri(
349 util.iri_to_uri(
357 util.iri_to_uri(