#6043 enhancement closed fixed (fixed)

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
(diff, github, buildbot, log)
Author: itamarst Launchpad Bug:

Description (last modified by itamar)

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 (6)

comment:1 Changed 23 months ago by itamar

  • Description modified (diff)

comment:2 Changed 23 months ago by itamar

  • Description modified (diff)
  • Summary changed from Utility object for indexing and iterating bytestrings to Utility object for iterating bytestrings

comment:3 Changed 23 months ago by itamarst

  • Author set to itamarst
  • Branch set to branches/bytes-py3-6043

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

comment:4 Changed 23 months ago by itamar

  • Keywords review added
  • Owner set to exarkun

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.

comment:5 Changed 23 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.

comment:6 Changed 23 months ago by itamarst

  • Resolution set to fixed
  • Status changed from new to closed

(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.