(self, s, can_break=True)
Write the string s to the file, taking care of width settings.
Write the string s to the file, taking care of width settings.
Write the string s to the file taking care of width settings .
def write(self, s, can_break=True):
        """Write the string s to the file, taking care of width settings."""
        assert isinstance(s, bytes)
        # only break lines at the start of a new string. width 255 means unlimited width
        s_width = 0
        newline = False
        # find width of first line in s
        for c in iterchar(s):
            if c in (b'\r', b'\n'):
                newline = True
                break
            if c >= b' ':
                # nonprinting characters including tabs are not counted for WIDTH
                s_width += 1
        if (
                can_break and self.width != 255 and self.col != 1 and
                self.col-1 + s_width > self.width and not newline
            ):
            self.write_line()
            self.col = 1
        for c in iterchar(s):
            # don't replace CR or LF with CRLF when writing to files
            if c == b'\r':
                self._fhandle.write(c)
                self.col = 1
            else:
                self._fhandle.write(c)
                # nonprinting characters including tabs are not counted for WIDTH
                if c >= b' ':
                    self.col += 1
                    # col-1 is a byte that wraps
                    if self.col == 257:
                        self.col = 1
def write ( self , s , can_break = True ) : assert isinstance ( s , bytes ) # only break lines at the start of a new string. width 255 means unlimited width s_width = 0 newline = False # find width of first line in s for c in iterchar ( s ) : if c in ( b'\r' , b'\n' ) : newline = True break if c >= b' ' : # nonprinting characters including tabs are not counted for WIDTH s_width += 1 if ( can_break and self . width != 255 and self . col != 1 and self . col - 1 + s_width > self . width and not newline ) : self . write_line ( ) self . col = 1 for c in iterchar ( s ) : # don't replace CR or LF with CRLF when writing to files if c == b'\r' : self . _fhandle . write ( c ) self . col = 1 else : self . _fhandle . write ( c ) # nonprinting characters including tabs are not counted for WIDTH if c >= b' ' : self . col += 1 # col-1 is a byte that wraps if self . col == 257 : self . col = 1