MCPcopy Create free account
hub / github.com/dateutil/dateutil / rrulebase

Class rrulebase

src/dateutil/rrule.py:87–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85
86
87class rrulebase:
88 def __init__(self, cache=False):
89 if cache:
90 self._cache = []
91 self._cache_lock = _thread.allocate_lock()
92 self._invalidate_cache()
93 else:
94 self._cache = None
95 self._cache_complete = False
96 self._len = None
97
98 def __reduce_ex__(self, protocol):
99 rv = super().__reduce_ex__(protocol)
100 state, slots = rv[2], None
101 if isinstance(state, tuple):
102 state, slots = state
103 if self._cache is not None:
104 state = dict(state)
105 state.pop("_cache_lock", None)
106 state.pop("_cache_gen", None)
107 state["_cache"] = []
108 if slots is not None:
109 state = (state, slots)
110 return rv[:2] + (state,) + rv[3:]
111
112 def __setstate__(self, state):
113 if isinstance(state, tuple):
114 state, slots = state
115 for name, value in slots.items():
116 setattr(self, name, value)
117 self.__dict__.update(state)
118 if self._cache is not None:
119 self._cache_lock = _thread.allocate_lock()
120 self._invalidate_cache()
121
122 def __iter__(self):
123 if self._cache_complete:
124 return iter(self._cache)
125 elif self._cache is None:
126 return self._iter()
127 else:
128 return self._iter_cached()
129
130 def _invalidate_cache(self):
131 if self._cache is not None:
132 self._cache = []
133 self._cache_complete = False
134 self._cache_gen = self._iter()
135
136 if self._cache_lock.locked():
137 self._cache_lock.release()
138
139 self._len = None
140
141 def _iter_cached(self):
142 i = 0
143 gen = self._cache_gen
144 cache = self._cache

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected