commit bda32a24cc543d07e3dbc7d993f9ac08517030a9 Author: Damian Johnson atagar@torproject.org Date: Mon Apr 24 09:11:01 2017 -0700
DescriptorType enum
Adding an enumeration for the common descriptor types. This is something I want for descriptor creation, but that aside it can be used for parse so...
stem.descriptor.parse(my_input, 'server-descriptor 1.0')
... becomes..
stem.descriptor.parse(my_input, DescriptorType.SERVER) --- stem/descriptor/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 6e8c5a4..f80e6f6 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -17,6 +17,22 @@ Package for parsing and processing descriptor data. |- get_unrecognized_lines - unparsed descriptor content +- __str__ - string that the descriptor was made from
+.. data:: DescriptorType (enum) + + Common descriptor types. + + .. versionadded:: 1.6.0 + + =================== =========== + DescriptorType Description + =================== =========== + **SERVER** :class:`~stem.descriptor.server_descriptor.RelayDescriptor` + **EXTRA** :class:`~stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor` + **MICRO** :class:`~stem.descriptor.microdescriptor.Microdescriptor` + **CONSENSUS** :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV3` + **HIDDEN_SERVICE** :class:`~stem.descriptor.hidden_service_descriptor.HiddenServiceDescriptor` + =================== =========== + .. data:: DocumentHandler (enum)
Ways in which we can parse a @@ -86,6 +102,14 @@ DocumentHandler = stem.util.enum.UppercaseEnum( 'BARE_DOCUMENT', )
+DescriptorType = stem.util.enum.Enum( + ('SERVER', 'server-descriptor 1.0'), + ('EXTRAINFO', 'extra-info 1.0'), + ('MICRO', 'microdescriptor 1.0'), + ('CONSENSUS', 'network-status-consensus-3 1.0'), + ('HIDDEN_SERVICE', 'hidden-service-descriptor 1.0'), +) +
def parse_file(descriptor_file, descriptor_type = None, validate = False, document_handler = DocumentHandler.ENTRIES, normalize_newlines = None, **kwargs): """