Mercurial > p > roundup > code
comparison roundup/anypy/strings.py @ 5418:55f09ca366c4
Python 3 preparation: StringIO.
This generally arranges for StringIO and cStringIO references to use
io.StringIO for Python 3 but io.BytesIO for Python 2, consistent with
the string representations generally used in Roundup. A special
FasterStringIO in the TAL code, which referenced internals of the old
Python 2 StringIO module, is cut down so it doesn't actually do
anything beyond the StringIO class it inherits from (it would also be
reasonable to remove FasterStringIO completely). One place in
roundup_server.py clearly needing binary I/O is made to use io.BytesIO
unconditionally.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 09:08:29 +0000 |
| parents | c749d6795bc2 |
| children | 6b0c542642be |
comparison
equal
deleted
inserted
replaced
| 5417:c749d6795bc2 | 5418:55f09ca366c4 |
|---|---|
| 4 # few places, generally for interacting with external modules | 4 # few places, generally for interacting with external modules |
| 5 # requiring that type to be used. | 5 # requiring that type to be used. |
| 6 | 6 |
| 7 import sys | 7 import sys |
| 8 _py3 = sys.version_info[0] > 2 | 8 _py3 = sys.version_info[0] > 2 |
| 9 | |
| 10 import io | |
| 11 if _py3: | |
| 12 StringIO = io.StringIO | |
| 13 else: | |
| 14 StringIO = io.BytesIO | |
| 9 | 15 |
| 10 def b2s(b): | 16 def b2s(b): |
| 11 """Convert a UTF-8 encoded bytes object to the internal string format.""" | 17 """Convert a UTF-8 encoded bytes object to the internal string format.""" |
| 12 if _py3: | 18 if _py3: |
| 13 return b.decode('utf-8') | 19 return b.decode('utf-8') |
