/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/ui/text.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-02 22:31:28 UTC
  • mfrom: (7291 work)
  • mto: This revision was merged to the branch mainline in revision 7293.
  • Revision ID: jelmer@jelmer.uk-20190302223128-0qk1i5tozmzq5nyq
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
import codecs
 
22
import io
22
23
import os
23
24
import sys
24
25
import warnings
668
669
def _wrap_in_stream(stream, encoding=None, errors='replace'):
669
670
    if encoding is None:
670
671
        encoding = _get_stream_encoding(stream)
671
 
    encoded_stream = codecs.getreader(encoding)(stream, errors=errors)
672
 
    encoded_stream.encoding = encoding
673
 
    return encoded_stream
 
672
    # Attempt to wrap using io.open if possible, since that can do
 
673
    # line-buffering.
 
674
    try:
 
675
        fileno = stream.fileno()
 
676
    except io.UnsupportedOperation:
 
677
        encoded_stream = codecs.getreader(encoding)(stream, errors=errors)
 
678
        encoded_stream.encoding = encoding
 
679
        return encoded_stream
 
680
    else:
 
681
        return io.open(fileno, encoding=encoding, errors=errors, mode='r', buffering=1)
674
682
 
675
683
 
676
684
def _wrap_out_stream(stream, encoding=None, errors='replace'):