Skip to content

Commit

Permalink
chore: black
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 15, 2023
1 parent 894078e commit dfc81ff
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 176 deletions.
2 changes: 1 addition & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
2 changes: 1 addition & 1 deletion plone/event/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EventAccessor:
"""

def __init__(self, context):
object.__setattr__(self, 'context', context)
object.__setattr__(self, "context", context)

def __getattr__(self, name):
return getattr(self.context, name)
Expand Down
143 changes: 69 additions & 74 deletions plone/event/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@


class IEvent(Interface):
"""Event type marker interface.
"""
"""Event type marker interface."""


class IEventRecurrence(Interface):
Expand All @@ -20,8 +18,9 @@ class IOccurrence(Interface):
occurrence.
"""
start = Attribute('Occurrence start date')
end = Attribute('Occurrence end date')

start = Attribute("Occurrence start date")
end = Attribute("Occurrence end date")


class ICalendarAccessor(Interface):
Expand All @@ -30,16 +29,15 @@ class ICalendarAccessor(Interface):
A calendar is a collection of calendar components, like events.
"""
uid = Attribute('UID of the calendar. Autogenerated, read only.')

uid = Attribute("UID of the calendar. Autogenerated, read only.")
# rw attributes
title = Attribute('Calendar title.')
description = Attribute('Calendar description text.')
timezone = Attribute('Default timezone of the calendar.')
title = Attribute("Calendar title.")
description = Attribute("Calendar description text.")
timezone = Attribute("Default timezone of the calendar.")

def items(self):
"""Return a list of calendar component items, like events.
"""
"""Return a list of calendar component items, like events."""


class IEventAccessor(Interface):
Expand All @@ -51,40 +49,38 @@ class IEventAccessor(Interface):
"""

# ro attributes
uid = Attribute('UID of the event. Autogenerated, read only.')
created = Attribute('Python datetime of the event creation timestamp.')
duration = Attribute('Duration of the event. Computed attribute.')
uid = Attribute("UID of the event. Autogenerated, read only.")
created = Attribute("Python datetime of the event creation timestamp.")
duration = Attribute("Duration of the event. Computed attribute.")

# reference
url = Attribute(
'Cannonical, unique url of the event. External events '
'are referenced by the origin url unless explicitly set.'
"Cannonical, unique url of the event. External events "
"are referenced by the origin url unless explicitly set."
)

# rw attributes
last_modified = Attribute('Last modified Python datetime.')
title = Attribute('Event title.')
description = Attribute('Event description text.')
start = Attribute('Event start date as Python datetime.')
end = Attribute('Event end date as Python datetime.')
whole_day = Attribute('Event lasts whole day.')
open_end = Attribute('Event has no defined end time.')
timezone = Attribute('Timezone of the event. A pytz timezone identifier.')
recurrence = Attribute('RFC5545 compatible recurrence definition.')
location = Attribute('Location of the event.')
attendees = Attribute('List of attendees.')
contact_name = Attribute('Contact name.')
contact_email = Attribute('Contact email.')
contact_phone = Attribute('Contact phone.')
event_url = Attribute('Website of the event.')
subjects = Attribute('Categories.')
text = Attribute('Body text of the event.')
last_modified = Attribute("Last modified Python datetime.")
title = Attribute("Event title.")
description = Attribute("Event description text.")
start = Attribute("Event start date as Python datetime.")
end = Attribute("Event end date as Python datetime.")
whole_day = Attribute("Event lasts whole day.")
open_end = Attribute("Event has no defined end time.")
timezone = Attribute("Timezone of the event. A pytz timezone identifier.")
recurrence = Attribute("RFC5545 compatible recurrence definition.")
location = Attribute("Location of the event.")
attendees = Attribute("List of attendees.")
contact_name = Attribute("Contact name.")
contact_email = Attribute("Contact email.")
contact_phone = Attribute("Contact phone.")
event_url = Attribute("Website of the event.")
subjects = Attribute("Categories.")
text = Attribute("Body text of the event.")


class IRecurrenceSupport(Interface):
"""Event type recurrence adatper.
"""
"""Event type recurrence adatper."""

def occurrences(self, range_start, range_end):
"""Return a list of IOccurrence objects with custom attributes of the
Expand All @@ -100,9 +96,7 @@ def occurrences(self, range_start, range_end):


class IICalendar(Interface):
"""Adapter, which is used to construct an icalendar object.
"""
"""Adapter, which is used to construct an icalendar object."""


class IICalendarEventComponent(Interface):
Expand Down Expand Up @@ -155,37 +149,38 @@ class / created / description / geo /
resources / rdate / x-prop / iana-prop
"""
dtstart = Attribute('Start Date/Time')
dtend = Attribute('End Date/Time')
duration = Attribute('Duration')
rrule = Attribute('Recurrence Rule')
description = Attribute('Description')
location = Attribute('Location')
summary = Attribute('Summary')
url = Attribute('Url')
attendee = Attribute('Attendee')
categories = Attribute('Categories')
contact = Attribute('Contact')

exdate = Attribute('Exdate')
rdate = Attribute('Rdate')

dtstamp = Attribute('Timestamp')
uid = Attribute('Unique identifier')
klass = Attribute('Class') # class
created = Attribute('Created')
geo = Attribute('Geo')
last_mod = Attribute('Last Modified') # last-mod
organizer = Attribute('Organizer')
priority = Attribute('Priority')
seq = Attribute('Seq')
status = Attribute('Status')
transp = Attribute('Transp')
recurid = Attribute('Recurid')
attach = Attribute('Attach')
comment = Attribute('Comment')
rstatus = Attribute('Rstatus')
related = Attribute('Related')
resources = Attribute('Resources')
x_prop = Attribute('X Prop') # x-prop
iana_prop = Attribute('Iana Prop') # iana-prop

dtstart = Attribute("Start Date/Time")
dtend = Attribute("End Date/Time")
duration = Attribute("Duration")
rrule = Attribute("Recurrence Rule")
description = Attribute("Description")
location = Attribute("Location")
summary = Attribute("Summary")
url = Attribute("Url")
attendee = Attribute("Attendee")
categories = Attribute("Categories")
contact = Attribute("Contact")

exdate = Attribute("Exdate")
rdate = Attribute("Rdate")

dtstamp = Attribute("Timestamp")
uid = Attribute("Unique identifier")
klass = Attribute("Class") # class
created = Attribute("Created")
geo = Attribute("Geo")
last_mod = Attribute("Last Modified") # last-mod
organizer = Attribute("Organizer")
priority = Attribute("Priority")
seq = Attribute("Seq")
status = Attribute("Status")
transp = Attribute("Transp")
recurid = Attribute("Recurid")
attach = Attribute("Attach")
comment = Attribute("Comment")
rstatus = Attribute("Rstatus")
related = Attribute("Related")
resources = Attribute("Resources")
x_prop = Attribute("X Prop") # x-prop
iana_prop = Attribute("Iana Prop") # iana-prop
38 changes: 19 additions & 19 deletions plone/event/recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@


def recurrence_sequence_ical(
start,
recrule=None,
from_=None,
until=None,
count=None,
duration=None,
start,
recrule=None,
from_=None,
until=None,
count=None,
duration=None,
):
"""Calculates a sequence of datetime objects from a recurrence rule
following the RFC2445 specification, using python-dateutil recurrence
Expand Down Expand Up @@ -67,7 +67,7 @@ def recurrence_sequence_ical(
_from = tzdel(from_)
_until = tzdel(until)
if duration:
assert (isinstance(duration, datetime.timedelta))
assert isinstance(duration, datetime.timedelta)
else:
duration = datetime.timedelta(0)

Expand All @@ -87,16 +87,16 @@ def recurrence_sequence_ical(
# time for UNTIL, RDATE and EXDATE.
t0 = start.time() # set initial time information.
# First, replace all times in the recurring rule with starttime
t0str = f'T{t0.hour:02d}{t0.minute:02d}{t0.second:02d}'
t0str = f"T{t0.hour:02d}{t0.minute:02d}{t0.second:02d}"
# Replace any times set to 000000 with start time, not all
# rrules are set by a specific broken widget. Don't waste time
# subbing if the start time is already 000000.
if t0str != 'T000000':
recrule = re.sub(r'T000000', t0str, recrule)
if t0str != "T000000":
recrule = re.sub(r"T000000", t0str, recrule)
# Then, replace incorrect until times with the end of the day
recrule = re.sub(
r'(UNTIL[^T]*[0-9]{8})T(000000)',
r'\1T235959',
r"(UNTIL[^T]*[0-9]{8})T(000000)",
r"\1T235959",
recrule,
)

Expand Down Expand Up @@ -140,13 +140,13 @@ def recurrence_sequence_ical(


def recurrence_sequence_timedelta(
start,
delta=None,
until=None,
count=None,
dst=DSTAUTO,
start,
delta=None,
until=None,
count=None,
dst=DSTAUTO,
):
""" Calculates a sequence of datetime objects from a timedelta integer,
"""Calculates a sequence of datetime objects from a timedelta integer,
which defines the minutes between each occurence.
:param start: datetime or DateTime instance of the date from which the
Expand Down Expand Up @@ -204,7 +204,7 @@ def recurrence_sequence_timedelta(


def recurrence_int_sequence(sequence):
""" Generates a sequence of integer representations from a sequence of
"""Generates a sequence of integer representations from a sequence of
dateime instances.
:param sequence: An iterable sequence of datetime instances.
Expand Down
18 changes: 10 additions & 8 deletions plone/event/tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ class MockObject:
class TestAdapters(unittest.TestCase):
def setUp(self):
import zope.component
context = xmlconfig.file('meta.zcml', zope.component)
xmlconfig.file('configure.zcml', zope.component, context=context)

context = xmlconfig.file("meta.zcml", zope.component)
xmlconfig.file("configure.zcml", zope.component, context=context)

import plone.event
xmlconfig.file('configure.zcml', plone.event, context=context)

xmlconfig.file("configure.zcml", plone.event, context=context)

def test_event_accessor(self):
obj = MockObject()
tz = pytz.timezone('Europe/Vienna')
tz = pytz.timezone("Europe/Vienna")
obj.start = datetime(2012, 12, 12, 10, 0, tzinfo=tz)
obj.end = datetime(2012, 12, 12, 12, 0, tzinfo=tz)
zope.interface.alsoProvides(obj, IEvent)
Expand All @@ -48,9 +50,9 @@ def test_event_accessor(self):
acc.something = True
self.assertTrue(acc.something == obj.something is True)
del acc.something
self.assertTrue(hasattr(acc, 'something') is False)
self.assertTrue(hasattr(obj, 'something') is False)
self.assertTrue(hasattr(acc, "something") is False)
self.assertTrue(hasattr(obj, "something") is False)

del acc.start
self.assertTrue(hasattr(acc, 'start') is False)
self.assertTrue(hasattr(obj, 'start') is False)
self.assertTrue(hasattr(acc, "start") is False)
self.assertTrue(hasattr(obj, "start") is False)
25 changes: 11 additions & 14 deletions plone/event/tests/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,33 @@

OPTIONFLAGS = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
DOCFILES = [
'recurrence.rst',
'recurrence_dateutil.rst',
'utils.rst',
"recurrence.rst",
"recurrence_dateutil.rst",
"utils.rst",
]
DOCMODS = [
"plone.event.utils",
]
DOCMODS = ['plone.event.utils', ]


def test_suite():
suite = unittest.TestSuite()
suite.addTests(
[
doctest.DocFileSuite(
os.path.join(os.path.dirname(__file__), '..', docfile),
os.path.join(os.path.dirname(__file__), "..", docfile),
module_relative=False,
optionflags=OPTIONFLAGS,
tearDown=tearDown
tearDown=tearDown,
)
for docfile in DOCFILES
]
)
suite.addTests(
[
doctest.DocTestSuite(
docmod, optionflags=OPTIONFLAGS
)
for docmod in DOCMODS
]
[doctest.DocTestSuite(docmod, optionflags=OPTIONFLAGS) for docmod in DOCMODS]
)
return suite


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
7 changes: 4 additions & 3 deletions plone/event/tests/test_recurrence_int_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@


class TestRecurrenceIntSequence(unittest.TestCase):
@mock.patch('plone.event.recurrence.dt2int')
@mock.patch("plone.event.recurrence.dt2int")
def test_recrule_str_(self, dt2int):
from plone.event.recurrence import recurrence_int_sequence

sequence = [1, 2, 3]
dt2int.return_value = 'a'
dt2int.return_value = "a"
res = [a for a in recurrence_int_sequence(sequence)]
self.assertEqual(res, ['a', 'a', 'a'])
self.assertEqual(res, ["a", "a", "a"])
Loading

0 comments on commit dfc81ff

Please sign in to comment.