[stem/master] TODO note to expand Descriptor.create()

commit e2ef267c68e43de7fa9b9fd126192c037bd04a24 Author: Damian Johnson <atagar@torproject.org> Date: Sat Sep 26 15:11:25 2020 -0700 TODO note to expand Descriptor.create() TODO note to expand our Descriptor's create() and content() methods. These were originally private methods within our tests. I productionized and opened them for Isis so BridgeDB could replace Lector. We use descriptor content as their input arguments for a couple reasons... 1. It's agnostic to the descriptor type, so all Descriptors can largely share a constructor. 2. This was the input our tests originally wanted to make test descriptors from. However, it makes creating descriptors cumbersome. For instance, if I simply want to make a server descriptor with my nickname I need to run... RelayDescriptor.create({'router': 'caerSidi 71.35.133.197 9001 0 0'}) Wouldn't this be a lot better if it was simply the following? RelayDescriptor.create(nickname = 'caerSidi') However, doing this is easier said than done. Doing so will require reverse mapping attributes to line content (that is to say, convert 'nickname =' into something like the above router line. Oh well. Project for another time when I rethink our Descriptor APIs. --- stem/descriptor/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 58a88d55..3f10bc57 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -921,6 +921,9 @@ class Descriptor(object): * **NotImplementedError** if not implemented for this descriptor type """ + # TODO: add support for creating descriptors with preset parameters (rather + # than line content) + return cls(cls.content(attr, exclude), validate = validate) # type: ignore def type_annotation(self) -> 'stem.descriptor.TypeAnnotation':
participants (1)
-
atagar@torproject.org