/usr/lib/python2.7/dist-packages/icalendar/tools.py is in python-icalendar 3.6.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from datetime import datetime
from icalendar.parser_tools import to_unicode
from icalendar.prop import vDatetime
from icalendar.prop import vText
from string import ascii_letters
from string import digits
import random
class UIDGenerator(object):
"""If you are too lazy to create real uid's.
"""
chars = list(ascii_letters + digits)
def rnd_string(self, length=16):
"""Generates a string with random characters of length.
"""
return ''.join([random.choice(self.chars) for _ in range(length)])
def uid(self, 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()
today = to_unicode(vDatetime(datetime.today()).to_ical())
return vText('%s-%s@%s' % (today,
unique,
host_name))
|