OXIESEC PANEL
- Current Dir:
/
/
snap
/
core24
/
888
/
usr
/
lib
/
python3.12
/
importlib
/
resources
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/18/2025 08:12:15 AM
rwxr-xr-x
📄
__init__.py
506 bytes
02/04/2025 02:48:35 PM
rw-r--r--
📁
__pycache__
-
03/18/2025 08:12:15 AM
rwxr-xr-x
📄
_adapters.py
4.38 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
_common.py
5.33 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
_itertools.py
1.25 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
_legacy.py
3.4 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
abc.py
5.08 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
readers.py
4.2 KB
02/04/2025 02:48:35 PM
rw-r--r--
📄
simple.py
2.52 KB
02/04/2025 02:48:35 PM
rw-r--r--
Editing: _itertools.py
Close
# from more_itertools 9.0 def only(iterable, default=None, too_long=None): """If *iterable* has only one item, return it. If it has zero items, return *default*. If it has more than one item, raise the exception given by *too_long*, which is ``ValueError`` by default. >>> only([], default='missing') 'missing' >>> only([1]) 1 >>> only([1, 2]) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... ValueError: Expected exactly one item in iterable, but got 1, 2, and perhaps more.' >>> only([1, 2], too_long=TypeError) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... TypeError Note that :func:`only` attempts to advance *iterable* twice to ensure there is only one item. See :func:`spy` or :func:`peekable` to check iterable contents less destructively. """ it = iter(iterable) first_value = next(it, default) try: second_value = next(it) except StopIteration: pass else: msg = ( 'Expected exactly one item in iterable, but got {!r}, {!r}, ' 'and perhaps more.'.format(first_value, second_value) ) raise too_long or ValueError(msg) return first_value