Skip to content

Commit

Permalink
Merge pull request #376 from WhyNotHugo/py38
Browse files Browse the repository at this point in the history
Remove any syntax required for python < 3.8
  • Loading branch information
niccokunzmann authored Aug 19, 2022
2 parents ae7d35c + d81af0a commit de7a96a
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 115 deletions.
9 changes: 4 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# icalendar documentation build configuration file
import pkg_resources
import datetime
Expand Down Expand Up @@ -26,9 +25,9 @@
source_suffix = '.rst'
master_doc = 'index'

project = u'icalendar'
project = 'icalendar'
this_year = datetime.date.today().year
copyright = u'{}, Plone Foundation'.format(this_year)
copyright = f'{this_year}, Plone Foundation'
version = pkg_resources.get_distribution('icalendar').version
release = version

Expand All @@ -38,6 +37,6 @@
htmlhelp_basename = 'icalendardoc'

man_pages = [
('index', 'icalendar', u'icalendar Documentation',
[u'Plone Foundation'], 1)
('index', 'icalendar', 'icalendar Documentation',
['Plone Foundation'], 1)
]
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import codecs
import setuptools
import re
Expand Down
1 change: 0 additions & 1 deletion src/icalendar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '5.0.0a2.dev0'

from icalendar.cal import (
Expand Down
19 changes: 9 additions & 10 deletions src/icalendar/cal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Calendar is a dictionary like Python object that can render itself as VCAL
files according to rfc2445.
Expand Down Expand Up @@ -34,7 +33,7 @@ class ComponentFactory(CaselessDict):
def __init__(self, *args, **kwargs):
"""Set keys to upper for initial dict.
"""
super(ComponentFactory, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self['VEVENT'] = Event
self['VTODO'] = Todo
self['VJOURNAL'] = Journal
Expand Down Expand Up @@ -79,7 +78,7 @@ class Component(CaselessDict):
def __init__(self, *args, **kwargs):
"""Set keys to upper for initial dict.
"""
super(Component, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# set parameters here for properties that use non-default values
self.subcomponents = [] # Components can be nested.
self.errors = [] # If we ignored exception(s) while
Expand Down Expand Up @@ -393,12 +392,12 @@ def from_ical(cls, st, multiple=False):
if multiple:
return comps
if len(comps) > 1:
raise ValueError('Found multiple components where '
'only one is allowed: {st!r}'.format(**locals()))
raise ValueError(f'Found multiple components where '
f'only one is allowed: {st!r}')
if len(comps) < 1:
raise ValueError('Found no components where '
'exactly one is required: '
'{st!r}'.format(**locals()))
raise ValueError(f'Found no components where '
f'exactly one is required: '
f'{st!r}')
return comps[0]

def content_line(self, name, value, sorted=True):
Expand Down Expand Up @@ -430,7 +429,7 @@ def __repr__(self):
"""String representation of class with all of it's subcomponents.
"""
subs = ', '.join([str(it) for it in self.subcomponents])
return '%s(%s%s)' % (
return '{}({}{})'.format(
self.name or type(self).__name__,
dict(self),
', %s' % subs if subs else ''
Expand Down Expand Up @@ -607,7 +606,7 @@ def to_tz(self):
tzname = component['TZNAME'].encode('ascii', 'replace')
tzname = self._make_unique_tzname(tzname, tznames)
except KeyError:
tzname = '{0}_{1}_{2}_{3}'.format(
tzname = '{}_{}_{}_{}'.format(
zone,
component['DTSTART'].to_ical().decode('utf-8'),
component['TZOFFSETFROM'].to_ical(), # for whatever reason this is str/unicode
Expand Down
27 changes: 13 additions & 14 deletions src/icalendar/caselessdict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from icalendar.compat import iteritems
from icalendar.parser_tools import to_unicode

Expand Down Expand Up @@ -30,47 +29,47 @@ class CaselessDict(OrderedDict):
def __init__(self, *args, **kwargs):
"""Set keys to upper for initial dict.
"""
super(CaselessDict, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for key, value in self.items():
key_upper = to_unicode(key).upper()
if key != key_upper:
super(CaselessDict, self).__delitem__(key)
super().__delitem__(key)
self[key_upper] = value

def __getitem__(self, key):
key = to_unicode(key)
return super(CaselessDict, self).__getitem__(key.upper())
return super().__getitem__(key.upper())

def __setitem__(self, key, value):
key = to_unicode(key)
super(CaselessDict, self).__setitem__(key.upper(), value)
super().__setitem__(key.upper(), value)

def __delitem__(self, key):
key = to_unicode(key)
super(CaselessDict, self).__delitem__(key.upper())
super().__delitem__(key.upper())

def __contains__(self, key):
key = to_unicode(key)
return super(CaselessDict, self).__contains__(key.upper())
return super().__contains__(key.upper())

def get(self, key, default=None):
key = to_unicode(key)
return super(CaselessDict, self).get(key.upper(), default)
return super().get(key.upper(), default)

def setdefault(self, key, value=None):
key = to_unicode(key)
return super(CaselessDict, self).setdefault(key.upper(), value)
return super().setdefault(key.upper(), value)

def pop(self, key, default=None):
key = to_unicode(key)
return super(CaselessDict, self).pop(key.upper(), default)
return super().pop(key.upper(), default)

def popitem(self):
return super(CaselessDict, self).popitem()
return super().popitem()

def has_key(self, key):
key = to_unicode(key)
return super(CaselessDict, self).__contains__(key.upper())
return super().__contains__(key.upper())

def update(self, *args, **kwargs):
# Multiple keys where key1.upper() == key2.upper() will be lost.
Expand All @@ -82,10 +81,10 @@ def update(self, *args, **kwargs):
self[key] = value

def copy(self):
return type(self)(super(CaselessDict, self).copy())
return type(self)(super().copy())

def __repr__(self):
return '%s(%s)' % (type(self).__name__, dict(self))
return f'{type(self).__name__}({dict(self)})'

def __eq__(self, other):
return self is other or dict(self.items()) == dict(other.items())
Expand Down
4 changes: 1 addition & 3 deletions src/icalendar/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
"""iCalendar utility"""
from __future__ import unicode_literals

import argparse
import sys
Expand Down Expand Up @@ -81,7 +79,7 @@ def main():
description=__doc__)
parser.add_argument(
'-v', '--version', action='version',
version='{} version {}'.format(parser.prog, __version__))
version=f'{parser.prog} version {__version__}')

# This seems a bit of an overkill now, but we will probably add more
# functionality later, e.g., iCalendar to JSON / YAML and vice versa.
Expand Down
1 change: 0 additions & 1 deletion src/icalendar/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys


Expand Down
8 changes: 3 additions & 5 deletions src/icalendar/parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
"""This module parses and generates contentlines as defined in RFC 2445
(iCalendar), but will probably work for other MIME types with similar syntax.
Eg. RFC 2426 (vCard)
It is stupid in the sense that it treats the content purely as strings. No type
conversion is attempted.
"""
from __future__ import unicode_literals

from icalendar import compat
from icalendar.caselessdict import CaselessDict
Expand Down Expand Up @@ -293,7 +291,7 @@ def __new__(cls, value, strict=False, encoding=DEFAULT_ENCODING):
value = to_unicode(value, encoding=encoding)
assert '\n' not in value, ('Content line can not contain unescaped '
'new line characters.')
self = super(Contentline, cls).__new__(cls, value)
self = super().__new__(cls, value)
self.strict = strict
return self

Expand All @@ -315,8 +313,8 @@ def from_parts(cls, name, params, values, sorted=True):
values = to_unicode(values)
if params:
params = to_unicode(params.to_ical(sorted=sorted))
return cls('%s;%s:%s' % (name, params, values))
return cls('%s:%s' % (name, values))
return cls(f'{name};{params}:{values}')
return cls(f'{name}:{values}')

def parts(self):
"""Split the content line up into (name, parameters, values) parts.
Expand Down
1 change: 0 additions & 1 deletion src/icalendar/parser_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from icalendar import compat


Expand Down
Loading

0 comments on commit de7a96a

Please sign in to comment.