Opened 4 weeks ago

Closed 3 weeks ago

Last modified 2 weeks ago

#28450 closed enhancement (implemented)

Add a parse_bytes function to load descriptors from bytes

Reported by: irl Owned by: irl
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: atagar Sponsor:

Description

This is a convenience function that wraps the bytes in a BytesIO and calls parse_file().

Child Tickets

Attachments (1)

0001-Adds-a-parse_bytes-function-to-load-descriptors.patch (2.8 KB) - added by irl 4 weeks ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 weeks ago by irl

Owner: changed from atagar to irl
Status: newaccepted

comment:2 Changed 4 weeks ago by irl

Reviewer: atagar
Status: acceptedneeds_review

comment:3 Changed 3 weeks ago by atagar

Status: needs_reviewneeds_information

Thanks irl! I took this in a slightly different direction.

https://gitweb.torproject.org/stem.git/commit/?id=670f403

Changes from your patch are...

  • Moved this to Descriptor.from_str() to match the convention used elsewhere in stem's codebase.
  • Fixed a bug where the kwargs weren't passed along.
  • The method provides a single descriptor by default, with a multiple = True argument that must be supplied if you want a list instead. I did this because for the common case of parsing a single descriptor stem's been a little clunky.
  • Descriptor type inference can now be done in three ways: a descriptor_type argument, a @type annotation, and use of from_str() on subclasses (for example, RelayServerDescriptor.from_str()).
  • Test coverage.

Thoughts?

comment:4 Changed 3 weeks ago by atagar

Resolution: implemented
Status: needs_informationclosed

Resolving. Feel free to reopen if ya need anything else.

comment:5 Changed 2 weeks ago by irl

I am now using this in bushel and it is working great.

Note: See TracTickets for help on using tickets.