diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2016-02-10 14:04:03 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2016-02-10 14:04:03 -0500 |
| commit | 590aef9ab3d872830ca27d95833e78c737fccd2d (patch) | |
| tree | 8c04f943cd837af80b89dce50cc5ef5ea1bcef58 /passlib/utils/__init__.py | |
| parent | 2b44e562f86375116a86b5034da618237176eff3 (diff) | |
| download | passlib-590aef9ab3d872830ca27d95833e78c737fccd2d.tar.gz | |
passlib.totp: factored out SequenceMixin for general use in passlib
Diffstat (limited to 'passlib/utils/__init__.py')
| -rw-r--r-- | passlib/utils/__init__.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 4bc45c0..1f703b4 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -242,6 +242,32 @@ class memoized_property(object): ## def __func__(self): ## "py3 compatible alias" +class SequenceMixin(object): + """ + helper which lets result object act like a fixed-length sequence. + subclass just needs to provide :meth:`_as_tuple()`. + """ + def _as_tuple(self): + raise NotImplemented("implement in subclass") + + def __repr__(self): + return repr(self._as_tuple()) + + def __getitem__(self, idx): + return self._as_tuple()[idx] + + def __iter__(self): + return iter(self._as_tuple()) + + def __len__(self): + return len(self._as_tuple()) + + def __eq__(self, other): + return self._as_tuple() == other + + def __ne__(self, other): + return not self.__eq__(other) + #============================================================================= # unicode helpers #============================================================================= |
