Ticket #6043 enhancement closed fixed

Opened 8 months ago

Last modified 8 months ago

Utility object for iterating bytestrings

Reported by: itamar Owned by: itamar
Priority: normal Milestone: Python 3.3 Minimal
Component: core Keywords:
Cc: Branch: branches/bytes-py3-6043
Author: itamarst Launchpad Bug:

Description (last modified by itamar) (diff)

Python 3 does not provide a way to iterate over individual bytes in a bytestring. We should provide a cross-version utility wrapper in twisted.python.compat.

A future enhancement might add % support on Python 3, another would fix indexing (e.g. b'abc[1]') to not return an integer.

Change History

1

Changed 8 months ago by itamar

  • description modified (diff)

2

Changed 8 months ago by itamar

  • description modified (diff)
  • summary changed from Utility object for indexing and iterating bytestrings to Utility object for iterating bytestrings

3

Changed 8 months ago by itamarst

  • branch set to branches/bytes-py3-6043
  • branch_author set to itamarst

(In [35905]) Branching to 'bytes-py3-6043'

4

Changed 8 months ago by itamar

  • owner set to exarkun
  • keywords review added

 http://buildbot.twistedmatrix.com/boxes-supported?branch=/branches/bytes-py3-6043

I would appreciate suggestions for a better name.

I left news file as a .misc on the theory that's only relevant to developers of Twisted, who would be better off reading the Python 3 page as a whole rather than trying to get individual info from news snippets. It could be changed to feature though.

5

Changed 8 months ago by exarkun

  • keywords review removed
  • owner changed from exarkun to itamar

Thanks.

  1. misc seems fine to me
  2. I was expecting something like an iterbytes function, rather than a class-or-no-op-function. Maybe that helps with the naming issue? Another issue that helps avoid is making the type of the helper depend on Python version. Not as though anyone should ever try to subclass this thing, but we have no real way to stop them from doing so. Also the variable type makes it impossible to satisfy Twisted's naming convention with respect to casing. On the other hand, iterbytes doesn't sound like something that would ever help with interpolation (but perhaps we should just have a separate API for interpolation).
  3. This is a bit hair-splitty, but list([b for b in python2Bytes(input)]) is always equivalent to list(python2Bytes(input)) right?

Merge when you're happy with it all.

6

Changed 8 months ago by itamarst

  • status changed from new to closed
  • resolution set to fixed

(In [35915]) Merge bytes-py3-6043: Utility function for iterating over bytes.

Author: itamar Review: exarkun Fixes: #6043

Python 3 bytes are broken. This provides a utility function to deal with one issue out of many.

Note: See TracTickets for help on using tickets.