|
33 | 33 | Field,
|
34 | 34 | FlagsField,
|
35 | 35 | FlagValue,
|
| 36 | + ListValue, |
36 | 37 | MayEnd,
|
37 | 38 | MultiEnumField,
|
38 | 39 | MultipleTypeField,
|
@@ -701,10 +702,10 @@ def _ensure_bound_field_value(
|
701 | 702 | Ensures a field instance bound with ``self`` when applicable.
|
702 | 703 | """
|
703 | 704 | if isinstance(value, list):
|
704 |
| - # If `value` is a simple `list`, create a new `list_field` instance. |
705 |
| - # If `value` is already a `list_field` instance, we never know where this instance comes from, and what it's being used for. |
706 |
| - # Let's create a new `list_field` instance in any case. |
707 |
| - return list_field( |
| 705 | + # If `value` is a simple `list`, create a new `ListValue` instance. |
| 706 | + # If `value` is already a `ListValue` instance, we never know where this instance comes from, and what it's being used for. |
| 707 | + # Let's create a new `ListValue` instance in any case. |
| 708 | + return ListValue( |
708 | 709 | self,
|
709 | 710 | # Recurse on list items.
|
710 | 711 | [self._ensure_bound_field_value(x) for x in value],
|
@@ -2171,77 +2172,6 @@ def route(self):
|
2171 | 2172 | return (None, None, None)
|
2172 | 2173 |
|
2173 | 2174 |
|
2174 |
| -################# |
2175 |
| -# list fields # |
2176 |
| -################# |
2177 |
| - |
2178 |
| - |
2179 |
| -class list_field_meta(type): |
2180 |
| - """ |
2181 |
| - Wraps modifying methods for ``list`` base type. |
2182 |
| -
|
2183 |
| - Inspired from https://stackoverflow.com/questions/8858525/track-changes-to-lists-and-dictionaries-in-python#8859168. |
2184 |
| - """ |
2185 |
| - def __new__( |
2186 |
| - mcs, |
2187 |
| - name, # type: str |
2188 |
| - bases, # Tuple[type, ...] |
2189 |
| - attrs, # type: Dict[str, Any] |
2190 |
| - ): # type: (...) -> type |
2191 |
| - # List names of `list` methods modifying the list. |
2192 |
| - for method_name in [ |
2193 |
| - "append", |
2194 |
| - "clear", |
2195 |
| - "extend", |
2196 |
| - "insert", |
2197 |
| - "pop", |
2198 |
| - "remove", |
2199 |
| - "reverse", # Memo: Reverse *IN PLACE*. |
2200 |
| - "sort", # Memo: Stable sort *IN PLACE*. |
2201 |
| - "__delitem__", |
2202 |
| - "__iadd__", |
2203 |
| - "__imul__", |
2204 |
| - "__setitem__", |
2205 |
| - ]: |
2206 |
| - # Wrap the method so that `Packet.clear_cache()` be automatically called. |
2207 |
| - attrs[method_name] = list_field_meta._wrap_method(getattr(list, method_name)) |
2208 |
| - return type.__new__(mcs, name, bases, attrs) |
2209 |
| - |
2210 |
| - @staticmethod |
2211 |
| - def _wrap_method(meth): # type: (Callable[[Any, ...], Any]) -> Callable[[Any, ...], Any] |
2212 |
| - def wrapped( |
2213 |
| - self, # type: list_field |
2214 |
| - *args, # type: Any |
2215 |
| - **kwargs, # type: Any |
2216 |
| - ): # type: (...) -> Any |
2217 |
| - # Automatically call `Packet.clear_cache()` when the `list_field` is modified. |
2218 |
| - self.pkt.clear_cache(upwards=True, downwards=False) |
2219 |
| - |
2220 |
| - # Call the wrapped method, and return its result. |
2221 |
| - return meth(self, *args, **kwargs) |
2222 |
| - return wrapped |
2223 |
| - |
2224 |
| - |
2225 |
| -class list_field(list, metaclass=list_field_meta): |
2226 |
| - """ |
2227 |
| - Overrides the base ``list`` type for list fields bound with packets. |
2228 |
| -
|
2229 |
| - Ensures :meth:`Packet.clear_cache()` is called when the list is modified. |
2230 |
| -
|
2231 |
| - Lower case for the class name in order to avoid confusions with classes like ``PacketListField``. |
2232 |
| - """ |
2233 |
| - def __init__( |
2234 |
| - self, |
2235 |
| - pkt, # type: Packet, |
2236 |
| - *args # type: Any |
2237 |
| - ): # type: (...) -> None |
2238 |
| - # Call the `list.__init__()` super constructor. |
2239 |
| - super().__init__(*args) |
2240 |
| - |
2241 |
| - #: Packet bound with this list field. |
2242 |
| - self.pkt = pkt |
2243 |
| - |
2244 |
| - |
2245 | 2175 | ####################
|
2246 | 2176 | # packet classes #
|
2247 | 2177 | ####################
|
|
0 commit comments