collects 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- collects-1.0.1/LICENSE +20 -0
- collects-1.0.1/PKG-INFO +16 -0
- collects-1.0.1/README +1 -0
- collects-1.0.1/collects/__init__.py +56 -0
- collects-1.0.1/collects/_util.py +70 -0
- collects-1.0.1/collects/_version.py +2 -0
- collects-1.0.1/collects/bags.py +645 -0
- collects-1.0.1/collects/bijection.py +97 -0
- collects-1.0.1/collects/indexed_dict.py +376 -0
- collects-1.0.1/collects/range_map.py +429 -0
- collects-1.0.1/collects/sentinel.py +44 -0
- collects-1.0.1/collects/setlists.py +605 -0
- collects-1.0.1/collects.egg-info/PKG-INFO +16 -0
- collects-1.0.1/collects.egg-info/SOURCES.txt +18 -0
- collects-1.0.1/collects.egg-info/dependency_links.txt +1 -0
- collects-1.0.1/collects.egg-info/requires.txt +4 -0
- collects-1.0.1/collects.egg-info/top_level.txt +1 -0
- collects-1.0.1/setup.cfg +7 -0
- collects-1.0.1/setup.py +16 -0
collects-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011-2026 Sergey Astanin and contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
collects-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: collects
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: collects
|
|
5
|
+
Author: ops
|
|
6
|
+
License: Python Script
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: blessings~=1.7
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=3.2; extra == "dev"
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: license
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: provides-extra
|
|
15
|
+
Dynamic: requires-dist
|
|
16
|
+
Dynamic: summary
|
collects-1.0.1/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
README.md
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""collections_extended contains a few extra basic data structures."""
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
from .bags import bag, frozenbag, UniqueElementsView, CountsView, Bag # noqa
|
|
5
|
+
from .bijection import bijection
|
|
6
|
+
from .indexed_dict import IndexedDict
|
|
7
|
+
from .range_map import RangeMap, MappedRange # noqa
|
|
8
|
+
from .setlists import frozensetlist, setlist, SetList
|
|
9
|
+
|
|
10
|
+
__all__ = (
|
|
11
|
+
'Collection',
|
|
12
|
+
'Bag',
|
|
13
|
+
'bag',
|
|
14
|
+
'frozenbag',
|
|
15
|
+
'bijection',
|
|
16
|
+
'IndexedDict',
|
|
17
|
+
'RangeMap',
|
|
18
|
+
'SetList',
|
|
19
|
+
'frozensetlist',
|
|
20
|
+
'setlist',
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def collection(iterable=None, mutable=True, ordered=False, unique=False):
|
|
25
|
+
"""Return a :class:`Collection` with the specified properties.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
iterable (Iterable): collection to instantiate new collection from.
|
|
29
|
+
mutable (bool): Whether or not the new collection is mutable.
|
|
30
|
+
ordered (bool): Whether or not the new collection is ordered.
|
|
31
|
+
unique (bool): Whether or not the new collection contains only unique values.
|
|
32
|
+
"""
|
|
33
|
+
if iterable is None:
|
|
34
|
+
iterable = tuple()
|
|
35
|
+
if unique:
|
|
36
|
+
if ordered:
|
|
37
|
+
if mutable:
|
|
38
|
+
return setlist(iterable)
|
|
39
|
+
else:
|
|
40
|
+
return frozensetlist(iterable)
|
|
41
|
+
else:
|
|
42
|
+
if mutable:
|
|
43
|
+
return set(iterable)
|
|
44
|
+
else:
|
|
45
|
+
return frozenset(iterable)
|
|
46
|
+
else:
|
|
47
|
+
if ordered:
|
|
48
|
+
if mutable:
|
|
49
|
+
return list(iterable)
|
|
50
|
+
else:
|
|
51
|
+
return tuple(iterable)
|
|
52
|
+
else:
|
|
53
|
+
if mutable:
|
|
54
|
+
return bag(iterable)
|
|
55
|
+
else:
|
|
56
|
+
return frozenbag(iterable)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""util functions for collections_extended."""
|
|
2
|
+
from functools import wraps
|
|
3
|
+
import textwrap
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
__all__ = ('hash_iterable', 'deprecated', 'deprecation_warning')
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def hash_iterable(it):
|
|
10
|
+
"""Perform a O(1) memory hash of an iterable of arbitrary length.
|
|
11
|
+
|
|
12
|
+
hash(tuple(it)) creates a temporary tuple containing all values from it
|
|
13
|
+
which could be a problem if it is large.
|
|
14
|
+
|
|
15
|
+
See discussion at:
|
|
16
|
+
https://groups.google.com/forum/#!msg/python-ideas/XcuC01a8SYs/e-doB9TbDwAJ
|
|
17
|
+
"""
|
|
18
|
+
hash_value = hash(type(it))
|
|
19
|
+
for value in it:
|
|
20
|
+
hash_value = hash((hash_value, value))
|
|
21
|
+
return hash_value
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def deprecation_warning(msg):
|
|
25
|
+
"""Raise a deprecation warning."""
|
|
26
|
+
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def deprecated(msg, dep_version):
|
|
30
|
+
"""Decorate a function, method or class to mark as deprecated.
|
|
31
|
+
|
|
32
|
+
Raise DeprecationWarning and add a deprecation notice to the docstring.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
msg: The message to document
|
|
36
|
+
dep_version: The version in which this was deprecated
|
|
37
|
+
See:
|
|
38
|
+
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-deprecated
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
def wrapper(func):
|
|
42
|
+
docstring = func.__doc__ or ''
|
|
43
|
+
docstring_msg = '.. deprecated:: {version} {msg}'.format(
|
|
44
|
+
version=dep_version,
|
|
45
|
+
msg=msg,
|
|
46
|
+
)
|
|
47
|
+
if docstring:
|
|
48
|
+
# We don't know how far to indent this message
|
|
49
|
+
# so instead we just dedent everything.
|
|
50
|
+
string_list = docstring.splitlines()
|
|
51
|
+
first_line = string_list[0]
|
|
52
|
+
remaining = textwrap.dedent(''.join(string_list[1:]))
|
|
53
|
+
docstring = '\n'.join([
|
|
54
|
+
first_line,
|
|
55
|
+
remaining,
|
|
56
|
+
'',
|
|
57
|
+
docstring_msg,
|
|
58
|
+
])
|
|
59
|
+
else:
|
|
60
|
+
docstring = docstring_msg
|
|
61
|
+
func.__doc__ = docstring
|
|
62
|
+
|
|
63
|
+
@wraps(func)
|
|
64
|
+
def inner(*args, **kwargs):
|
|
65
|
+
deprecation_warning(msg)
|
|
66
|
+
return func(*args, **kwargs)
|
|
67
|
+
|
|
68
|
+
return inner
|
|
69
|
+
|
|
70
|
+
return wrapper
|