@ajksunkang-aios/kgraph-linux-x64 0.1.2 → 0.1.3

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.
Files changed (196) hide show
  1. package/bin/kgraph-launcher +15 -3
  2. package/lib/kgraph/scripts/build-bundle.sh +17 -4
  3. package/lib/site-packages/outcome/__init__.py +20 -0
  4. package/lib/site-packages/outcome/_impl.py +239 -0
  5. package/lib/site-packages/outcome/_util.py +33 -0
  6. package/lib/site-packages/outcome/_version.py +7 -0
  7. package/lib/site-packages/outcome/py.typed +0 -0
  8. package/lib/site-packages/outcome-1.3.0.post0.dist-info/INSTALLER +1 -0
  9. package/lib/site-packages/outcome-1.3.0.post0.dist-info/LICENSE +3 -0
  10. package/lib/site-packages/outcome-1.3.0.post0.dist-info/LICENSE.APACHE2 +202 -0
  11. package/lib/site-packages/outcome-1.3.0.post0.dist-info/LICENSE.MIT +20 -0
  12. package/lib/site-packages/outcome-1.3.0.post0.dist-info/METADATA +63 -0
  13. package/lib/site-packages/outcome-1.3.0.post0.dist-info/RECORD +13 -0
  14. package/lib/site-packages/outcome-1.3.0.post0.dist-info/WHEEL +6 -0
  15. package/lib/site-packages/outcome-1.3.0.post0.dist-info/top_level.txt +1 -0
  16. package/lib/site-packages/sniffio/__init__.py +17 -0
  17. package/lib/site-packages/sniffio/_impl.py +95 -0
  18. package/lib/site-packages/sniffio/_tests/__init__.py +0 -0
  19. package/lib/site-packages/sniffio/_tests/test_sniffio.py +84 -0
  20. package/lib/site-packages/sniffio/_version.py +3 -0
  21. package/lib/site-packages/sniffio/py.typed +0 -0
  22. package/lib/site-packages/sniffio-1.3.1.dist-info/INSTALLER +1 -0
  23. package/lib/site-packages/sniffio-1.3.1.dist-info/LICENSE +3 -0
  24. package/lib/site-packages/sniffio-1.3.1.dist-info/LICENSE.APACHE2 +202 -0
  25. package/lib/site-packages/sniffio-1.3.1.dist-info/LICENSE.MIT +20 -0
  26. package/lib/site-packages/sniffio-1.3.1.dist-info/METADATA +104 -0
  27. package/lib/site-packages/sniffio-1.3.1.dist-info/RECORD +14 -0
  28. package/lib/site-packages/sniffio-1.3.1.dist-info/WHEEL +5 -0
  29. package/lib/site-packages/sniffio-1.3.1.dist-info/top_level.txt +1 -0
  30. package/lib/site-packages/sortedcontainers/__init__.py +74 -0
  31. package/lib/site-packages/sortedcontainers/sorteddict.py +812 -0
  32. package/lib/site-packages/sortedcontainers/sortedlist.py +2646 -0
  33. package/lib/site-packages/sortedcontainers/sortedset.py +733 -0
  34. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/INSTALLER +1 -0
  35. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/LICENSE +13 -0
  36. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/METADATA +264 -0
  37. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/RECORD +10 -0
  38. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/WHEEL +6 -0
  39. package/lib/site-packages/sortedcontainers-2.4.0.dist-info/top_level.txt +1 -0
  40. package/lib/site-packages/trio/__init__.py +133 -0
  41. package/lib/site-packages/trio/__main__.py +3 -0
  42. package/lib/site-packages/trio/_abc.py +714 -0
  43. package/lib/site-packages/trio/_channel.py +610 -0
  44. package/lib/site-packages/trio/_core/__init__.py +94 -0
  45. package/lib/site-packages/trio/_core/_asyncgens.py +243 -0
  46. package/lib/site-packages/trio/_core/_concat_tb.py +26 -0
  47. package/lib/site-packages/trio/_core/_entry_queue.py +223 -0
  48. package/lib/site-packages/trio/_core/_exceptions.py +169 -0
  49. package/lib/site-packages/trio/_core/_generated_instrumentation.py +50 -0
  50. package/lib/site-packages/trio/_core/_generated_io_epoll.py +98 -0
  51. package/lib/site-packages/trio/_core/_generated_io_kqueue.py +153 -0
  52. package/lib/site-packages/trio/_core/_generated_io_windows.py +204 -0
  53. package/lib/site-packages/trio/_core/_generated_run.py +269 -0
  54. package/lib/site-packages/trio/_core/_generated_windows_ffi.py +10 -0
  55. package/lib/site-packages/trio/_core/_instrumentation.py +117 -0
  56. package/lib/site-packages/trio/_core/_io_common.py +31 -0
  57. package/lib/site-packages/trio/_core/_io_epoll.py +385 -0
  58. package/lib/site-packages/trio/_core/_io_kqueue.py +292 -0
  59. package/lib/site-packages/trio/_core/_io_windows.py +1036 -0
  60. package/lib/site-packages/trio/_core/_ki.py +271 -0
  61. package/lib/site-packages/trio/_core/_local.py +104 -0
  62. package/lib/site-packages/trio/_core/_mock_clock.py +165 -0
  63. package/lib/site-packages/trio/_core/_parking_lot.py +317 -0
  64. package/lib/site-packages/trio/_core/_run.py +3148 -0
  65. package/lib/site-packages/trio/_core/_run_context.py +15 -0
  66. package/lib/site-packages/trio/_core/_tests/__init__.py +0 -0
  67. package/lib/site-packages/trio/_core/_tests/test_asyncgen.py +339 -0
  68. package/lib/site-packages/trio/_core/_tests/test_cancelled.py +222 -0
  69. package/lib/site-packages/trio/_core/_tests/test_exceptiongroup_gc.py +103 -0
  70. package/lib/site-packages/trio/_core/_tests/test_guest_mode.py +755 -0
  71. package/lib/site-packages/trio/_core/_tests/test_instrumentation.py +315 -0
  72. package/lib/site-packages/trio/_core/_tests/test_io.py +522 -0
  73. package/lib/site-packages/trio/_core/_tests/test_ki.py +703 -0
  74. package/lib/site-packages/trio/_core/_tests/test_local.py +118 -0
  75. package/lib/site-packages/trio/_core/_tests/test_mock_clock.py +193 -0
  76. package/lib/site-packages/trio/_core/_tests/test_parking_lot.py +389 -0
  77. package/lib/site-packages/trio/_core/_tests/test_run.py +3024 -0
  78. package/lib/site-packages/trio/_core/_tests/test_thread_cache.py +227 -0
  79. package/lib/site-packages/trio/_core/_tests/test_tutil.py +13 -0
  80. package/lib/site-packages/trio/_core/_tests/test_unbounded_queue.py +154 -0
  81. package/lib/site-packages/trio/_core/_tests/test_windows.py +305 -0
  82. package/lib/site-packages/trio/_core/_tests/tutil.py +117 -0
  83. package/lib/site-packages/trio/_core/_tests/type_tests/nursery_start.py +79 -0
  84. package/lib/site-packages/trio/_core/_tests/type_tests/run.py +51 -0
  85. package/lib/site-packages/trio/_core/_thread_cache.py +317 -0
  86. package/lib/site-packages/trio/_core/_traps.py +318 -0
  87. package/lib/site-packages/trio/_core/_unbounded_queue.py +163 -0
  88. package/lib/site-packages/trio/_core/_wakeup_socketpair.py +75 -0
  89. package/lib/site-packages/trio/_core/_windows_cffi.py +313 -0
  90. package/lib/site-packages/trio/_deprecate.py +171 -0
  91. package/lib/site-packages/trio/_dtls.py +1380 -0
  92. package/lib/site-packages/trio/_file_io.py +513 -0
  93. package/lib/site-packages/trio/_highlevel_generic.py +125 -0
  94. package/lib/site-packages/trio/_highlevel_open_tcp_listeners.py +251 -0
  95. package/lib/site-packages/trio/_highlevel_open_tcp_stream.py +397 -0
  96. package/lib/site-packages/trio/_highlevel_open_unix_stream.py +65 -0
  97. package/lib/site-packages/trio/_highlevel_serve_listeners.py +148 -0
  98. package/lib/site-packages/trio/_highlevel_socket.py +423 -0
  99. package/lib/site-packages/trio/_highlevel_ssl_helpers.py +180 -0
  100. package/lib/site-packages/trio/_path.py +289 -0
  101. package/lib/site-packages/trio/_repl.py +159 -0
  102. package/lib/site-packages/trio/_signals.py +185 -0
  103. package/lib/site-packages/trio/_socket.py +1326 -0
  104. package/lib/site-packages/trio/_ssl.py +964 -0
  105. package/lib/site-packages/trio/_subprocess.py +1178 -0
  106. package/lib/site-packages/trio/_subprocess_platform/__init__.py +123 -0
  107. package/lib/site-packages/trio/_subprocess_platform/kqueue.py +48 -0
  108. package/lib/site-packages/trio/_subprocess_platform/waitid.py +113 -0
  109. package/lib/site-packages/trio/_subprocess_platform/windows.py +11 -0
  110. package/lib/site-packages/trio/_sync.py +908 -0
  111. package/lib/site-packages/trio/_tests/__init__.py +0 -0
  112. package/lib/site-packages/trio/_tests/astrill-codesigning-cert.cer +0 -0
  113. package/lib/site-packages/trio/_tests/check_type_completeness.py +247 -0
  114. package/lib/site-packages/trio/_tests/module_with_deprecations.py +22 -0
  115. package/lib/site-packages/trio/_tests/pytest_plugin.py +54 -0
  116. package/lib/site-packages/trio/_tests/test_abc.py +72 -0
  117. package/lib/site-packages/trio/_tests/test_channel.py +750 -0
  118. package/lib/site-packages/trio/_tests/test_contextvars.py +56 -0
  119. package/lib/site-packages/trio/_tests/test_deprecate.py +277 -0
  120. package/lib/site-packages/trio/_tests/test_deprecate_strict_exception_groups_false.py +64 -0
  121. package/lib/site-packages/trio/_tests/test_dtls.py +950 -0
  122. package/lib/site-packages/trio/_tests/test_exports.py +626 -0
  123. package/lib/site-packages/trio/_tests/test_fakenet.py +317 -0
  124. package/lib/site-packages/trio/_tests/test_file_io.py +269 -0
  125. package/lib/site-packages/trio/_tests/test_highlevel_generic.py +98 -0
  126. package/lib/site-packages/trio/_tests/test_highlevel_open_tcp_listeners.py +419 -0
  127. package/lib/site-packages/trio/_tests/test_highlevel_open_tcp_stream.py +693 -0
  128. package/lib/site-packages/trio/_tests/test_highlevel_open_unix_stream.py +86 -0
  129. package/lib/site-packages/trio/_tests/test_highlevel_serve_listeners.py +186 -0
  130. package/lib/site-packages/trio/_tests/test_highlevel_socket.py +336 -0
  131. package/lib/site-packages/trio/_tests/test_highlevel_ssl_helpers.py +169 -0
  132. package/lib/site-packages/trio/_tests/test_path.py +279 -0
  133. package/lib/site-packages/trio/_tests/test_repl.py +428 -0
  134. package/lib/site-packages/trio/_tests/test_scheduler_determinism.py +47 -0
  135. package/lib/site-packages/trio/_tests/test_signals.py +186 -0
  136. package/lib/site-packages/trio/_tests/test_socket.py +1253 -0
  137. package/lib/site-packages/trio/_tests/test_ssl.py +1371 -0
  138. package/lib/site-packages/trio/_tests/test_subprocess.py +767 -0
  139. package/lib/site-packages/trio/_tests/test_sync.py +735 -0
  140. package/lib/site-packages/trio/_tests/test_testing.py +682 -0
  141. package/lib/site-packages/trio/_tests/test_testing_raisesgroup.py +1128 -0
  142. package/lib/site-packages/trio/_tests/test_threads.py +1173 -0
  143. package/lib/site-packages/trio/_tests/test_timeouts.py +281 -0
  144. package/lib/site-packages/trio/_tests/test_tracing.py +88 -0
  145. package/lib/site-packages/trio/_tests/test_trio.py +8 -0
  146. package/lib/site-packages/trio/_tests/test_unix_pipes.py +288 -0
  147. package/lib/site-packages/trio/_tests/test_util.py +349 -0
  148. package/lib/site-packages/trio/_tests/test_wait_for_object.py +225 -0
  149. package/lib/site-packages/trio/_tests/test_windows_pipes.py +112 -0
  150. package/lib/site-packages/trio/_tests/tools/__init__.py +0 -0
  151. package/lib/site-packages/trio/_tests/tools/test_gen_exports.py +179 -0
  152. package/lib/site-packages/trio/_tests/tools/test_mypy_annotate.py +140 -0
  153. package/lib/site-packages/trio/_tests/tools/test_sync_requirements.py +80 -0
  154. package/lib/site-packages/trio/_tests/type_tests/check_wraps.py +9 -0
  155. package/lib/site-packages/trio/_tests/type_tests/open_memory_channel.py +4 -0
  156. package/lib/site-packages/trio/_tests/type_tests/path.py +140 -0
  157. package/lib/site-packages/trio/_tests/type_tests/subprocesses.py +23 -0
  158. package/lib/site-packages/trio/_tests/type_tests/task_status.py +29 -0
  159. package/lib/site-packages/trio/_threads.py +610 -0
  160. package/lib/site-packages/trio/_timeouts.py +197 -0
  161. package/lib/site-packages/trio/_tools/__init__.py +0 -0
  162. package/lib/site-packages/trio/_tools/gen_exports.py +401 -0
  163. package/lib/site-packages/trio/_tools/mypy_annotate.py +126 -0
  164. package/lib/site-packages/trio/_tools/sync_requirements.py +98 -0
  165. package/lib/site-packages/trio/_tools/windows_ffi_build.py +220 -0
  166. package/lib/site-packages/trio/_unix_pipes.py +197 -0
  167. package/lib/site-packages/trio/_util.py +385 -0
  168. package/lib/site-packages/trio/_version.py +3 -0
  169. package/lib/site-packages/trio/_wait_for_object.py +67 -0
  170. package/lib/site-packages/trio/_windows_pipes.py +144 -0
  171. package/lib/site-packages/trio/abc.py +23 -0
  172. package/lib/site-packages/trio/from_thread.py +13 -0
  173. package/lib/site-packages/trio/lowlevel.py +95 -0
  174. package/lib/site-packages/trio/py.typed +0 -0
  175. package/lib/site-packages/trio/socket.py +602 -0
  176. package/lib/site-packages/trio/testing/__init__.py +58 -0
  177. package/lib/site-packages/trio/testing/_check_streams.py +570 -0
  178. package/lib/site-packages/trio/testing/_checkpoints.py +69 -0
  179. package/lib/site-packages/trio/testing/_fake_net.py +584 -0
  180. package/lib/site-packages/trio/testing/_memory_streams.py +633 -0
  181. package/lib/site-packages/trio/testing/_network.py +36 -0
  182. package/lib/site-packages/trio/testing/_raises_group.py +1015 -0
  183. package/lib/site-packages/trio/testing/_sequencer.py +87 -0
  184. package/lib/site-packages/trio/testing/_trio_test.py +50 -0
  185. package/lib/site-packages/trio/to_thread.py +4 -0
  186. package/lib/site-packages/trio-0.33.0.dist-info/INSTALLER +1 -0
  187. package/lib/site-packages/trio-0.33.0.dist-info/METADATA +186 -0
  188. package/lib/site-packages/trio-0.33.0.dist-info/RECORD +156 -0
  189. package/lib/site-packages/trio-0.33.0.dist-info/REQUESTED +0 -0
  190. package/lib/site-packages/trio-0.33.0.dist-info/WHEEL +5 -0
  191. package/lib/site-packages/trio-0.33.0.dist-info/entry_points.txt +2 -0
  192. package/lib/site-packages/trio-0.33.0.dist-info/licenses/LICENSE +3 -0
  193. package/lib/site-packages/trio-0.33.0.dist-info/licenses/LICENSE.APACHE2 +202 -0
  194. package/lib/site-packages/trio-0.33.0.dist-info/licenses/LICENSE.MIT +22 -0
  195. package/lib/site-packages/trio-0.33.0.dist-info/top_level.txt +1 -0
  196. package/package.json +1 -1
@@ -0,0 +1,812 @@
1
+ """Sorted Dict
2
+ ==============
3
+
4
+ :doc:`Sorted Containers<index>` is an Apache2 licensed Python sorted
5
+ collections library, written in pure-Python, and fast as C-extensions. The
6
+ :doc:`introduction<introduction>` is the best way to get started.
7
+
8
+ Sorted dict implementations:
9
+
10
+ .. currentmodule:: sortedcontainers
11
+
12
+ * :class:`SortedDict`
13
+ * :class:`SortedKeysView`
14
+ * :class:`SortedItemsView`
15
+ * :class:`SortedValuesView`
16
+
17
+ """
18
+
19
+ import sys
20
+ import warnings
21
+
22
+ from itertools import chain
23
+
24
+ from .sortedlist import SortedList, recursive_repr
25
+ from .sortedset import SortedSet
26
+
27
+ ###############################################################################
28
+ # BEGIN Python 2/3 Shims
29
+ ###############################################################################
30
+
31
+ try:
32
+ from collections.abc import (
33
+ ItemsView, KeysView, Mapping, ValuesView, Sequence
34
+ )
35
+ except ImportError:
36
+ from collections import ItemsView, KeysView, Mapping, ValuesView, Sequence
37
+
38
+ ###############################################################################
39
+ # END Python 2/3 Shims
40
+ ###############################################################################
41
+
42
+
43
+ class SortedDict(dict):
44
+ """Sorted dict is a sorted mutable mapping.
45
+
46
+ Sorted dict keys are maintained in sorted order. The design of sorted dict
47
+ is simple: sorted dict inherits from dict to store items and maintains a
48
+ sorted list of keys.
49
+
50
+ Sorted dict keys must be hashable and comparable. The hash and total
51
+ ordering of keys must not change while they are stored in the sorted dict.
52
+
53
+ Mutable mapping methods:
54
+
55
+ * :func:`SortedDict.__getitem__` (inherited from dict)
56
+ * :func:`SortedDict.__setitem__`
57
+ * :func:`SortedDict.__delitem__`
58
+ * :func:`SortedDict.__iter__`
59
+ * :func:`SortedDict.__len__` (inherited from dict)
60
+
61
+ Methods for adding items:
62
+
63
+ * :func:`SortedDict.setdefault`
64
+ * :func:`SortedDict.update`
65
+
66
+ Methods for removing items:
67
+
68
+ * :func:`SortedDict.clear`
69
+ * :func:`SortedDict.pop`
70
+ * :func:`SortedDict.popitem`
71
+
72
+ Methods for looking up items:
73
+
74
+ * :func:`SortedDict.__contains__` (inherited from dict)
75
+ * :func:`SortedDict.get` (inherited from dict)
76
+ * :func:`SortedDict.peekitem`
77
+
78
+ Methods for views:
79
+
80
+ * :func:`SortedDict.keys`
81
+ * :func:`SortedDict.items`
82
+ * :func:`SortedDict.values`
83
+
84
+ Methods for miscellany:
85
+
86
+ * :func:`SortedDict.copy`
87
+ * :func:`SortedDict.fromkeys`
88
+ * :func:`SortedDict.__reversed__`
89
+ * :func:`SortedDict.__eq__` (inherited from dict)
90
+ * :func:`SortedDict.__ne__` (inherited from dict)
91
+ * :func:`SortedDict.__repr__`
92
+ * :func:`SortedDict._check`
93
+
94
+ Sorted list methods available (applies to keys):
95
+
96
+ * :func:`SortedList.bisect_left`
97
+ * :func:`SortedList.bisect_right`
98
+ * :func:`SortedList.count`
99
+ * :func:`SortedList.index`
100
+ * :func:`SortedList.irange`
101
+ * :func:`SortedList.islice`
102
+ * :func:`SortedList._reset`
103
+
104
+ Additional sorted list methods available, if key-function used:
105
+
106
+ * :func:`SortedKeyList.bisect_key_left`
107
+ * :func:`SortedKeyList.bisect_key_right`
108
+ * :func:`SortedKeyList.irange_key`
109
+
110
+ Sorted dicts may only be compared for equality and inequality.
111
+
112
+ """
113
+ def __init__(self, *args, **kwargs):
114
+ """Initialize sorted dict instance.
115
+
116
+ Optional key-function argument defines a callable that, like the `key`
117
+ argument to the built-in `sorted` function, extracts a comparison key
118
+ from each dictionary key. If no function is specified, the default
119
+ compares the dictionary keys directly. The key-function argument must
120
+ be provided as a positional argument and must come before all other
121
+ arguments.
122
+
123
+ Optional iterable argument provides an initial sequence of pairs to
124
+ initialize the sorted dict. Each pair in the sequence defines the key
125
+ and corresponding value. If a key is seen more than once, the last
126
+ value associated with it is stored in the new sorted dict.
127
+
128
+ Optional mapping argument provides an initial mapping of items to
129
+ initialize the sorted dict.
130
+
131
+ If keyword arguments are given, the keywords themselves, with their
132
+ associated values, are added as items to the dictionary. If a key is
133
+ specified both in the positional argument and as a keyword argument,
134
+ the value associated with the keyword is stored in the
135
+ sorted dict.
136
+
137
+ Sorted dict keys must be hashable, per the requirement for Python's
138
+ dictionaries. Keys (or the result of the key-function) must also be
139
+ comparable, per the requirement for sorted lists.
140
+
141
+ >>> d = {'alpha': 1, 'beta': 2}
142
+ >>> SortedDict([('alpha', 1), ('beta', 2)]) == d
143
+ True
144
+ >>> SortedDict({'alpha': 1, 'beta': 2}) == d
145
+ True
146
+ >>> SortedDict(alpha=1, beta=2) == d
147
+ True
148
+
149
+ """
150
+ if args and (args[0] is None or callable(args[0])):
151
+ _key = self._key = args[0]
152
+ args = args[1:]
153
+ else:
154
+ _key = self._key = None
155
+
156
+ self._list = SortedList(key=_key)
157
+
158
+ # Reaching through ``self._list`` repeatedly adds unnecessary overhead
159
+ # so cache references to sorted list methods.
160
+
161
+ _list = self._list
162
+ self._list_add = _list.add
163
+ self._list_clear = _list.clear
164
+ self._list_iter = _list.__iter__
165
+ self._list_reversed = _list.__reversed__
166
+ self._list_pop = _list.pop
167
+ self._list_remove = _list.remove
168
+ self._list_update = _list.update
169
+
170
+ # Expose some sorted list methods publicly.
171
+
172
+ self.bisect_left = _list.bisect_left
173
+ self.bisect = _list.bisect_right
174
+ self.bisect_right = _list.bisect_right
175
+ self.index = _list.index
176
+ self.irange = _list.irange
177
+ self.islice = _list.islice
178
+ self._reset = _list._reset
179
+
180
+ if _key is not None:
181
+ self.bisect_key_left = _list.bisect_key_left
182
+ self.bisect_key_right = _list.bisect_key_right
183
+ self.bisect_key = _list.bisect_key
184
+ self.irange_key = _list.irange_key
185
+
186
+ self._update(*args, **kwargs)
187
+
188
+
189
+ @property
190
+ def key(self):
191
+ """Function used to extract comparison key from keys.
192
+
193
+ Sorted dict compares keys directly when the key function is none.
194
+
195
+ """
196
+ return self._key
197
+
198
+
199
+ @property
200
+ def iloc(self):
201
+ """Cached reference of sorted keys view.
202
+
203
+ Deprecated in version 2 of Sorted Containers. Use
204
+ :func:`SortedDict.keys` instead.
205
+
206
+ """
207
+ # pylint: disable=attribute-defined-outside-init
208
+ try:
209
+ return self._iloc
210
+ except AttributeError:
211
+ warnings.warn(
212
+ 'sorted_dict.iloc is deprecated.'
213
+ ' Use SortedDict.keys() instead.',
214
+ DeprecationWarning,
215
+ stacklevel=2,
216
+ )
217
+ _iloc = self._iloc = SortedKeysView(self)
218
+ return _iloc
219
+
220
+
221
+ def clear(self):
222
+
223
+ """Remove all items from sorted dict.
224
+
225
+ Runtime complexity: `O(n)`
226
+
227
+ """
228
+ dict.clear(self)
229
+ self._list_clear()
230
+
231
+
232
+ def __delitem__(self, key):
233
+ """Remove item from sorted dict identified by `key`.
234
+
235
+ ``sd.__delitem__(key)`` <==> ``del sd[key]``
236
+
237
+ Runtime complexity: `O(log(n))` -- approximate.
238
+
239
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
240
+ >>> del sd['b']
241
+ >>> sd
242
+ SortedDict({'a': 1, 'c': 3})
243
+ >>> del sd['z']
244
+ Traceback (most recent call last):
245
+ ...
246
+ KeyError: 'z'
247
+
248
+ :param key: `key` for item lookup
249
+ :raises KeyError: if key not found
250
+
251
+ """
252
+ dict.__delitem__(self, key)
253
+ self._list_remove(key)
254
+
255
+
256
+ def __iter__(self):
257
+ """Return an iterator over the keys of the sorted dict.
258
+
259
+ ``sd.__iter__()`` <==> ``iter(sd)``
260
+
261
+ Iterating the sorted dict while adding or deleting items may raise a
262
+ :exc:`RuntimeError` or fail to iterate over all keys.
263
+
264
+ """
265
+ return self._list_iter()
266
+
267
+
268
+ def __reversed__(self):
269
+ """Return a reverse iterator over the keys of the sorted dict.
270
+
271
+ ``sd.__reversed__()`` <==> ``reversed(sd)``
272
+
273
+ Iterating the sorted dict while adding or deleting items may raise a
274
+ :exc:`RuntimeError` or fail to iterate over all keys.
275
+
276
+ """
277
+ return self._list_reversed()
278
+
279
+
280
+ def __setitem__(self, key, value):
281
+ """Store item in sorted dict with `key` and corresponding `value`.
282
+
283
+ ``sd.__setitem__(key, value)`` <==> ``sd[key] = value``
284
+
285
+ Runtime complexity: `O(log(n))` -- approximate.
286
+
287
+ >>> sd = SortedDict()
288
+ >>> sd['c'] = 3
289
+ >>> sd['a'] = 1
290
+ >>> sd['b'] = 2
291
+ >>> sd
292
+ SortedDict({'a': 1, 'b': 2, 'c': 3})
293
+
294
+ :param key: key for item
295
+ :param value: value for item
296
+
297
+ """
298
+ if key not in self:
299
+ self._list_add(key)
300
+ dict.__setitem__(self, key, value)
301
+
302
+ _setitem = __setitem__
303
+
304
+
305
+ def __or__(self, other):
306
+ if not isinstance(other, Mapping):
307
+ return NotImplemented
308
+ items = chain(self.items(), other.items())
309
+ return self.__class__(self._key, items)
310
+
311
+
312
+ def __ror__(self, other):
313
+ if not isinstance(other, Mapping):
314
+ return NotImplemented
315
+ items = chain(other.items(), self.items())
316
+ return self.__class__(self._key, items)
317
+
318
+
319
+ def __ior__(self, other):
320
+ self._update(other)
321
+ return self
322
+
323
+
324
+ def copy(self):
325
+ """Return a shallow copy of the sorted dict.
326
+
327
+ Runtime complexity: `O(n)`
328
+
329
+ :return: new sorted dict
330
+
331
+ """
332
+ return self.__class__(self._key, self.items())
333
+
334
+ __copy__ = copy
335
+
336
+
337
+ @classmethod
338
+ def fromkeys(cls, iterable, value=None):
339
+ """Return a new sorted dict initailized from `iterable` and `value`.
340
+
341
+ Items in the sorted dict have keys from `iterable` and values equal to
342
+ `value`.
343
+
344
+ Runtime complexity: `O(n*log(n))`
345
+
346
+ :return: new sorted dict
347
+
348
+ """
349
+ return cls((key, value) for key in iterable)
350
+
351
+
352
+ def keys(self):
353
+ """Return new sorted keys view of the sorted dict's keys.
354
+
355
+ See :class:`SortedKeysView` for details.
356
+
357
+ :return: new sorted keys view
358
+
359
+ """
360
+ return SortedKeysView(self)
361
+
362
+
363
+ def items(self):
364
+ """Return new sorted items view of the sorted dict's items.
365
+
366
+ See :class:`SortedItemsView` for details.
367
+
368
+ :return: new sorted items view
369
+
370
+ """
371
+ return SortedItemsView(self)
372
+
373
+
374
+ def values(self):
375
+ """Return new sorted values view of the sorted dict's values.
376
+
377
+ See :class:`SortedValuesView` for details.
378
+
379
+ :return: new sorted values view
380
+
381
+ """
382
+ return SortedValuesView(self)
383
+
384
+
385
+ if sys.hexversion < 0x03000000:
386
+ def __make_raise_attributeerror(original, alternate):
387
+ # pylint: disable=no-self-argument
388
+ message = (
389
+ 'SortedDict.{original}() is not implemented.'
390
+ ' Use SortedDict.{alternate}() instead.'
391
+ ).format(original=original, alternate=alternate)
392
+ def method(self):
393
+ # pylint: disable=missing-docstring,unused-argument
394
+ raise AttributeError(message)
395
+ method.__name__ = original # pylint: disable=non-str-assignment-to-dunder-name
396
+ method.__doc__ = message
397
+ return property(method)
398
+
399
+ iteritems = __make_raise_attributeerror('iteritems', 'items')
400
+ iterkeys = __make_raise_attributeerror('iterkeys', 'keys')
401
+ itervalues = __make_raise_attributeerror('itervalues', 'values')
402
+ viewitems = __make_raise_attributeerror('viewitems', 'items')
403
+ viewkeys = __make_raise_attributeerror('viewkeys', 'keys')
404
+ viewvalues = __make_raise_attributeerror('viewvalues', 'values')
405
+
406
+
407
+ class _NotGiven(object):
408
+ # pylint: disable=too-few-public-methods
409
+ def __repr__(self):
410
+ return '<not-given>'
411
+
412
+ __not_given = _NotGiven()
413
+
414
+ def pop(self, key, default=__not_given):
415
+ """Remove and return value for item identified by `key`.
416
+
417
+ If the `key` is not found then return `default` if given. If `default`
418
+ is not given then raise :exc:`KeyError`.
419
+
420
+ Runtime complexity: `O(log(n))` -- approximate.
421
+
422
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
423
+ >>> sd.pop('c')
424
+ 3
425
+ >>> sd.pop('z', 26)
426
+ 26
427
+ >>> sd.pop('y')
428
+ Traceback (most recent call last):
429
+ ...
430
+ KeyError: 'y'
431
+
432
+ :param key: `key` for item
433
+ :param default: `default` value if key not found (optional)
434
+ :return: value for item
435
+ :raises KeyError: if `key` not found and `default` not given
436
+
437
+ """
438
+ if key in self:
439
+ self._list_remove(key)
440
+ return dict.pop(self, key)
441
+ else:
442
+ if default is self.__not_given:
443
+ raise KeyError(key)
444
+ return default
445
+
446
+
447
+ def popitem(self, index=-1):
448
+ """Remove and return ``(key, value)`` pair at `index` from sorted dict.
449
+
450
+ Optional argument `index` defaults to -1, the last item in the sorted
451
+ dict. Specify ``index=0`` for the first item in the sorted dict.
452
+
453
+ If the sorted dict is empty, raises :exc:`KeyError`.
454
+
455
+ If the `index` is out of range, raises :exc:`IndexError`.
456
+
457
+ Runtime complexity: `O(log(n))`
458
+
459
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
460
+ >>> sd.popitem()
461
+ ('c', 3)
462
+ >>> sd.popitem(0)
463
+ ('a', 1)
464
+ >>> sd.popitem(100)
465
+ Traceback (most recent call last):
466
+ ...
467
+ IndexError: list index out of range
468
+
469
+ :param int index: `index` of item (default -1)
470
+ :return: key and value pair
471
+ :raises KeyError: if sorted dict is empty
472
+ :raises IndexError: if `index` out of range
473
+
474
+ """
475
+ if not self:
476
+ raise KeyError('popitem(): dictionary is empty')
477
+
478
+ key = self._list_pop(index)
479
+ value = dict.pop(self, key)
480
+ return (key, value)
481
+
482
+
483
+ def peekitem(self, index=-1):
484
+ """Return ``(key, value)`` pair at `index` in sorted dict.
485
+
486
+ Optional argument `index` defaults to -1, the last item in the sorted
487
+ dict. Specify ``index=0`` for the first item in the sorted dict.
488
+
489
+ Unlike :func:`SortedDict.popitem`, the sorted dict is not modified.
490
+
491
+ If the `index` is out of range, raises :exc:`IndexError`.
492
+
493
+ Runtime complexity: `O(log(n))`
494
+
495
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
496
+ >>> sd.peekitem()
497
+ ('c', 3)
498
+ >>> sd.peekitem(0)
499
+ ('a', 1)
500
+ >>> sd.peekitem(100)
501
+ Traceback (most recent call last):
502
+ ...
503
+ IndexError: list index out of range
504
+
505
+ :param int index: index of item (default -1)
506
+ :return: key and value pair
507
+ :raises IndexError: if `index` out of range
508
+
509
+ """
510
+ key = self._list[index]
511
+ return key, self[key]
512
+
513
+
514
+ def setdefault(self, key, default=None):
515
+ """Return value for item identified by `key` in sorted dict.
516
+
517
+ If `key` is in the sorted dict then return its value. If `key` is not
518
+ in the sorted dict then insert `key` with value `default` and return
519
+ `default`.
520
+
521
+ Optional argument `default` defaults to none.
522
+
523
+ Runtime complexity: `O(log(n))` -- approximate.
524
+
525
+ >>> sd = SortedDict()
526
+ >>> sd.setdefault('a', 1)
527
+ 1
528
+ >>> sd.setdefault('a', 10)
529
+ 1
530
+ >>> sd
531
+ SortedDict({'a': 1})
532
+
533
+ :param key: key for item
534
+ :param default: value for item (default None)
535
+ :return: value for item identified by `key`
536
+
537
+ """
538
+ if key in self:
539
+ return self[key]
540
+ dict.__setitem__(self, key, default)
541
+ self._list_add(key)
542
+ return default
543
+
544
+
545
+ def update(self, *args, **kwargs):
546
+ """Update sorted dict with items from `args` and `kwargs`.
547
+
548
+ Overwrites existing items.
549
+
550
+ Optional arguments `args` and `kwargs` may be a mapping, an iterable of
551
+ pairs or keyword arguments. See :func:`SortedDict.__init__` for
552
+ details.
553
+
554
+ :param args: mapping or iterable of pairs
555
+ :param kwargs: keyword arguments mapping
556
+
557
+ """
558
+ if not self:
559
+ dict.update(self, *args, **kwargs)
560
+ self._list_update(dict.__iter__(self))
561
+ return
562
+
563
+ if not kwargs and len(args) == 1 and isinstance(args[0], dict):
564
+ pairs = args[0]
565
+ else:
566
+ pairs = dict(*args, **kwargs)
567
+
568
+ if (10 * len(pairs)) > len(self):
569
+ dict.update(self, pairs)
570
+ self._list_clear()
571
+ self._list_update(dict.__iter__(self))
572
+ else:
573
+ for key in pairs:
574
+ self._setitem(key, pairs[key])
575
+
576
+ _update = update
577
+
578
+
579
+ def __reduce__(self):
580
+ """Support for pickle.
581
+
582
+ The tricks played with caching references in
583
+ :func:`SortedDict.__init__` confuse pickle so customize the reducer.
584
+
585
+ """
586
+ items = dict.copy(self)
587
+ return (type(self), (self._key, items))
588
+
589
+
590
+ @recursive_repr()
591
+ def __repr__(self):
592
+ """Return string representation of sorted dict.
593
+
594
+ ``sd.__repr__()`` <==> ``repr(sd)``
595
+
596
+ :return: string representation
597
+
598
+ """
599
+ _key = self._key
600
+ type_name = type(self).__name__
601
+ key_arg = '' if _key is None else '{0!r}, '.format(_key)
602
+ item_format = '{0!r}: {1!r}'.format
603
+ items = ', '.join(item_format(key, self[key]) for key in self._list)
604
+ return '{0}({1}{{{2}}})'.format(type_name, key_arg, items)
605
+
606
+
607
+ def _check(self):
608
+ """Check invariants of sorted dict.
609
+
610
+ Runtime complexity: `O(n)`
611
+
612
+ """
613
+ _list = self._list
614
+ _list._check()
615
+ assert len(self) == len(_list)
616
+ assert all(key in self for key in _list)
617
+
618
+
619
+ def _view_delitem(self, index):
620
+ """Remove item at `index` from sorted dict.
621
+
622
+ ``view.__delitem__(index)`` <==> ``del view[index]``
623
+
624
+ Supports slicing.
625
+
626
+ Runtime complexity: `O(log(n))` -- approximate.
627
+
628
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
629
+ >>> view = sd.keys()
630
+ >>> del view[0]
631
+ >>> sd
632
+ SortedDict({'b': 2, 'c': 3})
633
+ >>> del view[-1]
634
+ >>> sd
635
+ SortedDict({'b': 2})
636
+ >>> del view[:]
637
+ >>> sd
638
+ SortedDict({})
639
+
640
+ :param index: integer or slice for indexing
641
+ :raises IndexError: if index out of range
642
+
643
+ """
644
+ _mapping = self._mapping
645
+ _list = _mapping._list
646
+ dict_delitem = dict.__delitem__
647
+ if isinstance(index, slice):
648
+ keys = _list[index]
649
+ del _list[index]
650
+ for key in keys:
651
+ dict_delitem(_mapping, key)
652
+ else:
653
+ key = _list.pop(index)
654
+ dict_delitem(_mapping, key)
655
+
656
+
657
+ class SortedKeysView(KeysView, Sequence):
658
+ """Sorted keys view is a dynamic view of the sorted dict's keys.
659
+
660
+ When the sorted dict's keys change, the view reflects those changes.
661
+
662
+ The keys view implements the set and sequence abstract base classes.
663
+
664
+ """
665
+ __slots__ = ()
666
+
667
+
668
+ @classmethod
669
+ def _from_iterable(cls, it):
670
+ return SortedSet(it)
671
+
672
+
673
+ def __getitem__(self, index):
674
+ """Lookup key at `index` in sorted keys views.
675
+
676
+ ``skv.__getitem__(index)`` <==> ``skv[index]``
677
+
678
+ Supports slicing.
679
+
680
+ Runtime complexity: `O(log(n))` -- approximate.
681
+
682
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
683
+ >>> skv = sd.keys()
684
+ >>> skv[0]
685
+ 'a'
686
+ >>> skv[-1]
687
+ 'c'
688
+ >>> skv[:]
689
+ ['a', 'b', 'c']
690
+ >>> skv[100]
691
+ Traceback (most recent call last):
692
+ ...
693
+ IndexError: list index out of range
694
+
695
+ :param index: integer or slice for indexing
696
+ :return: key or list of keys
697
+ :raises IndexError: if index out of range
698
+
699
+ """
700
+ return self._mapping._list[index]
701
+
702
+
703
+ __delitem__ = _view_delitem
704
+
705
+
706
+ class SortedItemsView(ItemsView, Sequence):
707
+ """Sorted items view is a dynamic view of the sorted dict's items.
708
+
709
+ When the sorted dict's items change, the view reflects those changes.
710
+
711
+ The items view implements the set and sequence abstract base classes.
712
+
713
+ """
714
+ __slots__ = ()
715
+
716
+
717
+ @classmethod
718
+ def _from_iterable(cls, it):
719
+ return SortedSet(it)
720
+
721
+
722
+ def __getitem__(self, index):
723
+ """Lookup item at `index` in sorted items view.
724
+
725
+ ``siv.__getitem__(index)`` <==> ``siv[index]``
726
+
727
+ Supports slicing.
728
+
729
+ Runtime complexity: `O(log(n))` -- approximate.
730
+
731
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
732
+ >>> siv = sd.items()
733
+ >>> siv[0]
734
+ ('a', 1)
735
+ >>> siv[-1]
736
+ ('c', 3)
737
+ >>> siv[:]
738
+ [('a', 1), ('b', 2), ('c', 3)]
739
+ >>> siv[100]
740
+ Traceback (most recent call last):
741
+ ...
742
+ IndexError: list index out of range
743
+
744
+ :param index: integer or slice for indexing
745
+ :return: item or list of items
746
+ :raises IndexError: if index out of range
747
+
748
+ """
749
+ _mapping = self._mapping
750
+ _mapping_list = _mapping._list
751
+
752
+ if isinstance(index, slice):
753
+ keys = _mapping_list[index]
754
+ return [(key, _mapping[key]) for key in keys]
755
+
756
+ key = _mapping_list[index]
757
+ return key, _mapping[key]
758
+
759
+
760
+ __delitem__ = _view_delitem
761
+
762
+
763
+ class SortedValuesView(ValuesView, Sequence):
764
+ """Sorted values view is a dynamic view of the sorted dict's values.
765
+
766
+ When the sorted dict's values change, the view reflects those changes.
767
+
768
+ The values view implements the sequence abstract base class.
769
+
770
+ """
771
+ __slots__ = ()
772
+
773
+
774
+ def __getitem__(self, index):
775
+ """Lookup value at `index` in sorted values view.
776
+
777
+ ``siv.__getitem__(index)`` <==> ``siv[index]``
778
+
779
+ Supports slicing.
780
+
781
+ Runtime complexity: `O(log(n))` -- approximate.
782
+
783
+ >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
784
+ >>> svv = sd.values()
785
+ >>> svv[0]
786
+ 1
787
+ >>> svv[-1]
788
+ 3
789
+ >>> svv[:]
790
+ [1, 2, 3]
791
+ >>> svv[100]
792
+ Traceback (most recent call last):
793
+ ...
794
+ IndexError: list index out of range
795
+
796
+ :param index: integer or slice for indexing
797
+ :return: value or list of values
798
+ :raises IndexError: if index out of range
799
+
800
+ """
801
+ _mapping = self._mapping
802
+ _mapping_list = _mapping._list
803
+
804
+ if isinstance(index, slice):
805
+ keys = _mapping_list[index]
806
+ return [_mapping[key] for key in keys]
807
+
808
+ key = _mapping_list[index]
809
+ return _mapping[key]
810
+
811
+
812
+ __delitem__ = _view_delitem