kopia lustrzana https://github.com/collective/icalendar
commit
f6f3a2e09a
|
@ -5,7 +5,11 @@ Changelog
|
|||
5.0.0a2 (unreleased)
|
||||
--------------------
|
||||
|
||||
- Nothing changed yet.
|
||||
Bug fixes:
|
||||
|
||||
- Changed tools.UIDGenerator instance methods to static methods
|
||||
Ref: #345
|
||||
[spralja]
|
||||
|
||||
|
||||
5.0.0a1 (2022-07-11)
|
||||
|
|
|
@ -57,6 +57,8 @@ icalendar contributors
|
|||
- Dalton Durst <github@daltondur.st>
|
||||
- Kamil Mańkowski <kam193@wp.pl>
|
||||
- `Nicco Kunzmann <https://github.com/niccokunzmann>`_
|
||||
- Robert Spralja <robert.spralja@gmail.com>
|
||||
- Maurits van Rees <maurits@vanrees.org>
|
||||
|
||||
Find out who contributed::
|
||||
|
||||
|
|
|
@ -478,3 +478,16 @@ END:VCALENDAR"""
|
|||
expected_tzname = 'Brasília standard'.encode('ascii', 'replace')
|
||||
self.assertEqual(dtstart.tzinfo.zone, expected_zone)
|
||||
self.assertEqual(dtstart.tzname(), expected_tzname)
|
||||
|
||||
def test_issue_345(self):
|
||||
"""Issue #345 - Why is tools.UIDGenerator a class (that must be instantiated) instead of a module? """
|
||||
uid1 = icalendar.tools.UIDGenerator.uid()
|
||||
uid2 = icalendar.tools.UIDGenerator.uid('test.test')
|
||||
uid3 = icalendar.tools.UIDGenerator.uid(unique='123')
|
||||
uid4 = icalendar.tools.UIDGenerator.uid('test.test', '123')
|
||||
|
||||
self.assertEqual(uid1.split('@')[1], 'example.com')
|
||||
self.assertEqual(uid2.split('@')[1], 'test.test')
|
||||
self.assertEqual(uid3.split('-')[1], '123@example.com')
|
||||
self.assertEqual(uid4.split('-')[1], '123@test.test')
|
||||
|
||||
|
|
|
@ -15,19 +15,21 @@ class UIDGenerator(object):
|
|||
"""
|
||||
chars = list(ascii_letters + digits)
|
||||
|
||||
def rnd_string(self, length=16):
|
||||
@staticmethod
|
||||
def rnd_string(length=16):
|
||||
"""Generates a string with random characters of length.
|
||||
"""
|
||||
return ''.join([random.choice(self.chars) for _ in range(length)])
|
||||
return ''.join([random.choice(UIDGenerator.chars) for _ in range(length)])
|
||||
|
||||
def uid(self, host_name='example.com', unique=''):
|
||||
@staticmethod
|
||||
def uid(host_name='example.com', unique=''):
|
||||
"""Generates a unique id consisting of:
|
||||
datetime-uniquevalue@host.
|
||||
Like:
|
||||
20050105T225746Z-HKtJMqUgdO0jDUwm@example.com
|
||||
"""
|
||||
host_name = to_unicode(host_name)
|
||||
unique = unique or self.rnd_string()
|
||||
unique = unique or UIDGenerator.rnd_string()
|
||||
today = to_unicode(vDatetime(datetime.today()).to_ical())
|
||||
return vText('%s-%s@%s' % (today,
|
||||
unique,
|
||||
|
|
Ładowanie…
Reference in New Issue