コード例 #1
0
ファイル: tools.py プロジェクト: TheBHump/ATXFindABlank
 def uid(self, host_name='example.com', unique=''):
     """Generates a unique id consisting of:
         datetime-uniquevalue@host.
     Like:
         [email protected]
     """
     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))
コード例 #2
0
ファイル: tools.py プロジェクト: 4bic/open_county
 def uid(self, host_name='example.com', unique=''):
     """Generates a unique id consisting of:
         datetime-uniquevalue@host.
     Like:
         [email protected]
     """
     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))
コード例 #3
0
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vFrequency, cls).__new__(cls, value)
     if not self in vFrequency.frequencies:
         raise ValueError('Expected frequency, got: %s' % self)
     self.params = Parameters()
     return self
コード例 #4
0
 def __new__(cls, value, strict=False, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     assert u'\n' not in value, ('Content line can not contain unescaped '
                                 'new line characters.')
     self = super(Contentline, cls).__new__(cls, value)
     self.strict = strict
     return self
コード例 #5
0
ファイル: prop.py プロジェクト: brysmi/icalendar
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vFrequency, cls).__new__(cls, value)
     if not self in vFrequency.frequencies:
         raise ValueError('Expected frequency, got: %s' % self)
     self.params = Parameters()
     return self
コード例 #6
0
    def test_issue_112(self):
        """Issue #112 - No timezone info on EXDATE
        https://github.com/collective/icalendar/issues/112
        """
        directory = os.path.dirname(__file__)
        path = os.path.join(directory,
                            'issue_112_missing_tzinfo_on_exdate.ics')
        with open(path, 'rb') as ics:
            cal = icalendar.Calendar.from_ical(ics.read())
            event = cal.walk('VEVENT')[0]

            event_ical = to_unicode(event.to_ical())  # Py3 str type doesn't
                                                      # support buffer API
            # General timezone aware dates in ical string
            self.assertTrue('DTSTART;TZID=America/New_York:20130907T120000'
                            in event_ical)
            self.assertTrue('DTEND;TZID=America/New_York:20130907T170000'
                            in event_ical)
            # Specific timezone aware exdates in ical string
            self.assertTrue('EXDATE;TZID=America/New_York:20131012T120000'
                            in event_ical)
            self.assertTrue('EXDATE;TZID=America/New_York:20131011T120000'
                            in event_ical)

            self.assertEqual(event['exdate'][0].dts[0].dt.tzname(), 'EDT')
コード例 #7
0
ファイル: test_fixed_issues.py プロジェクト: 4bic/open_county
    def test_issue_112(self):
        """Issue #112 - No timezone info on EXDATE
        https://github.com/collective/icalendar/issues/112
        """
        directory = os.path.dirname(__file__)
        path = os.path.join(directory,
                            'issue_112_missing_tzinfo_on_exdate.ics')
        with open(path, 'rb') as ics:
            cal = icalendar.Calendar.from_ical(ics.read())
            event = cal.walk('VEVENT')[0]

            event_ical = to_unicode(event.to_ical())  # Py3 str type doesn't
                                                      # support buffer API
            # General timezone aware dates in ical string
            self.assertTrue('DTSTART;TZID=America/New_York:20130907T120000'
                            in event_ical)
            self.assertTrue('DTEND;TZID=America/New_York:20130907T170000'
                            in event_ical)
            # Specific timezone aware exdates in ical string
            self.assertTrue('EXDATE;TZID=America/New_York:20131012T120000'
                            in event_ical)
            self.assertTrue('EXDATE;TZID=America/New_York:20131011T120000'
                            in event_ical)

            self.assertEqual(event['exdate'][0].dts[0].dt.tzname(), 'EDT')
コード例 #8
0
    def test_parser_tools_to_unicode(self):

        self.assertEqual(to_unicode(b'spam'), 'spam')
        self.assertEqual(to_unicode('spam'), 'spam')
        self.assertEqual(to_unicode('spam'.encode('utf-8')), 'spam')
        self.assertEqual(to_unicode(b'\xc6\xb5'), '\u01b5')
        self.assertEqual(to_unicode('\xc6\xb5'.encode('iso-8859-1')), '\u01b5')
        self.assertEqual(to_unicode(b'\xc6\xb5', encoding='ascii'), '\u01b5')
        self.assertEqual(to_unicode(1), 1)
        self.assertEqual(to_unicode(None), None)
コード例 #9
0
 def __init__(self, *args, **kwargs):
     """Set keys to upper for initial dict.
     """
     super(CaselessDict, self).__init__(*args, **kwargs)
     for key, value in self.items():
         key_upper = to_unicode(key).upper()
         if key != key_upper:
             super(CaselessDict, self).__delitem__(key)
             self[key_upper] = value
コード例 #10
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def __init__(self, *args, **kwargs):
     """Set keys to upper for initial dict.
     """
     super(CaselessDict, self).__init__(*args, **kwargs)
     for key, value in self.items():
         key_upper = to_unicode(key).upper()
         if key != key_upper:
             super(CaselessDict, self).__delitem__(key)
             self[key_upper] = value
コード例 #11
0
    def test_parser_tools_to_unicode(self):

        self.assertEqual(to_unicode(b'spam'), 'spam')
        self.assertEqual(to_unicode('spam'), 'spam')
        self.assertEqual(to_unicode('spam'.encode('utf-8')), 'spam')
        self.assertEqual(to_unicode(b'\xc6\xb5'), '\u01b5')
        self.assertEqual(to_unicode('\xc6\xb5'.encode('iso-8859-1')),
                         '\u01b5')
        self.assertEqual(to_unicode(b'\xc6\xb5', encoding='ascii'), '\u01b5')
        self.assertEqual(to_unicode(1), 1)
        self.assertEqual(to_unicode(None), None)
コード例 #12
0
    def from_parts(cls, name, params, values, sorted=True):
        """Turn a parts into a content line.
        """
        assert isinstance(params, Parameters)
        if hasattr(values, 'to_ical'):
            values = values.to_ical()
        else:
            values = vText(values).to_ical()
        # elif isinstance(values, basestring):
        #    values = escape_char(values)

        # TODO: after unicode only, remove this
        # Convert back to unicode, after to_ical encoded it.
        name = to_unicode(name)
        values = to_unicode(values)
        if params:
            params = to_unicode(params.to_ical(sorted=sorted))
            return cls(u'%s;%s:%s' % (name, params, values))
        return cls(u'%s:%s' % (name, values))
コード例 #13
0
 def from_ical(cls, st):
     """Parses a string into content lines.
     """
     st = to_unicode(st)
     try:
         # a fold is carriage return followed by either a space or a tab
         unfolded = uFOLD.sub('', st)
         lines = cls(Contentline(line) for
                     line in unfolded.splitlines() if line)
         lines.append('')  # '\r\n' at the end of every content line
         return lines
     except:
         raise ValueError('Expected StringType with content lines')
コード例 #14
0
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vWeekday, cls).__new__(cls, value)
     match = WEEKDAY_RULE.match(self)
     if match is None:
         raise ValueError('Expected weekday abbrevation, got: %s' % self)
     match = match.groupdict()
     sign = match['signal']
     weekday = match['weekday']
     relative = match['relative']
     if not weekday in vWeekday.week_days or sign not in '+-':
         raise ValueError('Expected weekday abbrevation, got: %s' % self)
     self.relative = relative and int(relative) or None
     self.params = Parameters()
     return self
コード例 #15
0
ファイル: prop.py プロジェクト: brysmi/icalendar
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vWeekday, cls).__new__(cls, value)
     match = WEEKDAY_RULE.match(self)
     if match is None:
         raise ValueError('Expected weekday abbrevation, got: %s' % self)
     match = match.groupdict()
     sign = match['signal']
     weekday = match['weekday']
     relative = match['relative']
     if not weekday in vWeekday.week_days or sign not in '+-':
         raise ValueError('Expected weekday abbrevation, got: %s' % self)
     self.relative = relative and int(relative) or None
     self.params = Parameters()
     return self
コード例 #16
0
 def pop(self, key, default=None):
     key = to_unicode(key)
     return super(CaselessDict, self).pop(key.upper(), default)
コード例 #17
0
 def pop(self, key, default=None):
     key = to_unicode(key)
     return dict.pop(self, key.upper(), default)
コード例 #18
0
 def setdefault(self, key, value=None):
     key = to_unicode(key)
     return super(CaselessDict, self).setdefault(key.upper(), value)
コード例 #19
0
ファイル: prop.py プロジェクト: brysmi/icalendar
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vInline, cls).__new__(cls, value)
     self.params = Parameters()
     return self
コード例 #20
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def __getitem__(self, key):
     key = to_unicode(key)
     return dict.__getitem__(self, key.upper())
コード例 #21
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def has_key(self, key):
     key = to_unicode(key)
     return super(CaselessDict, self).__contains__(key.upper())
コード例 #22
0
 def setdefault(self, key, value=None):
     key = to_unicode(key)
     return dict.setdefault(self, key.upper(), value)
コード例 #23
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def __setitem__(self, key, value):
     key = to_unicode(key)
     super(CaselessDict, self).__setitem__(key.upper(), value)
コード例 #24
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def pop(self, key, default=None):
     key = to_unicode(key)
     return dict.pop(self, key.upper(), default)
コード例 #25
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def has_key(self, key):
     key = to_unicode(key)
     return dict.__contains__(self, key.upper())
コード例 #26
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def setdefault(self, key, value=None):
     key = to_unicode(key)
     return dict.setdefault(self, key.upper(), value)
コード例 #27
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def __delitem__(self, key):
     key = to_unicode(key)
     dict.__delitem__(self, key.upper())
コード例 #28
0
ファイル: caselessdict.py プロジェクト: affinitic/icalendar
 def __setitem__(self, key, value):
     key = to_unicode(key)
     dict.__setitem__(self, key.upper(), value)
コード例 #29
0
 def from_ical(cls, ical, strict=False):
     """Unfold the content lines in an iCalendar into long content lines.
     """
     ical = to_unicode(ical)
     # a fold is carriage return followed by either a space or a tab
     return cls(uFOLD.sub('', ical), strict=strict)
コード例 #30
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def setdefault(self, key, value=None):
     key = to_unicode(key)
     return super(CaselessDict, self).setdefault(key.upper(), value)
コード例 #31
0
 def __setitem__(self, key, value):
     key = to_unicode(key)
     super(CaselessDict, self).__setitem__(key.upper(), value)
コード例 #32
0
 def has_key(self, key):
     key = to_unicode(key)
     return super(CaselessDict, self).__contains__(key.upper())
コード例 #33
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def __getitem__(self, key):
     key = to_unicode(key)
     return super(CaselessDict, self).__getitem__(key.upper())
コード例 #34
0
 def __setitem__(self, key, value):
     key = to_unicode(key)
     dict.__setitem__(self, key.upper(), value)
コード例 #35
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def __delitem__(self, key):
     key = to_unicode(key)
     super(CaselessDict, self).__delitem__(key.upper())
コード例 #36
0
 def __init__(self, obj):
     self.obj = to_unicode(obj)
     self.params = Parameters(encoding='BASE64', value="BINARY")
コード例 #37
0
ファイル: caselessdict.py プロジェクト: WilliamMayor/workleft
 def pop(self, key, default=None):
     key = to_unicode(key)
     return super(CaselessDict, self).pop(key.upper(), default)
コード例 #38
0
 def __getitem__(self, key):
     key = to_unicode(key)
     return super(CaselessDict, self).__getitem__(key.upper())
コード例 #39
0
ファイル: prop.py プロジェクト: brysmi/icalendar
 def __init__(self, obj):
     self.obj = to_unicode(obj)
     self.params = Parameters(encoding='BASE64', value="BINARY")
コード例 #40
0
 def __new__(cls, value, encoding=DEFAULT_ENCODING):
     value = to_unicode(value, encoding=encoding)
     self = super(vInline, cls).__new__(cls, value)
     self.params = Parameters()
     return self
コード例 #41
0
 def __delitem__(self, key):
     key = to_unicode(key)
     dict.__delitem__(self, key.upper())
コード例 #42
0
 def has_key(self, key):
     key = to_unicode(key)
     return dict.__contains__(self, key.upper())
コード例 #43
0
 def __getitem__(self, key):
     key = to_unicode(key)
     return dict.__getitem__(self, key.upper())
コード例 #44
0
 def __delitem__(self, key):
     key = to_unicode(key)
     super(CaselessDict, self).__delitem__(key.upper())