Opened 6 years ago

Closed 6 years ago

#6114 enhancement closed fixed (fixed)

Add a function for returning a byte string from a native string to help Python 3 porting

Reported by: Jean-Paul Calderone Owned by: Jean-Paul Calderone
Priority: normal Milestone: Python 3.3 Minimal
Component: core Keywords:
Cc: Branch: branches/nativestring-py3-6114
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun

Description

Many APIs only accept byte strings. On Python 3, only native (unicode) strings support string interpolation though. This makes it convenient to use native strings to construct a value (eg to be written to a socket), but Python 3 then requires an encode step whereas Python 2 does not. A function to smooth over this difference would simplify some code.

Change History (6)

comment:1 Changed 6 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/nativestring-py3-6114

(In [36178]) Branching to 'nativestring-py3-6114'

comment:2 Changed 6 years ago by Jean-Paul Calderone

(In [36180]) Pull in code from http branch

refs #6114

comment:3 Changed 6 years ago by Jean-Paul Calderone

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

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

Keywords: review removed
Owner: changed from Itamar Turner-Trauring to Jean-Paul Calderone
  1. Add a @param indicating it takes a str as input.
  2. Given it has a particular use case, maybe the docstring should mention that, i.e. give an example of using it for string formatting?
  3. Add new function to __all__.

Fix, then merge.

comment:5 Changed 6 years ago by Jean-Paul Calderone

(In [36204]) Example, @param, and __all__ update

refs #6114

comment:6 Changed 6 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [36205]) Merge nativestring-py3-6114 (sic)

Author: exarkun Reviewer: itamarst Fixes: #6114

Introduce twisted.python.compat.networkString, a helper for formatting bytes on Python 3.

Note: See TracTickets for help on using tickets.