Opened 10 years ago

Closed 10 years ago

#6043 enhancement closed fixed (fixed)

Utility object for iterating bytestrings

Reported by: Itamar Turner-Trauring Owned by: Itamar Turner-Trauring
Priority: normal Milestone: Python 3.3 Minimal
Component: core Keywords:
Cc: Branch: branches/bytes-py3-6043
branch-diff, diff-cov, branch-cov, buildbot
Author: itamarst

Description (last modified by Itamar Turner-Trauring)

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 10 years ago by Itamar Turner-Trauring

Description: modified (diff)

comment:2 Changed 10 years ago by Itamar Turner-Trauring

Description: modified (diff)
Summary: Utility object for indexing and iterating bytestringsUtility object for iterating bytestrings

comment:3 Changed 10 years ago by itamarst

Author: itamarst
Branch: branches/bytes-py3-6043

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

comment:4 Changed 10 years ago by Itamar Turner-Trauring

Keywords: review added
Owner: set to Jean-Paul Calderone

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 10 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: changed from Jean-Paul Calderone to Itamar Turner-Trauring


  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 10 years ago by itamarst

Resolution: fixed
Status: newclosed

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